diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 6f7c70e..2067095 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -139,6 +139,8 @@ namespace CMS_CORE_Application Stopwatch st = new Stopwatch(); sw.Restart(); + ActiveProgramDataModel a = new ActiveProgramDataModel(); + cmsError = N.FILES_RActiveProgramData(1, ref a); OffsetModel offset = new OffsetModel(); N.TOOLS_ROffset(1, ref offset); diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 667e252..b9b4a3c 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -432,13 +432,13 @@ namespace CMS_CORE_Library.Siemens Timeout = TimeoutConn, PriorityFlag = SlPriority.lowPriority }; - Item ReadItem = new Item(NC_TIME_PATH); + Item itemRead = new Item(NC_TIME_PATH); //Read Data - Data.Read(ReadItem); + Data.Read(itemRead); //Save Data - ActualTime = (DateTime)ReadItem.Value; + ActualTime = (DateTime)itemRead.Value; } catch (Exception ex) { @@ -975,17 +975,17 @@ namespace CMS_CORE_Library.Siemens Timeout = TimeoutConn, PriorityFlag = SlPriority.highPriority }; - Item ReadItem = new Item(NC_GENERIC_MODE_PATH + "[u" + ProcNumber + "]"); - Item ReadItemIncr = new Item(JOG_INCR_PATH + "[u" + ProcNumber + "]"); - Item ReadItemAdv = new Item(ADVANCED_JOG_PATH + "[u" + ProcNumber + "]"); + Item itemRead = new Item(NC_GENERIC_MODE_PATH + "[u" + ProcNumber + "]"); + Item itemReadIncr = new Item(JOG_INCR_PATH + "[u" + ProcNumber + "]"); + Item itemReadAdv = new Item(ADVANCED_JOG_PATH + "[u" + ProcNumber + "]"); //Read Data - Data.Read(ReadItem); - Data.Read(ReadItemIncr); - Data.Read(ReadItemAdv); + Data.Read(itemRead); + Data.Read(itemReadIncr); + Data.Read(itemReadAdv); //Save Data - Mode = ConvertToSTEPMode((uint)ReadItem.Value, (uint)ReadItemIncr.Value, (uint)ReadItemAdv.Value); + Mode = ConvertToSTEPMode((uint)itemRead.Value, (uint)itemReadIncr.Value, (uint)itemReadAdv.Value); } catch (Exception ex) { @@ -1012,13 +1012,13 @@ namespace CMS_CORE_Library.Siemens Timeout = TimeoutConn, PriorityFlag = SlPriority.highPriority }; - Item ReadItem = new Item(NC_GENERIC_STATE_PATH + "[u" + ProcNumber + "]"); + Item itemRead = new Item(NC_GENERIC_STATE_PATH + "[u" + ProcNumber + "]"); //Read Data - Data.Read(ReadItem); + Data.Read(itemRead); //Save Data - Status = ConvertToSTEPStatus((uint)ReadItem.Value); + Status = ConvertToSTEPStatus((uint)itemRead.Value); } catch (Exception ex) { @@ -1046,17 +1046,17 @@ namespace CMS_CORE_Library.Siemens Timeout = TimeoutConn, PriorityFlag = SlPriority.highPriority }; - Item ReadItem = new Item(ACT_PROG_LINES_PATH + "[u" + ProcNumber + "]"); + Item itemRead = new Item(ACT_PROG_LINES_PATH + "[u" + ProcNumber + "]"); //Read Data - Data.Read(ReadItem); + Data.Read(itemRead); //Save Data - newLines = ((String)ReadItem.Value).Replace("\r", string.Empty).Split('\n'); + newLines = ((string)itemRead.Value).Replace("\r", string.Empty).Split('\n'); //Setup the return values Lines.Clear(); - foreach (String Line in newLines) + foreach (string Line in newLines) Lines.Add(Line); //Remove the first Line (the previous line) @@ -1086,18 +1086,14 @@ namespace CMS_CORE_Library.Siemens try { //Setup variables - DataSvc Data = new DataSvc - { - Timeout = TimeoutConn, - PriorityFlag = SlPriority.highPriority - }; - Item ReadItem = new Item(ACT_PROG_NAME_PATH + "[u" + ProcNumber + "]"); + DataSvc Data = new DataSvc { Timeout = TimeoutConn, PriorityFlag = SlPriority.highPriority }; + Item itemRead = new Item(ACT_PROG_NAME_PATH + "[u" + ProcNumber + "]"); //Read Data - Data.Read(ReadItem); + Data.Read(itemRead); //Elaborate String - RetString = ((string)ReadItem.Value); + RetString = ((string)itemRead.Value); RetString = RetString.Replace("_N_", ""); LastUnderscore = RetString.LastIndexOf("_"); if (LastUnderscore >= 0) @@ -1143,7 +1139,7 @@ namespace CMS_CORE_Library.Siemens byte[] bytes = BitConverter.GetBytes(readValue); // Convert Byte into true/false array - BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible + BitArray bits = new BitArray(new byte[] { bytes[0] }); // 1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible // Get part program info visibility processData.Visible = bits[0]; @@ -1912,20 +1908,31 @@ namespace CMS_CORE_Library.Siemens FileSvc fileSvc = new FileSvc(); - // string trimString = tmpPath.Replace("_DIR", ""); + string trimString = tmpPath.Replace("_DIR", ""); // Preapare folder node - Node fileNode = new Node(@"//PARTPRG:/ciao.spf"); + Node fileNode = new Node(trimString); + if(fileNode != null) + fileInfo = new InfoFile() + { + CreationDate = fileNode.Attributes.LastAccess, + LastModDate = fileNode.Attributes.LastAccess, + Name = fileNode.Name, + Content = new List() { fileNode.LogicalPath }, + PreviewBase64 = FindImageBase64String(IMAGES_PATH, fileNode.Name), + AbsolutePath = fileNode.LogicalPath + }; + else + fileInfo = new InfoFile() + { + CreationDate = fileNode.Attributes.LastAccess, + LastModDate = fileNode.Attributes.LastAccess, + Name = fileNode.Name, + Content = new List() { fileNode.LogicalPath }, + PreviewBase64 = FindImageBase64String(IMAGES_PATH, fileNode.Name), + AbsolutePath = fileNode.LogicalPath + }; - fileInfo = new InfoFile() - { - CreationDate = fileNode.Attributes.LastAccess, - LastModDate = fileNode.Attributes.LastAccess, - Name = fileNode.Name, - Content = new List() { fileNode.LogicalPath }, - PreviewBase64 = FindImageBase64String(IMAGES_PATH, fileNode.Name), - AbsolutePath = fileNode.LogicalPath - }; } catch (Exception ex) { @@ -1968,35 +1975,42 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } - public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel data) + public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel programData) { try { - int lastUnderscore; - //Setup variables - DataSvc Data = new DataSvc - { - Timeout = TimeoutConn, - PriorityFlag = SlPriority.highPriority - }; - - Item readItem = new Item("/Channel/ProgramInfo/workPandProgName " + "[u" + processId + "]"); + DataSvc dataSvc = new DataSvc(); + + // Read position and tool data + List itemRead = new List() + { + new Item($"/Channel/ProgramInfo/workPandProgName[u{processId}]"), + new Item($"/Channel/ProgramInfo/actPartProgram[u{processId}]") + }; //Read Data - Data.Read(readItem); + dataSvc.Read(itemRead.ToArray()); // Elaborate String - string trimString = ((string)readItem.Value); + string trimString = ((string)itemRead[0].Value); trimString = trimString.Replace("_N_", ""); - lastUnderscore = trimString.LastIndexOf("_"); + int lastUnderscore = trimString.LastIndexOf("_"); if (lastUnderscore >= 0) trimString = trimString.Remove(lastUnderscore, 1).Insert(lastUnderscore, "."); - data = new ActiveProgramDataModel() + // Separate string into list of lines + List isoLines = itemRead[1] + .Value + .ToString() + .Split('\n') // Line separator + .Skip(1) // The actPartProgram read starting with the line before the current + .ToList(); + + programData = new ActiveProgramDataModel() { Path = trimString, - IsoLines = new List(), + IsoLines = isoLines, TimeLeft = new DateTime() }; }