diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index cf211fe..bc9a569 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -111,11 +111,12 @@ namespace CMS_CORE_Application ////////////////////////////////////////// TEST Stopwatch st = new Stopwatch(); sw.Restart(); + ActiveProgramDataModel active = new ActiveProgramDataModel(); + string name = ""; + + N.PROC_RSelectedPPName(1, ref name); + cmsError = N.FILES_RActiveProgramData(1, ref active); - cmsError = N.PLC_WOperatorInputResponse(1, 230.0); - double test = 55.5423; - N.MEM_RWDouble(true, 1, Nc.MEMORY_TYPE.Osai_GD, 900, ref test); - Console.WriteLine("TIME " + sw.ElapsedMilliseconds); sw.Stop(); /////////////////////////////////////////// END TEST diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 17d9677..dce4ec9 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -1166,6 +1166,28 @@ namespace CMS_CORE_Library.Demo return NO_ERROR; } + public override CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData) + { + byte val = 0; + CmsError cmsError = MEM_RWByte(R, 1, OFFSET_ID.MemType, OFFSET_ID.Address, 0, ref val); + if (cmsError.IsError()) + return cmsError; + + processData = new SelectedProcessData() + { + ActiveOffsetId = val + }; + val = 0; + + cmsError = MEM_RWByte(R, 1, ORIGIN_DATA.MemType, ORIGIN_DATA.Address, 0, ref val); + if (cmsError.IsError()) + return cmsError; + + processData.Origin = val; + + return NO_ERROR; + } + #endregion PROCESS (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3280,6 +3302,9 @@ namespace CMS_CORE_Library.Demo internal static MEMORY_CELL MTCONNECT_DATA_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Demo, 457, 1); internal static MEMORY_CELL MTCONNECT_ONOFF = new MEMORY_CELL(MEMORY_TYPE.Demo, 458, 1); + + internal static MEMORY_CELL ORIGIN_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 459, 1); + internal static MEMORY_CELL OFFSET_ID = new MEMORY_CELL(MEMORY_TYPE.Demo, 460, 1); } #endregion Memory addresses diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 171ede9..66a46c9 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -462,7 +462,7 @@ namespace CMS_CORE_Library.Fanuc if (cmsError.IsError()) return cmsError; - unitOfMeasure = val ? "inch" : "mm"; + unitOfMeasure = val ? INCHES : MILLIMETERS; return NO_ERROR; } @@ -718,6 +718,21 @@ namespace CMS_CORE_Library.Fanuc // Get all the machine counters public override CmsError PLC_RMachineCounters(ref List counters) { + //List val = new List(); + //// Read ints + //CmsError cmsError = MEM_RWDWordList(R, 0, COUNTERS_DATA.MemType, COUNTERS_DATA.Address, COUNTERS_DATA.SubAddress, COUNTERS_DATA.Size / 4, ref val); + //if (cmsError.IsError()) + // return cmsError; + + //// Set return value + //uint i = 0; + //counters = val.Select(x => new CounterModel() + //{ + // Id = i++, + // Value = x + //}) + //.ToList(); + return NO_ERROR; } @@ -1220,8 +1235,13 @@ namespace CMS_CORE_Library.Fanuc if (path < 0) return PROC_NOT_FOUND_ERROR; + char[] tmp = new char[244]; + nReturn = Focas1.cnc_pdf_rdmain(nLibHandle[path], tmp); + + name = new string(tmp); + //Execute the method - nReturn = Focas1.cnc_exeprgname(nLibHandle[path], partPrg); + // nReturn = Focas1.cnc_exeprgname(nLibHandle[path], partPrg); //Throw Exception if there's an error if (nReturn != 0) @@ -1341,6 +1361,11 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } + public override CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData) + { + return NO_ERROR; + } + #endregion PROCESS (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4292,7 +4317,7 @@ namespace CMS_CORE_Library.Fanuc internal static MEMORY_CELL HEADS_STROBE_INCREMENT = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2924, 4); internal static MEMORY_CELL HEADS_STROBE_DECREMENT = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2927, 4); - internal static MEMORY_CELL COUNTERS = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2930, 0, 44); + internal static MEMORY_CELL COUNTERS_DATA = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2930, 0, 44); internal static MEMORY_CELL COUNTER_IS_RESETTABLE = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2998, 0, 2); internal static MEMORY_CELL COUNTER_IS_RESETTABLE_ACK = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 3000, 0, 2); internal static MEMORY_CELL COUNTER_IS_RESETTABLE_STROBE = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 3002, 0, 2); @@ -4306,7 +4331,7 @@ namespace CMS_CORE_Library.Fanuc internal static MEMORY_CELL M154_ACK = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 3032, 1); internal static MEMORY_CELL AXES_BUTTON_VISIBLE = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 3033, 16); - + // Tool manager areas internal static MEMORY_CELL MAGAZINE_ACTION = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 4000, 16); diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index e31083b..0489b4e 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -381,6 +381,23 @@ namespace CMS_CORE_Library.Models public bool StartStopQueueEnabled; } + public class SelectedProcessData + { + public short Origin { get; set; } + + public short ActiveOffsetId { get; set; } + } + + public enum ORIGIN + { + NONE = 0, + G54 = 1, + G55 = 2, + G56 = 3, + G57 = 4, + G505 = 5 + } + public enum QUEUE_STATUS { NOT_ACTIVE = 0, diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 704886b..13dbfa9 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -681,6 +681,8 @@ namespace CMS_CORE_Library public abstract CmsError PROC_WSelectProcess(ushort procNumber); + public abstract CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData); + #endregion PROCESS (PATH, CHANNEL) data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index efb7558..18218b8 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -419,16 +419,16 @@ namespace CMS_CORE_Library.Osai switch (info.feedmisunit) { case 0: - unitOfMeasure = "inch"; + unitOfMeasure = INCHES; break; case 1: - unitOfMeasure = "mm"; + unitOfMeasure = MILLIMETERS; break; case 2: - unitOfMeasure = "inch"; + unitOfMeasure = INCHES; break; case 3: - unitOfMeasure = "mm"; + unitOfMeasure = MILLIMETERS; break; } @@ -650,6 +650,21 @@ namespace CMS_CORE_Library.Osai public override CmsError PLC_RMachineCounters(ref List counters) { + List val = new List(); + // Read ints + CmsError cmsError = MEM_RWDWordList(R, 0, COUNTERS_DATA.MemType, COUNTERS_DATA.Address, COUNTERS_DATA.SubAddress, COUNTERS_DATA.Size / 4, ref val); + if (cmsError.IsError()) + return cmsError; + + // Set return value + uint i = 0; + counters = val.Select(x => new CounterModel() + { + Id = i++, + Value = x + }) + .ToList(); + return NO_ERROR; } @@ -1319,7 +1334,7 @@ namespace CMS_CORE_Library.Osai try { // Execute the method - nReturn = OpenNC.GetActivePartProgram(ProcNumber, out Level, out MainName, out SubName, out uint errorClass, out uint errorNum); + nReturn = OpenNC.GetActivePartProgramFullPath(ProcNumber, out Level, out MainName, out SubName, out uint errorClass, out uint errorNum); // If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -1432,6 +1447,29 @@ namespace CMS_CORE_Library.Osai return NO_ERROR; } + public override CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData) + { + // Read active tool offset + ushort nReturn = OpenNC.GetNcInfo1((ushort)processId, out GETINFO1DATA info, out uint errorClass, out uint errorNum); + if (errorClass != 0 || errorNum != 0 || nReturn == 0) + return GetNCError(errorClass, errorNum); + + ushort axesR = 1; + // Read origins + nReturn = OpenNC.GetAxOriginNum((ushort)processId, ref axesR, out AXORIGNUMC4array axOrigin, out errorClass, out errorNum); + if (errorClass != 0 || errorNum != 0 || nReturn == 0) + return GetNCError(errorClass, errorNum); + + short axOr = axOrigin.Count() > 1 ? axOrigin[0].OriginNumber : (short)0; + processData = new SelectedProcessData() + { + ActiveOffsetId = (short)info.actualtooloff, + Origin = axOr + }; + + return NO_ERROR; + } + #endregion PROCESS (PATH) High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1460,7 +1498,7 @@ namespace CMS_CORE_Library.Osai nReturn = OpenNC.GetAxesPosition(process, 0, OSAI_INTERPOLPOS, ref nAxis, out GETINTDATAC4array Pos, out uint errorClass, out uint errorNum); - //If there's an error launch exception + // if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); @@ -2003,6 +2041,7 @@ namespace CMS_CORE_Library.Osai byte TempVal = 0; int MemIndexTemp = MemIndex; List WordList = new List(); + CmsError cmsError = null; //Save if i have to start from Higher bit @@ -2421,6 +2460,12 @@ namespace CMS_CORE_Library.Osai // Open file FileStream fileStream = new FileStream(localPath + "\\" + name, FileMode.Open); newFilePath = NC_PROGRAM_UPLOAD_PATH + name; + + // Create directory + ushort nReturn = OpenNC.LogFSCreateDir(NC_PROGRAM_UPLOAD_PATH, out uint errClass, out uint errNum); + if (errClass != 0 || errNum != 0 || nReturn == 0) + return GetNCError(errClass, errNum); + // Transfer file on NC CmsError cmsError = FILES_WProgramFromFile(newFilePath, fileStream); if (cmsError.IsError()) @@ -4115,7 +4160,7 @@ namespace CMS_CORE_Library.Osai internal static MEMORY_CELL HEADS_STROBE_INCREMENT = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4240, 4); internal static MEMORY_CELL HEADS_STROBE_DECREMENT = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4250, 4); - internal static MEMORY_CELL COUNTERS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4260, 0, 40); + internal static MEMORY_CELL COUNTERS_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4260, 0, 40); internal static MEMORY_CELL COUNTER_IS_RESETTABLE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4300, 0, 2); internal static MEMORY_CELL COUNTER_IS_RESETTABLE_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4302, 0, 2); internal static MEMORY_CELL COUNTER_IS_RESETTABLE_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4304, 0, 2); diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 06d12a3..bb936db 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -1650,6 +1650,44 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } + + public override CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData) + { + try + { + Item[] items = new Item[2] + { + new Item { Path = "/Channel/State/actDLNumber[u" + processId + ",1]" }, // OffsetId + new Item { Path = "/Channel/State/actFrameIndex[u" + processId + "]" }, // Origin + }; + + // Read data + DataSvc dataSvc = new DataSvc(); + dataSvc.Read(items); + + short origin = 0; + // Convert SIEMENS enumerable to G(N) + if (Convert.ToInt16(items[1].Value) > 0) + { + if (Convert.ToInt16(items[1].Value) >= 5) + origin = (short)(Convert.ToInt16(items[1].Value) + 500); + else + origin = (short)(Convert.ToInt16(items[1].Value) + 53); + } + + processData = new SelectedProcessData + { + ActiveOffsetId = Convert.ToInt16(items[0].Value), + Origin = origin + }; + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } private CmsError PROC_ReadActiveLine(uint processId, ref string line) {