diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index e981eb9..e4cc08d 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -850,7 +850,7 @@ namespace CMS_CORE_Library.Demo return MEM_RWByte(W, 0, MEMORY_TYPE.Demo, procAddress, 0, ref approxymatedVal); } - public override CmsError PLC_RMTConnectData(ref List value) + public override CmsError PLC_RM154Data(ref List value) { return NO_ERROR; } @@ -1089,7 +1089,7 @@ namespace CMS_CORE_Library.Demo CmsError cmsError; bool readValue = false; - for (int i = 0; i < PROCESS_NUMBER; i++) + for (int i = 0; i < MAX_PROCESS_NUMBER; i++) { int memoryAddress = SELECTED_PROCESS.Address + i * (2); // Read memory from plc @@ -1113,7 +1113,7 @@ namespace CMS_CORE_Library.Demo byte processNum = (byte)procNumber; // Check parameter - if (processNum > PROCESS_NUMBER) + if (processNum > MAX_PROCESS_NUMBER) return INCORRECT_PARAMETERS_ERROR; // Write process number diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 6cd78d0..73b55ba 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -832,36 +832,37 @@ namespace CMS_CORE_Library.Fanuc bool[] bits = ByteToBits(val); - uint processId = 1; - foreach(bool bit in bits) + string[] parameters; + string actualLine = ""; + + for (uint processId = 1; processId <= MAX_PROCESS_NUMBER; processId++) { - if (bit) + if (bits[processId - 1]) { - string actualLine = ""; // Read active program line cmsError = PROC_ReadActiveLine(processId, ref actualLine); if (cmsError.IsError()) return cmsError; - // Extract parameters - string[] parameters = ExtractM155ParametersFromNcCodeLine(actualLine); - byte i = 0; - // Populate buttons + + // Parse line & get parameters + parameters = ExtractM155ParametersFromNcCodeLine(actualLine); + + byte i = 1; + // Skip first parameter because it's the message string + // Set button with -> id = 1..5 -> value = parameter value Dictionary buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x); - // Create output model value.Add(new M155InputIsNeededModel() { - Process = processId, - IsNeeded = bit, + Process = (uint)processId, + IsNeeded = bits[processId - 1], Message = parameters[0] ?? "", Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request Buttons = buttons }); } - - processId++; } - + return NO_ERROR; } @@ -870,19 +871,37 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - public override CmsError PLC_RMTConnectData(ref List value) + public override CmsError PLC_RM154Data(ref List data) { - 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); + 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; - ushort length = 256; - char[] line = new char[256]; - nReturn = Focas1.cnc_rdexecprog(nLibHandle[i], ref length, out short b, line); + // Convert a byte to an array of booleans + bool[] bits = ByteToBits(val); + string[] parameters; + string tmpStr = ""; + + for (uint processId = 1; processId <= MAX_PROCESS_NUMBER; processId++) + { + if (bits[processId - 1]) + { + // Read active program line + cmsError = PROC_ReadActiveLine(processId, ref tmpStr); + if (cmsError.IsError()) + return cmsError; + + // Parse parameters + parameters = ExtractM154ParametersFromNcCodeLine(tmpStr); + data.Add(new M154DataModel() + { + Process = processId, + IsNeeded = bits[processId - 1], + ActualLine = parameters + }); + + } } return NO_ERROR; @@ -978,6 +997,8 @@ namespace CMS_CORE_Library.Fanuc processData.Type = bits[1] ? "WORK" : "AUX"; processData.IsSelected = bits[2]; processData.IsInAlarm = bits[3]; + processData.CanLoadProgram = bits[4]; + // Choose process status if (bytes[1] == 1) @@ -1186,7 +1207,7 @@ namespace CMS_CORE_Library.Fanuc CmsError cmsError; bool readValue = false; - for (int i = 0; i < PROCESS_NUMBER; i++) + for (int i = 0; i < MAX_PROCESS_NUMBER; i++) { int memoryAddress = SELECTED_PROCESS.Address + i * (2); // Read memory from plc @@ -1207,7 +1228,7 @@ namespace CMS_CORE_Library.Fanuc byte processNum = (byte)procNumber; // Check parameter - if (processNum > PROCESS_NUMBER) + if (processNum > MAX_PROCESS_NUMBER) return INCORRECT_PARAMETERS_ERROR; // Write process number @@ -2270,42 +2291,13 @@ namespace CMS_CORE_Library.Fanuc string absolutePath = FormatPathForNc(path, baseDir.drive1); ODBPDFNFIL dataNum = new ODBPDFNFIL(); + // Get the number of the directories and of files nReturn = Focas1.cnc_rdpdf_subdirn(nLibHandle[0], absolutePath, dataNum); if (nReturn != 0) return GetNcError(nReturn); - - IDBPDFSDIR currDirInput = new IDBPDFSDIR(); - ODBPDFSDIR currDirOutData = new ODBPDFSDIR(); - + short maxDir = 1; - // Check if there are directories - if (dataNum.dir_num > 0) - { - // Setup input data - currDirInput.dummy = 0; - currDirInput.path = absolutePath; - - for (short i = 0; i < dataNum.dir_num; i++) - { - // Update index - currDirInput.req_num = i; - // Read directory data - nReturn = cnc_rdpdf_subdir(nLibHandle[0], ref maxDir, currDirInput, currDirOutData); - if (nReturn != 0) - return GetNcError(nReturn); - - // Add to list read data - files.Add(new PreviewFileModel() - { - AbsolutePath = FormatPathForHighLevel(absolutePath + currDirOutData.d_f, true), - IsDirectory = true, - Name = currDirOutData.d_f, - Path = path + currDirOutData.d_f - }); - } - } - // Check if there are files if (dataNum.file_num > 0) { @@ -2325,15 +2317,28 @@ namespace CMS_CORE_Library.Fanuc nReturn = Focas1.cnc_rdpdf_alldir(nLibHandle[0], ref maxDir, funcInput, fileData); if (nReturn != 0) return GetNcError(nReturn); - - // Add to list read data - files.Add(new PreviewFileModel() + if(fileData.data_kind == 0) { - AbsolutePath = FormatPathForHighLevel(absolutePath + fileData.d_f, false), - IsDirectory = false, - Name = fileData.d_f, - Path = path + fileData.d_f - }); + // Add directory to list + files.Add(new PreviewFileModel() + { + AbsolutePath = FormatPathForHighLevel(absolutePath + fileData.d_f, true), + IsDirectory = true, + Name = fileData.d_f, + Path = path + fileData.d_f + }); + } + else + { + // Add file to list + files.Add(new PreviewFileModel() + { + AbsolutePath = FormatPathForHighLevel(absolutePath + fileData.d_f, false), + IsDirectory = false, + Name = fileData.d_f, + Path = path + fileData.d_f + }); + } } } } @@ -2349,16 +2354,15 @@ namespace CMS_CORE_Library.Fanuc { string partProgramContent = ""; // Read NC part program content - - string absolutePath = FormatPathForNc(path, ""); - CmsError cmsError = ReadPartProgramContent(absolutePath, ref partProgramContent); + + CmsError cmsError = ReadPartProgramContent(path, ref partProgramContent); if (cmsError.IsError()) return cmsError; // Add to list read data fileInfo = new InfoFile() { - AbsolutePath = absolutePath, + AbsolutePath = path, Name = Path.GetFileName(path), Content = partProgramContent.Split('\n').ToList() }; @@ -2657,7 +2661,7 @@ namespace CMS_CORE_Library.Fanuc private string FormatPathForHighLevel(string path, bool isFolder) { - string tmp = path.Replace('/', '\\'); + string tmp = path.Replace('\\', '/'); if (isFolder) tmp = tmp + "/"; diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index 046fb58..0e84431 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -20,7 +20,7 @@ namespace CMS_CORE_Library.Models public const int USER_SOFTKEYS_NUMBER = 128; public const int NC_SOFTKEYS_NUMBER = 32; - public const int PROCESS_NUMBER = 6; + public const int MAX_PROCESS_NUMBER = 6; public const int ALARMS_NUMBER = 1024; public const int MAX_HEADS_NUMBER = 20; @@ -240,6 +240,7 @@ namespace CMS_CORE_Library.Models public bool Visible; public ushort Reps; public bool IsSelected; + public bool CanLoadProgram; } public class FunctionalityModel @@ -296,7 +297,7 @@ namespace CMS_CORE_Library.Models public Dictionary Buttons; } - public struct MtConnectDataIsNeededModel + public struct M154DataModel { public uint Process; public bool IsNeeded; @@ -316,8 +317,14 @@ namespace CMS_CORE_Library.Models public bool Value; } - public class HeadDataModel + public class ToolInSpindleModel { + public string ToolName; + public int ChildId; + } + + public class HeadDataModel + { public uint Id; public byte Process; public byte Override; @@ -329,6 +336,8 @@ namespace CMS_CORE_Library.Models public bool IsSelected; public bool OverrideEditable; public bool AbrasiveIsActive; + + public ToolInSpindleModel Tool; } public class AxisModel diff --git a/CMS_CORE_Library/Models/NcToolModel.cs b/CMS_CORE_Library/Models/NcToolModel.cs index ca90614..6a1a24e 100644 --- a/CMS_CORE_Library/Models/NcToolModel.cs +++ b/CMS_CORE_Library/Models/NcToolModel.cs @@ -141,8 +141,8 @@ namespace CMS_CORE_Library.Models MaxLoad = obj.MaxLoad, MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation, MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation, - MaxLoadPctAutoload = obj.MaxLoadPctAutoload, MinLoadPctAutoload = obj.MinLoadPctAutoload, + MaxLoadPctAutoload = obj.MaxLoadPctAutoload, DynamicCompensation = obj.DynamicCompensation, LifeType = obj.LifeType, NominalLife = obj.NominalLife, diff --git a/CMS_CORE_Library/Models/SiemensToolModels.cs b/CMS_CORE_Library/Models/SiemensToolModels.cs index 29bff88..8876e48 100644 --- a/CMS_CORE_Library/Models/SiemensToolModels.cs +++ b/CMS_CORE_Library/Models/SiemensToolModels.cs @@ -114,6 +114,7 @@ namespace CMS_CORE_Library.Models public POSITION_TYPE PhysicalType; public int Type; public bool Disabled; + public bool UsedBySpindle; } public class EdgeConfigModel diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 0898ff5..4a65559 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -558,7 +558,7 @@ namespace CMS_CORE_Library public abstract CmsError PLC_WOperatorInputResponse(int process, double responseVal); - public abstract CmsError PLC_RMTConnectData(ref List value); + public abstract CmsError PLC_RM154Data(ref List value); public abstract CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value); diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 426dc05..4b2ece3 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -43,8 +43,8 @@ namespace CMS_CORE_Library.Osai private const string PLC_MESSAGE_PATH = @"C:\CMS\OSAI\"; private readonly string WINNBI_PATH = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\OSAI\WinNBI\"; private const string TOOL_MANAGER_DIRECTORY_PATH = @"ACTIVE\"; - private const string NC_PROGRAM_PATH = @"CAMBIO\"; - private const string NC_PROGRAM_UPLOAD_PATH = @"CAMBIO\UPLOADED_PP\"; + private const string NC_PROGRAM_PATH = @"Programs\"; + private const string NC_PROGRAM_UPLOAD_PATH = @"Programs\UPLOADED_PP\"; //private const string TOOL_MANAGER_DIRECTORY_PATH = @"active\OEM\CMS\SYS\ACTIVE\"; @@ -782,14 +782,13 @@ namespace CMS_CORE_Library.Osai bool[] bits = ByteToBits(val); string[] parameters; string actualLine = ""; - int processId = 0; - foreach (bool bit in bits) + for(uint processId = 1; processId <= MAX_PROCESS_NUMBER; processId ++) { - if (bit) + if (bits[processId - 1]) { // Read active program line - cmsError = ReadActiveLine(processId, ref actualLine); + cmsError = PROC_ReadActiveLine(processId, ref actualLine); if (cmsError.IsError()) return cmsError; @@ -803,32 +802,18 @@ namespace CMS_CORE_Library.Osai value.Add(new M155InputIsNeededModel() { - Process = (uint)processId, - IsNeeded = bit, + Process = processId, + IsNeeded = bits[processId - 1], Message = parameters[0] ?? "", Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request Buttons = buttons }); } - - // Next path - processId++; } return NO_ERROR; } - private CmsError ReadActiveLine(int processId, ref string line) - { - List lines = new List(); - CmsError cmsError = PROC_RPPLines((ushort)processId,ref lines); - if (cmsError.IsError()) - return cmsError; - - line = lines.First(); - - return NO_ERROR; - } public override CmsError PLC_WOperatorInputResponse(int process, double responseVal) { @@ -839,66 +824,132 @@ namespace CMS_CORE_Library.Osai return PLC_WStrobe(M155_INPUT_ACK, M155_INPUT_STROBE, (uint)process); } - public override CmsError PLC_RMTConnectData(ref List value) + public override CmsError PLC_RM154Data(ref List data) { + 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); + string[] parameters; + string tmpStr = ""; + + for (uint processId = 1; processId <= MAX_PROCESS_NUMBER; processId++) + { + if (bits[processId - 1]) + { + // Read active program line + cmsError = PROC_ReadActiveLine(processId, ref tmpStr); + if (cmsError.IsError()) + return cmsError; + + // Parse parameters + parameters = ExtractM154ParametersFromNcCodeLine(tmpStr); + data.Add(new M154DataModel() + { + Process = (uint)processId, + IsNeeded = bits[processId - 1], + ActualLine = parameters + }); + + } + } + return NO_ERROR; } public override CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value) - { - return NO_ERROR; - } - - public override CmsError PLC_WScadaValue(string memIndex, SCADA_MEM_TYPE memType, object value) { string[] index = memIndex.Split('.'); - + CmsError cmsError = NO_ERROR; if (index.Count() == 0) - { return INCORRECT_PARAMETERS_ERROR; - } + else if (index.Count() == 1) { if (memType == SCADA_MEM_TYPE.INT) { - // READ INT + // read INT int val = 0; - CmsError cmsError = MEM_RWInteger(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWInteger(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val); value = val; } else if (memType == SCADA_MEM_TYPE.WORD) - { // READ WORD + { // read WORD ushort val = 0; - CmsError cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWWord(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val); value = val; } + else if (memType == SCADA_MEM_TYPE.REAL) + { // read DOUBLE + double val = 0; + cmsError = MEM_RWDouble(R, 0, MEMORY_TYPE.Osai_GD, Convert.ToInt32(index[0]), ref val); + + value = val; + } else - { // READ byte + { // read BYTE byte val = 0; - CmsError cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), 0, ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), 0, ref val); value = val; } } else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL) - { // READ BOOL + { // read BOOL bool val = false; - CmsError cmsError = MEM_RWBoolean(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val); - if (cmsError.IsError()) - return cmsError; - + cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val); + value = val; } - return NO_ERROR; + return cmsError; + } + + public override CmsError PLC_WScadaValue(string memIndex, SCADA_MEM_TYPE memType, object value) + { + string[] index = memIndex.Split('.'); + CmsError cmsError = NO_ERROR; + if (index.Count() == 0) + return INCORRECT_PARAMETERS_ERROR; + + else if (index.Count() == 1) + { + if (memType == SCADA_MEM_TYPE.INT) + { + // write INT + int val = 0; + cmsError = MEM_RWInteger(W, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val); + } + else if (memType == SCADA_MEM_TYPE.WORD) + { // write WORD + ushort val = 0; + cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val); + } + else if (memType == SCADA_MEM_TYPE.REAL) + { // write DOUBLE + double val = 0; + cmsError = MEM_RWDouble(W, 0, MEMORY_TYPE.Osai_GD, Convert.ToInt32(index[0]), ref val); + + value = val; + } + else + { // write byte + byte val = 0; + cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), 0, ref val); + } + } + else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL) + { // write BOOL + bool val = false; + cmsError = MEM_RWBoolean(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val); + } + + return cmsError; } private CmsError PLC_WStrobe(MEMORY_CELL ackCell, MEMORY_CELL strobeCell, uint id) @@ -1255,6 +1306,7 @@ namespace CMS_CORE_Library.Osai processData.Type = bits[1] ? "WORK" : "AUX"; processData.IsSelected = bits[2]; processData.IsInAlarm = bits[3]; + processData.CanLoadProgram = bits[4]; // Choose process status if (bytes[1] == 1) @@ -1278,7 +1330,7 @@ namespace CMS_CORE_Library.Osai CmsError cmsError; bool readValue = false; - for (int i = 0; i < PROCESS_NUMBER; i++) + for (int i = 0; i < MAX_PROCESS_NUMBER; i++) { int memoryAddress = SELECTED_PROCESS.Address + i * (2); // Read memory from plc @@ -1299,7 +1351,7 @@ namespace CMS_CORE_Library.Osai byte processNum = (byte)procNumber; // Check parameter - if (processNum > PROCESS_NUMBER) + if (processNum > MAX_PROCESS_NUMBER) return INCORRECT_PARAMETERS_ERROR; // Write process number @@ -1310,6 +1362,19 @@ namespace CMS_CORE_Library.Osai return NO_ERROR; } + private CmsError PROC_ReadActiveLine(uint processId, ref string line) + { + List lines = new List(); + CmsError cmsError = PROC_RPPLines((ushort)processId, ref lines); + if (cmsError.IsError()) + return cmsError; + + // The second line is the one under execution + line = lines[1]; + + return NO_ERROR; + } + #endregion PROCESS (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 6eee944..33227bf 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -983,17 +983,25 @@ namespace CMS_CORE_Library.Siemens { // Head address = posizion * size of single head in memory var headOffset = i * headsByte; + short toolId = SwapShortEndianFormat(BitConverter.ToInt16(readValues.ToArray(), headOffset + 4)); + // Find tool + var tool = ToolTableData.Where(x => x.Id == toolId).FirstOrDefault(); heads.Add(new HeadDataModel() { Id = (uint)i + 1, Process = readValues[headOffset], Override = readValues[headOffset + 1], Load_Abrasive = SwapShortEndianFormat(BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2)), // Uint 16 = 2byte - MountedTool_Vacum = SwapShortEndianFormat(BitConverter.ToInt16(readValues.ToArray(), headOffset + 4)), // Uint 16 = 2byte + MountedTool_Vacum = toolId, // Uint 16 = 2byte ActualSpeed_Pressure = SwapIntEndianFormat(BitConverter.ToInt32(readValues.ToArray(), headOffset + 6)), // Int32 = 4byte IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0 IsSelected = (readValues[headOffset + 10] & 2) != 0, // bit 1 - OverrideEditable = (readValues[headOffset + 10] & 4) != 0 // bit 2 + OverrideEditable = (readValues[headOffset + 10] & 4) != 0, // bit 2 + Tool = new ToolInSpindleModel() + { + ChildId = tool == null ? 0 : tool.ChildId, + ToolName = tool == null ? "" : tool.FamilyName, + } }); } @@ -1096,8 +1104,6 @@ namespace CMS_CORE_Library.Siemens dataSvc.Write(item); - - return PLC_WStrobe(M155_INPUT_ACK, M155_INPUT_STROBE,(uint)process); } catch (Exception ex) @@ -1106,7 +1112,7 @@ namespace CMS_CORE_Library.Siemens } } - public override CmsError PLC_RMTConnectData(ref List data) + public override CmsError PLC_RM154Data(ref List data) { byte val = 0; CmsError cmsError = MEM_RWByte(R, 0, MTCONNECT_DATA_NEEDED.MemType, MTCONNECT_DATA_NEEDED.Address, 0, ref val); @@ -1115,90 +1121,125 @@ namespace CMS_CORE_Library.Siemens // Convert a byte to an array of booleans bool[] bits = ByteToBits(val); - uint processId = 1; string[] parameters; string tmpStr = ""; - foreach (bool bit in bits) + for (uint processId = 1; processId <= MAX_PROCESS_NUMBER; processId++) { - // Read active program line - cmsError = PROC_ReadActiveLine(processId, ref tmpStr); - if (cmsError.IsError()) - return cmsError; - - // Parse parameters - parameters = ExtractM154ParametersFromNcCodeLine(tmpStr); - data.Add(new MtConnectDataIsNeededModel() + if(bits[processId - 1]) { - Process = processId, - IsNeeded = bit, - ActualLine = parameters - }); + // Read active program line + cmsError = PROC_ReadActiveLine(processId, ref tmpStr); + if (cmsError.IsError()) + return cmsError; - // Next path - processId++; + // Parse parameters + parameters = ExtractM154ParametersFromNcCodeLine(tmpStr); + data.Add(new M154DataModel() + { + Process = processId, + IsNeeded = bits[processId - 1], + ActualLine = parameters + }); + + } } return NO_ERROR; } public override CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value) - { - return NO_ERROR; - } - - public override CmsError PLC_WScadaValue(string memIndex, SCADA_MEM_TYPE memType, object value) { string[] index = memIndex.Split('.'); - + CmsError cmsError = NO_ERROR; if (index.Count() == 0) - { return INCORRECT_PARAMETERS_ERROR; - } + else if (index.Count() == 1) { if (memType == SCADA_MEM_TYPE.INT) { - // READ INT + // read INT int val = 0; - CmsError cmsError = MEM_RWInteger(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWInteger(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), ref val); value = val; } else if (memType == SCADA_MEM_TYPE.WORD) - { // READ WORD + { // read WORD ushort val = 0; - CmsError cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWWord(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), ref val); + + value = val; + } + else if (memType == SCADA_MEM_TYPE.REAL) + { // read DOUBLE + double val = 0; + cmsError = MEM_RWDouble(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), ref val); value = val; } else - { // READ byte + { // read BYTE byte val = 0; - CmsError cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), 0, ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), 0, ref val); value = val; } } else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL) - { // READ BOOL + { // read BOOL bool val = false; - CmsError cmsError = MEM_RWBoolean(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val); - if (cmsError.IsError()) - return cmsError; + cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val); value = val; } - return NO_ERROR; + return cmsError; } - + + public override CmsError PLC_WScadaValue(string memIndex, SCADA_MEM_TYPE memType, object value) + { + string[] index = memIndex.Split('.'); + CmsError cmsError = NO_ERROR; + if (index.Count() == 0) + return INCORRECT_PARAMETERS_ERROR; + + else if (index.Count() == 1) + { + if (memType == SCADA_MEM_TYPE.INT) + { + // write INT + int val = 0; + cmsError = MEM_RWInteger(W, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val); + } + else if (memType == SCADA_MEM_TYPE.WORD) + { // write WORD + ushort val = 0; + cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val); + } + else if (memType == SCADA_MEM_TYPE.REAL) + { // write DOUBLE + double val = 0; + cmsError = MEM_RWDouble(W, 0, MEMORY_TYPE.Osai_GD, Convert.ToInt32(index[0]), ref val); + + value = val; + } + else + { // write byte + byte val = 0; + cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), 0, ref val); + } + } + else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL) + { // write BOOL + bool val = false; + cmsError = MEM_RWBoolean(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val); + } + + return cmsError; + } + private CmsError PLC_WStrobe(MEMORY_CELL ackCell, MEMORY_CELL strobeCell, uint id) { CmsError cmsError; @@ -1487,7 +1528,8 @@ namespace CMS_CORE_Library.Siemens processData.Type = bits[1] ? "WORK" : "AUX"; processData.IsSelected = bits[2]; processData.IsInAlarm = bits[3]; - + processData.CanLoadProgram = bits[4]; + // Choose process status if (bytes[1] == 1) processData.Status = "HOLD"; @@ -1536,7 +1578,7 @@ namespace CMS_CORE_Library.Siemens byte processNum = (byte)procNumber; // Check parameter - if (processNum > PROCESS_NUMBER) + if (processNum > MAX_PROCESS_NUMBER) return INCORRECT_PARAMETERS_ERROR; // Write process number @@ -4688,7 +4730,10 @@ namespace CMS_CORE_Library.Siemens { int index = MagazinePositionsData.FindIndex(x => x.PositionId == secondId && x.MagazineId == firstId); if (index >= 0) + { MagazinePositionsData[index].Disabled = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 1); + MagazinePositionsData[index].UsedBySpindle = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 2); + } } break; diff --git a/CMS_CORE_Library/ToolConfigurations.cs b/CMS_CORE_Library/ToolConfigurations.cs index a0533a6..487baf5 100644 --- a/CMS_CORE_Library/ToolConfigurations.cs +++ b/CMS_CORE_Library/ToolConfigurations.cs @@ -100,8 +100,7 @@ namespace CMS_CORE_Library {6, "loading_station" }, {7, "loading_point" } }; - - + private static Dictionary cmsRotationTypeList = new Dictionary() { {0, "none"}, @@ -109,6 +108,7 @@ namespace CMS_CORE_Library {2, "counterClockWhise"}, {3, "doubleRotation"} }; + #endregion PRIVATE_SELECTS_VALUES /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -187,11 +187,12 @@ namespace CMS_CORE_Library public static List SiemensMagazinePosFieldsConfig = new List() { - new FieldsConfiguration{ Name = "magazineId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, - new FieldsConfiguration{ Name = "positionId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, - new FieldsConfiguration{ Name = "type", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, - new FieldsConfiguration{ Name = "physicalType", Type = "select", SelectValues = physicalType, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, - new FieldsConfiguration{ Name = "disabled", Type = "boolean", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = 0 } + new FieldsConfiguration{ Name = "magazineId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, + new FieldsConfiguration{ Name = "positionId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, + new FieldsConfiguration{ Name = "type", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, + new FieldsConfiguration{ Name = "physicalType", Type = "select", SelectValues = physicalType, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, + new FieldsConfiguration{ Name = "usedBySpindle", Type = "boolean", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, + new FieldsConfiguration{ Name = "disabled", Type = "boolean", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = 0 } }; public static EdgesConfiguration SiemensEdgesFieldsConfiguration = new EdgesConfiguration()