From 674c68ac1dfd951453c185c45df7d7cb2014df63 Mon Sep 17 00:00:00 2001 From: Nicola Carminati Date: Fri, 21 Sep 2018 07:55:31 +0000 Subject: [PATCH] Fixed a lot of issues --- CMS_CORE_Library/DataStructures.cs | 2 + CMS_CORE_Library/Demo/Nc_Demo.cs | 79 ++++++++++++++++---------- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 19 ++++--- CMS_CORE_Library/Nc.cs | 6 +- CMS_CORE_Library/Osai/Nc_Osai.cs | 10 +++- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 6 +- CMS_CORE_Library/ToolConfigurations.cs | 26 +++++---- 7 files changed, 93 insertions(+), 55 deletions(-) diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs index 630f7fa..12ada0f 100644 --- a/CMS_CORE_Library/DataStructures.cs +++ b/CMS_CORE_Library/DataStructures.cs @@ -305,6 +305,7 @@ namespace CMS_CORE_Library public class QueueStatusModel { + public int ProcessId; public bool LoadNextProgram; public QUEUE_STATUS Status; public bool StartStopQueueEnabled; @@ -741,6 +742,7 @@ namespace CMS_CORE_Library public bool MultitoolOptionActive; public bool FamilyOptionActive; public bool MagPositionOptionActive; + public bool OffsetOptionActive; public List Magazines; public List ToolsConfiguration; diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 779206b..c6f76b4 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -1796,47 +1796,63 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError FILES_RQueueData(ref QueueStatusModel status) + public override CmsError FILES_RQueueData(ref List statusList) { - // Check if the NC Demo is Connected - CmsError cmsError = CheckConnection(); - if (cmsError.IsError()) - return cmsError; - - // Read status - byte readStatus = 0; - cmsError = MEM_RWByte(R, 0, QUEUE_STATUS_MEM.MemType, QUEUE_STATUS_MEM.Address, 0, ref readStatus); + // Read all the values + List ints = new List(); + CmsError cmsError = MEM_RWIntegerList(R, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address, 6, ref ints); if (cmsError.IsError()) return cmsError; - // Read next cmd - byte next = 0; - cmsError = MEM_RWByte(R, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address, 0, ref next); + int processId = 0; + // Foreach value + foreach(var val in ints) + { + byte[] bytes = BitConverter.GetBytes(val); + + if (bytes[0] == 1) + { + // Read tool manager status + byte zero = 0; + cmsError = MEM_RWByte(W, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address + (processId * 4), 0, ref zero); + if (cmsError.IsError()) + return cmsError; + } + + QueueStatusModel tmpStatus = new QueueStatusModel() + { + LoadNextProgram = bytes[0] == 1, + Status = (QUEUE_STATUS)bytes[1], + StartStopQueueEnabled = bytes[2] == 1, + ProcessId = processId + 1 + }; + + statusList.Add(tmpStatus); + + processId += 1; + }; + + return NO_ERROR; + } + + public override CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId) + { + // Read all the values + int ints = 0; + CmsError cmsError = MEM_RWInteger(R, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address + ((processId - 1) * 4), ref ints); if (cmsError.IsError()) return cmsError; - // Read start & stop - byte startStopActive = 0; - cmsError = MEM_RWByte(R, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address, 0, ref startStopActive); - if (cmsError.IsError()) - return cmsError; + byte[] bytes = BitConverter.GetBytes(ints); status = new QueueStatusModel() { - LoadNextProgram = next == 1, - Status = (QUEUE_STATUS)readStatus, - StartStopQueueEnabled = startStopActive == 1 + LoadNextProgram = bytes[0] == 1, + Status = (QUEUE_STATUS)bytes[1], + StartStopQueueEnabled = bytes[2] == 1, + ProcessId = processId }; - - if (next == 1) - { - // Read tool manager status - byte val = 0; - cmsError = MEM_RWByte(W, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address, 0, ref val); - if (cmsError.IsError()) - return cmsError; - } - + return NO_ERROR; } @@ -2988,7 +3004,8 @@ namespace CMS_CORE.Demo internal static MEMORY_CELL MAGAZINES_ENABLED_CMD = new MEMORY_CELL(MEMORY_TYPE.Demo, 441, 4); internal static MEMORY_CELL QUEUE_NEXT = new MEMORY_CELL(MEMORY_TYPE.Demo, 445, 1); internal static MEMORY_CELL QUEUE_STATUS_MEM = new MEMORY_CELL(MEMORY_TYPE.Demo, 446, 1); - internal static MEMORY_CELL QUEUE_CMD = new MEMORY_CELL(MEMORY_TYPE.Demo, 447, 1); + 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); } #endregion Memory addresses diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 70047bc..163519b 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -144,11 +144,11 @@ namespace CMS_CORE.Fanuc byte langToWrite = (byte)(ConvertToNCLanguage(Language) | 128); // write the byte - CmsError cmsError = MEM_RWByte(W,0, PARAM_LING_FANUC_W.MemType, PARAM_LING_FANUC_W.Address, 0, ref langToWrite); + CmsError cmsError = MEM_RWByte(W, 0, PARAM_LING_FANUC_W.MemType, PARAM_LING_FANUC_W.Address, 0, ref langToWrite); if (cmsError.IsError()) return cmsError; - + return NO_ERROR; } @@ -1606,7 +1606,7 @@ namespace CMS_CORE.Fanuc { return NO_ERROR; } - + public override CmsError FILES_RGetFileInfo(string path, ref InfoFile fileInfo) { return NO_ERROR; @@ -1740,11 +1740,14 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - public override CmsError FILES_RQueueData(ref QueueStatusModel status) + public override CmsError FILES_RQueueData(ref List statusList) { return NO_ERROR; } + public override CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId) + { return NO_ERROR; } + public override CmsError FILES_WStartQueue() { return NO_ERROR; @@ -1762,9 +1765,9 @@ namespace CMS_CORE.Fanuc #endregion File Management - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region Tools Management + #region Tools Management public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config) { @@ -1936,7 +1939,7 @@ namespace CMS_CORE.Fanuc { return NO_ERROR; } - + public override CmsError TOOLS_WUpdateShanks(List list) { return NO_ERROR; @@ -1998,7 +2001,7 @@ namespace CMS_CORE.Fanuc default: return 0; } } - + private CmsError ErrorHandler(short exNum) { if (exNum != 0) diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 20de4e7..aadbba8 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1366,8 +1366,10 @@ namespace CMS_CORE public abstract CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName); - public abstract CmsError FILES_RQueueData(ref QueueStatusModel status); - + public abstract CmsError FILES_RQueueData(ref List statusList); + + public abstract CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId); + public abstract CmsError FILES_WStartQueue(); public abstract CmsError FILES_WStopQueue(); diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 1589375..78dbebe 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -130,8 +130,9 @@ namespace CMS_CORE.Osai public override CmsError NC_Disconnect() { //Set Connected to FALSE and close the session - OpenNC.Close(); - Connected = false; + if(Connected) + OpenNC.Close(); + Connected = false; return NO_ERROR; } @@ -2312,11 +2313,14 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError FILES_RQueueData(ref QueueStatusModel status) + public override CmsError FILES_RQueueData(ref List statusList) { return NO_ERROR; } + public override CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId) + { return NO_ERROR; } + public override CmsError FILES_WStartQueue() { return NO_ERROR; diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 283979a..439925a 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -2142,11 +2142,15 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError FILES_RQueueData(ref QueueStatusModel status) + public override CmsError FILES_RQueueData(ref List statusList) { return NO_ERROR; } + public override CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId) + { return NO_ERROR; } + + public override CmsError FILES_WStartQueue() { return NO_ERROR; diff --git a/CMS_CORE_Library/ToolConfigurations.cs b/CMS_CORE_Library/ToolConfigurations.cs index 31cae2e..c84356f 100644 --- a/CMS_CORE_Library/ToolConfigurations.cs +++ b/CMS_CORE_Library/ToolConfigurations.cs @@ -73,6 +73,14 @@ namespace CMS_CORE_Library {7, "loading_point" } }; + + private static Dictionary cmsRotationTypeList = new Dictionary() + { + {0, "none"}, + {1, "clockWhise"}, + {2, "counterClockWhise"}, + {3, "doubleRotation"} + }; #endregion PRIVATE_SELECTS_VALUES /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -180,16 +188,14 @@ namespace CMS_CORE_Library new FieldsConfiguration{ Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0}, new FieldsConfiguration{ Name = "shankId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0}, new FieldsConfiguration{ Name = "familyId", Type = "select", SelectValues = new Dictionary(), Category = "general", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, - new FieldsConfiguration{ Name = "offsetLength", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, + //new FieldsConfiguration{ Name = "offsetLength", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, new FieldsConfiguration{ Name = "disabled", Type = "boolean", SelectValues = null, Category = "status", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, new FieldsConfiguration{ Name = "broken", Type = "boolean", SelectValues = null, Category = "status", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, new FieldsConfiguration{ Name = "measured", Type = "boolean", SelectValues = null, Category = "status", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, - new FieldsConfiguration{ Name = "clockwiseRotation", Type = "boolean", SelectValues = null, Category = "status", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, - new FieldsConfiguration{ Name = "counterClockwiseRotation", Type = "boolean", SelectValues = null, Category = "status", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, - new FieldsConfiguration{ Name = "residualLife", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, - new FieldsConfiguration{ Name = "offsetId1", Type = "int", SelectValues = null, Category = "offset", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, - new FieldsConfiguration{ Name = "offsetId2", Type = "int", SelectValues = null, Category = "offset", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, - new FieldsConfiguration{ Name = "offsetId3", Type = "int", SelectValues = null, Category = "offset", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, + new FieldsConfiguration{ Name = "residualLife", Type = "int", SelectValues = null, Category = "life", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, + new FieldsConfiguration{ Name = "offsetId1", Type = "int", SelectValues = null, Category = "offset", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, + new FieldsConfiguration{ Name = "offsetId2", Type = "int", SelectValues = null, Category = "offset", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, + new FieldsConfiguration{ Name = "offsetId3", Type = "int", SelectValues = null, Category = "offset", ReadOnly = false, MinValue = 0, MaxValue = ushort.MaxValue}, }; public static FamiliesConfiguration NcFamilyFieldsConfig = new FamiliesConfiguration() @@ -199,11 +205,11 @@ namespace CMS_CORE_Library new FieldsConfiguration{ Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0}, new FieldsConfiguration{ Name = "name", Type = "string", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = 0}, new FieldsConfiguration{ Name = "toolType", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "leftSize", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "rightSize", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "leftSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "rightSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "tcpTable", Type = "int", SelectValues = null, Category = "tcp", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "gamma", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "rotationType", Type = "int", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "rotationType", Type = "select", SelectValues = cmsRotationTypeList, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "cooling", Type = "boolean", SelectValues = null, Category = "cooling", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue}, new FieldsConfiguration{ Name = "cooling1", Type = "boolean", SelectValues = null, Category = "cooling", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue},