diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index ca24008..9409695 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -796,10 +796,33 @@ namespace CMS_CORE_Library.Demo return cmsError; } - public override CmsError PLC_ROperatorInputIsNeeded(ref List value) + public override CmsError PLC_ROperatorInputIsNeeded(ref List value) + { + byte val = 0; + CmsError cmsError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, 0, ref val); + if (cmsError.IsError()) + return cmsError; + + bool[] bits = ByteToBits(val); + uint i = 0; + + value = bits + .Select(x => new InputIsNeededModel() + { + Process = i++, + IsNeeded = x + }) + .ToList(); + + return NO_ERROR; + } + + public override CmsError PLC_RMTConnectData(ref List value) { return NO_ERROR; } + + #endregion PLC High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3057,6 +3080,13 @@ namespace CMS_CORE_Library.Demo internal static MEMORY_CELL QUEUE_START_STOP_ACTIVE = new MEMORY_CELL(MEMORY_TYPE.Demo, 447, 1); internal static MEMORY_CELL QUEUE_CMD = new MEMORY_CELL(MEMORY_TYPE.Demo, 448, 1); internal static MEMORY_CELL PROGRAM_TYPE = new MEMORY_CELL(MEMORY_TYPE.Demo, 449, 1); + + internal static MEMORY_CELL COUNTERS_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 43, 40); + internal static MEMORY_CELL COUNTERS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 3008, 2); + internal static MEMORY_CELL COUNTERS_STROBE = new MEMORY_CELL(MEMORY_TYPE.Demo, 3010, 2); + + internal static MEMORY_CELL OPERATOR_INPUT_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Demo, 450, 1); + internal static MEMORY_CELL MTCONNECT_DATA_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Demo, 451, 1); } #endregion Memory addresses diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 64f9410..e2eaab7 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -768,11 +768,46 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - public override CmsError PLC_ROperatorInputIsNeeded(ref List value) + public override CmsError PLC_ROperatorInputIsNeeded(ref List value) { + byte val = 0; + CmsError cmsError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, 0, ref val); + if (cmsError.IsError()) + return cmsError; + + bool[] bits = ByteToBits(val); + uint i = 0; + + value = bits + .Select(x => new InputIsNeededModel() + { + Process = i++, + IsNeeded = x + }) + .ToList(); + return NO_ERROR; } + public override CmsError PLC_RMTConnectData(ref List value) + { + short nReturn = 0; + for (int i = 0; i < nLibHandle.Count(); i++) + { + // Read block number + nReturn = Focas1.cnc_rdblkcount(nLibHandle[i], out int blockNum); + if (nReturn != 0) + return GetNcError(nReturn); + + ushort length = 256; + char[] line = new char[256]; + nReturn = Focas1.cnc_rdexecprog(nLibHandle[i], ref length, out short b, line); + } + + return NO_ERROR; + } + + #endregion PLC High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3652,5 +3687,12 @@ namespace CMS_CORE_Library.Fanuc internal static MEMORY_CELL FAMILY_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 42000, 7500); internal static MEMORY_CELL SHANK_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 49600, 2100); internal static MEMORY_CELL MAG_POS_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 51800, 900); + + internal static MEMORY_CELL COUNTERS_DATA = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 0, 64); + internal static MEMORY_CELL COUNTERS_ACK = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 0, 2); + internal static MEMORY_CELL COUNTERS_STROBE = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 0, 2); + + internal static MEMORY_CELL OPERATOR_INPUT_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 0, 1); + internal static MEMORY_CELL MTCONNECT_DATA_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 0, 1); } } \ No newline at end of file diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index 47bb524..6a01275 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -109,7 +109,21 @@ namespace CMS_CORE_Library.Models public uint Id; public uint Value; } - public struct InputOperatorIsNeededModel + + public struct InputIsNeededModel + { + public uint Process; + public bool IsNeeded; + } + + public struct MtConnectDataIsNeededModel + { + public uint Process; + public bool IsNeeded; + public string[] ActualLine; + } + + public struct MtConnectDataNeededModel { public uint Process; public bool IsNeeded; diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 6adb4d2..6336e74 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -549,7 +549,10 @@ namespace CMS_CORE_Library public abstract CmsError PLC_WHeadOverride(uint id, HEAD_OVERRIDE_SIGN sign); - public abstract CmsError PLC_ROperatorInputIsNeeded(ref List value); + public abstract CmsError PLC_ROperatorInputIsNeeded(ref List value); + + public abstract CmsError PLC_RMTConnectData(ref List value); + #endregion PLC High-level data (to override) diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 9f4c8c7..3210b8c 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -739,7 +739,28 @@ namespace CMS_CORE_Library.Osai return NO_ERROR; } - public override CmsError PLC_ROperatorInputIsNeeded(ref List value) + public override CmsError PLC_ROperatorInputIsNeeded(ref List value) + { + byte val = 0; + CmsError cmsError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, 0, ref val); + if (cmsError.IsError()) + return cmsError; + + bool[] bits = ByteToBits(val); + uint i = 0; + + value = bits + .Select(x => new InputIsNeededModel() + { + Process = i++, + IsNeeded = x + }) + .ToList(); + + return NO_ERROR; + } + + public override CmsError PLC_RMTConnectData(ref List value) { return NO_ERROR; } @@ -3784,6 +3805,13 @@ namespace CMS_CORE_Library.Osai internal static MEMORY_CELL TOOL_STATUS_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13011, 10); internal static MEMORY_CELL TOOL_LIFE_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13022, 40); + + internal static MEMORY_CELL COUNTERS_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 0, 64); + internal static MEMORY_CELL COUNTERS_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 0, 2); + internal static MEMORY_CELL COUNTERS_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 0, 2); + + internal static MEMORY_CELL OPERATOR_INPUT_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 0, 1); + internal static MEMORY_CELL MTCONNECT_DATA_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 0, 1); } #endregion Memory addresses diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 2a12c9e..33746bc 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -891,7 +891,7 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } - public override CmsError PLC_ROperatorInputIsNeeded(ref List value) + public override CmsError PLC_ROperatorInputIsNeeded(ref List value) { byte val = 0; CmsError cmsError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, 0, ref val); @@ -904,7 +904,7 @@ namespace CMS_CORE_Library.Siemens // .ToDictionary(x => i++, x => x); value = bits - .Select(x => new InputOperatorIsNeededModel() + .Select(x => new InputIsNeededModel() { Process = i++, IsNeeded = x @@ -913,6 +913,63 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } + + public override CmsError PLC_RMTConnectData(ref List value) + { + byte val = 0; + CmsError cmsError = MEM_RWByte(R, 0, MTCONNECT_DATA_NEEDED.MemType, MTCONNECT_DATA_NEEDED.Address, 0, ref val); + if (cmsError.IsError()) + return cmsError; + + // Convert a byte to an array of booleans + bool[] bits = ByteToBits(val); + uint path = 1; + string[] parameters; + string tmpStr = ""; + + foreach (bool bit in bits) + { + // Read active program line + cmsError = ReadActiveLine(path, ref tmpStr); + if (cmsError.IsError()) + return cmsError; + + // Parse parameters + parameters = ExtractM154Parameters(tmpStr); + value.Add(new MtConnectDataIsNeededModel() + { + Process = path, + IsNeeded = bit, + ActualLine = parameters + }); + + // Next path + path++; + } + + return NO_ERROR; + } + + private CmsError ReadActiveLine(uint path, ref string line) + { + try + { + Item item = new Item(); + if (path == 0) + item.Path = "/Channel/ProgramInfo/actBlock[u1,1]"; // Default + else + item.Path = "/Channel/ProgramInfo/actBlock[u" + path + ",1]"; + + DataSvc dataSvc = new DataSvc(); + dataSvc.Read(item); + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } private CmsError PLC_WStrobe(MEMORY_CELL ackCell, MEMORY_CELL strobeCell, uint id) { @@ -1948,6 +2005,17 @@ namespace CMS_CORE_Library.Siemens { try { + string fileName = Path.GetFileName(path); + string localFilePath = "C://PARTPRG/" + fileName; + if (File.Exists(localFilePath)) + { + FileInfo f = new FileInfo(localFilePath); + fileInfo.Name = f.Name; + fileInfo.CreationDate = f.CreationTime; + fileInfo.LastModDate = f.LastAccessTime; + fileInfo.AbsolutePath = localFilePath; + } + string tmpPath = FormatPath(path); tmpPath = BASE_FILE_PATH + tmpPath; @@ -2219,6 +2287,8 @@ namespace CMS_CORE_Library.Siemens public override CmsError FILES_RGetProgramType(ref PROGRAM_TYPE_ENUM programType) { + programType = PROGRAM_TYPE_ENUM.PART_PROGRAM; + return NO_ERROR; } @@ -5156,5 +5226,6 @@ namespace CMS_CORE_Library.Siemens internal static MEMORY_CELL COUNTERS_STROBE = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 3010, 2); internal static MEMORY_CELL OPERATOR_INPUT_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 3014, 1); + internal static MEMORY_CELL MTCONNECT_DATA_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 3042, 1); } } \ No newline at end of file diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index 4f08efd..51f9b0e 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -210,5 +210,33 @@ namespace CMS_CORE_Library.Utils return SIEMENS_MAGAZINE_TYPE.BOX_MAGAZINE; } + + public static string[] ExtractM154Parameters(string m154Command) + { + string[] returnVal = new string[1]; + int startPos = 0, endPos = 0; + + // Get first position + startPos = m154Command.IndexOf('('); + if (startPos == -1) + startPos = m154Command.IndexOf(';'); + + // Get second position + endPos = m154Command.IndexOf(')', startPos + 1); + if (startPos != -1 && endPos == -1) + endPos = m154Command.Length; + + // if not exists + if (startPos != -1) + { + string tmpString = m154Command; + if (endPos != -1) + tmpString = m154Command.Substring(startPos, endPos - startPos - 1); + + returnVal = tmpString.Split(','); + } + + return returnVal; + } } } \ No newline at end of file