diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index baebb8a..09faa1c 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -209,9 +209,9 @@ namespace CMS_CORE_Library.Fanuc { try { - foreach(string file in Directory.GetFiles(PLC_MESSAGE_PATH)) + foreach (string file in Directory.GetFiles(PLC_MESSAGE_PATH)) { - if(Path.GetExtension(file) == ".txt") + if (Path.GetExtension(file) == ".txt") { string fileName = Path.GetFileNameWithoutExtension(file); @@ -273,7 +273,7 @@ namespace CMS_CORE_Library.Fanuc // // Wait before read // Thread.Sleep(200); - // cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Fanuc_F, 545, 0, ref b); + // cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Fanuc_F, 545, 0, ref b); // // Decrement // n--; //} while (!b && n > 0); @@ -283,7 +283,6 @@ namespace CMS_CORE_Library.Fanuc //if (cmsError.IsError()) // return cmsError; - /////// FANUC METODO // //byte lang = ConvertToNCLanguage(Language, out bool isSpecial); @@ -329,7 +328,6 @@ namespace CMS_CORE_Library.Fanuc SWV = Cnc_SftVersion; - return NO_ERROR; } @@ -533,7 +531,7 @@ namespace CMS_CORE_Library.Fanuc return GetNcError(nReturn); OFFSET_DECIMAL_DIGITS = input[0]; - + return NO_ERROR; } @@ -543,7 +541,7 @@ namespace CMS_CORE_Library.Fanuc CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - + short nReturn = Focas1.cnc_wrmdiprog(nLibHandle[processId - 1], (short)mdiString.Count(), mdiString.ToArray()); if (nReturn != 0) return GetNcError(nReturn); @@ -796,7 +794,7 @@ namespace CMS_CORE_Library.Fanuc if (!isResettable) return FUNCTION_NOT_ALLOWED_ERROR; - + cmsError = PLC_WStrobe(COUNTER_IS_RESETTABLE_ACK, COUNTER_IS_RESETTABLE_STROBE, counter); if (cmsError.IsError()) return cmsError; @@ -899,7 +897,7 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - + public override CmsError PLC_RWorkedTimeHead(int head, ref uint time) { int index = (head - 1) * 4; @@ -935,7 +933,7 @@ namespace CMS_CORE_Library.Fanuc public override CmsError PLC_RWorkedTimeMachine(ref uint time) { - // Read Worked time + // Read Worked time CmsError cmsError = MEM_RWDWord(R, 0, MACHINE_WORKED_TIME.MemType, MACHINE_WORKED_TIME.Address, ref time); if (cmsError.IsError()) return cmsError; @@ -975,7 +973,6 @@ namespace CMS_CORE_Library.Fanuc cmsError = MEM_RWBoolean(R, 0, MACHINE_RESET_WORKED_TIME.MemType, MACHINE_RESET_WORKED_TIME.Address, 0, ref bitValue); if (cmsError.IsError()) return cmsError; - } while (bitValue && nTry <= 10); //se il valore è rimasto a 1 il plc non l'ha preso in carico, e abortisco @@ -993,7 +990,6 @@ namespace CMS_CORE_Library.Fanuc //Se l'ha abbassato scrivo il nuovo dato cmsError = MEM_RWDWord(W, 0, MACHINE_WORKED_TIME.MemType, MACHINE_WORKED_TIME.Address, ref time); } - } return NO_ERROR; @@ -1007,7 +1003,7 @@ namespace CMS_CORE_Library.Fanuc MEMORY_CELL currentStrobeCell = sign == HEAD_OVERRIDE_SIGN.PLUS ? HEADS_STROBE_INCREMENT : HEADS_STROBE_DECREMENT; // Write strobe into memory - CmsError cmsError = PLC_WStrobe(HEADS_ACK, currentStrobeCell, id); + CmsError cmsError = PLC_WStrobe(HEADS_ACK, currentStrobeCell, id); if (cmsError.IsError()) return cmsError; @@ -1115,7 +1111,7 @@ namespace CMS_CORE_Library.Fanuc private CmsError ReadMacroValue(int processId, int memIndex, bool isCustom, ref double val) { - if (isCustom) + if (isCustom) { // Read custom machine variable IODBMR readVal = new IODBMR() @@ -1187,7 +1183,7 @@ namespace CMS_CORE_Library.Fanuc public override CmsError PLC_W154ManageAck(int processId) { - return PLC_ManageActiveAck(M154_STROBE.Address, processId - 1, M154_ACK.Address, processId - 1, M154_STROBE.MemType); + return PLC_ManageActiveAck(M154_STROBE.Address, processId - 1, M154_ACK.Address, processId - 1, M154_STROBE.MemType); } public override CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value) @@ -1257,11 +1253,11 @@ namespace CMS_CORE_Library.Fanuc value = val; } } - catch(Exception ex) + catch (Exception ex) { return ManageException(ex); } - + return cmsError; } @@ -1413,7 +1409,7 @@ namespace CMS_CORE_Library.Fanuc bool newVal = false; //Scrivo il dato - CmsError cmsError = MEM_RWBoolean(W, 0, EXP_CANDY_MEM.MemType, EXP_CANDY_MEM.Address,5, ref value); + CmsError cmsError = MEM_RWBoolean(W, 0, EXP_CANDY_MEM.MemType, EXP_CANDY_MEM.Address, 5, ref value); if (cmsError.IsError()) return cmsError; else @@ -1428,13 +1424,12 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; else return PLC_NOT_RUNNING_ERROR; - } } public override CmsError PLC_RExpiredCandy(ref bool value) { - CmsError cmsError = MEM_RWBoolean(R, 0, EXP_CANDY_MEM.MemType, EXP_CANDY_MEM.Address,5, ref value); + CmsError cmsError = MEM_RWBoolean(R, 0, EXP_CANDY_MEM.MemType, EXP_CANDY_MEM.Address, 5, ref value); if (cmsError.IsError()) return cmsError; return NO_ERROR; @@ -1442,7 +1437,7 @@ namespace CMS_CORE_Library.Fanuc public override CmsError PLC_WCandy(int value) { - int newVal=0; + int newVal = 0; //Scrivo il dato CmsError cmsError = MEM_RWInteger(W, 0, CANDY_MEM.MemType, CANDY_MEM.Address, ref value); @@ -1460,7 +1455,6 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; else return PLC_NOT_RUNNING_ERROR; - } } @@ -1492,7 +1486,7 @@ namespace CMS_CORE_Library.Fanuc clientId = i + 1; } - return NO_ERROR; + return NO_ERROR; } #endregion PLC High-level data @@ -1787,8 +1781,8 @@ namespace CMS_CORE_Library.Fanuc return GetNcError(nReturn); string lines = new string(text.Take(length).ToArray()); - - if(!string.IsNullOrEmpty(lines)) + + if (!string.IsNullOrEmpty(lines)) line = lines.Split('\n').FirstOrDefault(); return NO_ERROR; @@ -1830,7 +1824,7 @@ namespace CMS_CORE_Library.Fanuc ReadMacroValue(processId, 4111, false, ref macroVal); offsetId = (short)macroVal; } - + // Read operator's message #3006 & #3017 Focas1.OPMSG3 Messg = new Focas1.OPMSG3(); short count = FANUC_MAXMSGPMC; @@ -1841,41 +1835,40 @@ namespace CMS_CORE_Library.Fanuc // Check return value if (nReturn != 0) return GetNcError(nReturn); - + string msg = ""; // Check if message exist & if is an operator type (type == 4) if (count >= 5 && Messg.msg5.datano >= 0 && Messg.msg5.type == 4) msg = Messg.msg5.data; - + OffsetModel offsetData = new OffsetModel(); - if(offsetId != 0) + if (offsetId != 0) // Read offset data cmsError = TOOLS_ROffset(offsetId, ref offsetData); - if (cmsError.IsError()) - return cmsError; + if (cmsError.IsError()) + return cmsError; - byte rapid= 0, work = 0; + byte rapid = 0, work = 0; - // Choose & read work override // jogIsActive ? (processId - 1) * 1000 + 10 : + // Choose & read work override // jogIsActive ? (processId - 1) * 1000 + 10 : int mem = (processId - 1) * 1000 + 12; cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Fanuc_G, mem, 0, ref work); if (cmsError.IsError()) return cmsError; if (work != 0) - work = (byte)(((work - 256) + 1)* -1 ); + work = (byte)(((work - 256) + 1) * -1); // Read rapid cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Fanuc_G, 96, 0, ref rapid); if (cmsError.IsError()) return cmsError; - - if(rapid != 0) + + if (rapid != 0) rapid = (byte)(((rapid - 256) + 1) * -1); - ODBACT feed = new ODBACT(); - nReturn = Focas1.cnc_actf(nLibHandle[0], feed); + nReturn = Focas1.cnc_actf(nLibHandle[0], feed); // Check return value if (nReturn != 0) return GetNcError(nReturn); @@ -2173,16 +2166,16 @@ namespace CMS_CORE_Library.Fanuc if (nReturn != 0) return GetNcError(nReturn); - short[] types = new short[]{ 0, 1, 2, 3 }; + short[] types = new short[] { 0, 1, 2, 3 }; ODBAXDT axisData = new ODBAXDT(); nReturn = Focas1.cnc_rdaxisdata(nLibHandle[process - 1], 1, types, 4, ref numAxesRead, axisData); if (nReturn != 0) return GetNcError(nReturn); - + // Parse data if (numAxesRead >= 1) - axesData.Add(new AxisModel() { Id = 1, Name = sOdbExAxisName.axname1, IsSelectable = false, Type = axisData.data1.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); + axesData.Add(new AxisModel() { Id = 1, Name = sOdbExAxisName.axname1, IsSelectable = false, Type = axisData.data1.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); if (numAxesRead >= 2) axesData.Add(new AxisModel() { Id = 2, Name = sOdbExAxisName.axname2, IsSelectable = false, Type = axisData.data2.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); if (numAxesRead >= 3) @@ -2214,7 +2207,7 @@ namespace CMS_CORE_Library.Fanuc if (numAxesRead >= 16) axesData.Add(new AxisModel() { Id = 16, Name = sOdbExAxisName.axname16, IsSelectable = false, Type = axisData.data16.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); if (numAxesRead >= 17) - axesData.Add(new AxisModel() { Id = 17, Name = sOdbExAxisName.axname17, IsSelectable = false, Type = axisData.data17.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); + axesData.Add(new AxisModel() { Id = 17, Name = sOdbExAxisName.axname17, IsSelectable = false, Type = axisData.data17.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); if (numAxesRead >= 18) axesData.Add(new AxisModel() { Id = 18, Name = sOdbExAxisName.axname18, IsSelectable = false, Type = axisData.data18.unit == 2 ? AXIS_TYPE.ROTATING : AXIS_TYPE.LINEAR }); if (numAxesRead >= 19) @@ -2292,15 +2285,12 @@ namespace CMS_CORE_Library.Fanuc public override CmsError AXES_ROrigin(int numberOfAxes) { double d = 0; - - uint G54Index = 5221; uint G55Index = 5241; int G56Index = 5261; int G57Index = 5281; int G58Index = 5301; int G59Index = 5321; - List axesNames = new List(); CmsError cmsError = AXES_RAxesNames(1, ref axesNames); if (cmsError.IsError()) @@ -2310,7 +2300,7 @@ namespace CMS_CORE_Library.Fanuc axesNamesDict = axesNames.ToDictionary(x => x.Id.ToString(), x => (double)0); - Dictionary> value + Dictionary> value = new Dictionary>(); value.Add("G54", axesNamesDict); @@ -2322,8 +2312,8 @@ namespace CMS_CORE_Library.Fanuc value["G54"][id.ToString()] = d; } - - for (int i =(int) G55Index; i < G55Index + numberOfAxes; i++) + + for (int i = (int)G55Index; i < G55Index + numberOfAxes; i++) ReadMacroValue(1, i, false, ref d); for (int i = G56Index; i < G56Index + numberOfAxes; i++) @@ -3001,16 +2991,47 @@ namespace CMS_CORE_Library.Fanuc string absolutePath = FormatPathForNc(path, baseDir.drive1); - ODBPDFNFIL dataNum = new ODBPDFNFIL(); + ODBPDFNFIL dataNum = new ODBPDFNFIL + { + file_num = 0, + dir_num = 0 + }; // Get the number of the directories and of files nReturn = Focas1.cnc_rdpdf_subdirn(nLibHandle[0], absolutePath, dataNum); if (nReturn != 0) return GetNcError(nReturn); + + short maxFiles = 1; + // Check if there are directories + if(dataNum.dir_num > 0) + { + IDBPDFSDIR funcInput = new IDBPDFSDIR(); + ODBPDFSDIR dirData = new ODBPDFSDIR(); - short maxDir = 1; + for (short i = 0; i < dataNum.dir_num; i++) + { + dirData.dummy = 0; + funcInput.path = absolutePath; + funcInput.req_num = i; + + // Read directory data + nReturn = Focas1.cnc_rdpdf_subdir(nLibHandle[0], ref maxFiles, funcInput, dirData); + if (nReturn != 0) + return GetNcError(nReturn); + + // Add directory to list + files.Add(new PreviewFileModel() + { + AbsolutePath = FormatAbsolutePathForHighLevel(absolutePath + dirData.d_f, true), + IsDirectory = true, + Name = dirData.d_f, + Path = FormatPathFroHighLevel(path, dirData.d_f) + }); + } + } // Check if there are files - if (dataNum.file_num > 0 || dataNum.dir_num > 0) + if (dataNum.file_num > 0 ) { IDBPDFADIR funcInput = new IDBPDFADIR(); ODBPDFADIR fileData = new ODBPDFADIR(); @@ -3019,38 +3040,23 @@ namespace CMS_CORE_Library.Fanuc funcInput.path = absolutePath; funcInput.type = 1; funcInput.size_kind = 1; - funcInput.dummy = 0; - maxDir =(short)(dataNum.file_num + dataNum.dir_num); - for (short i = 0; i < dataNum.file_num + dataNum.dir_num; i++) + for (short i = 0; i < dataNum.file_num; i++) { - funcInput.req_num = i; // Update file index + funcInput.req_num = (short)(dataNum.dir_num + i); // Update file index // Read file data - nReturn = Focas1.cnc_rdpdf_alldir(nLibHandle[0], ref maxDir, funcInput, fileData); + nReturn = Focas1.cnc_rdpdf_alldir(nLibHandle[0], ref maxFiles, funcInput, fileData); if (nReturn != 0) return GetNcError(nReturn); - if (fileData.data_kind == 0) + + // Add file to list + files.Add(new PreviewFileModel() { - // Add directory to list - files.Add(new PreviewFileModel() - { - AbsolutePath = FormatAbsolutePathForHighLevel(absolutePath + fileData.d_f, true), - IsDirectory = true, - Name = fileData.d_f, - Path = FormatPathFroHighLevel(path, fileData.d_f) - }); - } - else - { - // Add file to list - files.Add(new PreviewFileModel() - { - AbsolutePath = FormatAbsolutePathForHighLevel(absolutePath + fileData.d_f, false), - IsDirectory = false, - Name = fileData.d_f, - Path = FormatPathFroHighLevel(path, fileData.d_f) - }); - } + AbsolutePath = FormatAbsolutePathForHighLevel(absolutePath + fileData.d_f, false), + IsDirectory = false, + Name = fileData.d_f, + Path = FormatPathFroHighLevel(path, fileData.d_f) + }); } } } @@ -3375,7 +3381,7 @@ namespace CMS_CORE_Library.Fanuc try { - string tmpM198FilePath = string.Format(NC_SUPPORT_FILE_PATH + CUSTOM_MAIN_PROGRAM, processId); + string tmpM198FilePath = string.Format(NC_SUPPORT_FILE_PATH + CUSTOM_MAIN_PROGRAM, processId); string fileName = string.Format(M198_FILE_NAME, processId); @@ -3446,7 +3452,7 @@ namespace CMS_CORE_Library.Fanuc CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - + // Set limits config.MaxTools = NC_MAX_TOOL_NUMER; config.MaxEdgesPerTools = NC_MAX_EDGES_PER_TOOL; @@ -3741,7 +3747,8 @@ namespace CMS_CORE_Library.Fanuc if (cmsError.IsError()) return cmsError; - offset = new OffsetModel() { + offset = new OffsetModel() + { Id = offsetId, UnitOfMeasure = unitOfmeasure }; @@ -3808,11 +3815,11 @@ namespace CMS_CORE_Library.Fanuc val = val * INCHES_CONST; // Convert INCHES to MM else val = val / INCHES_CONST; // Convert MM to INCHES - } + } // Change double to int int valueToWrite = (int)(val * Math.Pow(10, OFFSET_DECIMAL_DIGITS)); - + // Read data short nReturn = Focas1.cnc_wrtofs(nLibHandle[0], offsetId, i, 8, valueToWrite); if (nReturn != 0) @@ -3824,7 +3831,7 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - + private CmsError GetOffsetMisureAndDivider(out string unitOfMeasure, out double divider) { divider = 1; @@ -3849,7 +3856,6 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - public override CmsError TOOLS_WStartEditData() { // Check if the NC is Connected @@ -4109,7 +4115,7 @@ namespace CMS_CORE_Library.Fanuc public override CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks) { List readInt = new List(); - CmsError cmsError = MEM_RWIntegerList(R, 0, FAMILY_TABLE_INDEX.MemType, FAMILY_TABLE_INDEX.Address, FAMILY_TABLE_INDEX.Size/4, ref readInt); + CmsError cmsError = MEM_RWIntegerList(R, 0, FAMILY_TABLE_INDEX.MemType, FAMILY_TABLE_INDEX.Address, FAMILY_TABLE_INDEX.Size / 4, ref readInt); if (cmsError.IsError()) return cmsError; @@ -4124,7 +4130,6 @@ namespace CMS_CORE_Library.Fanuc // Test FromMemoryToModels(readInt, out tools); - readInt = new List(); cmsError = MEM_RWIntegerList(R, 0, SHANK_TABLE_INDEX.MemType, SHANK_TABLE_INDEX.Address, SHANK_TABLE_INDEX.Size / 4, ref readInt); if (cmsError.IsError()) @@ -4172,11 +4177,11 @@ namespace CMS_CORE_Library.Fanuc if (propertyIndex == 0) { // Check if id = 0, if not create new object - if(byteValues[memoryIndex] != 0) + if (byteValues[memoryIndex] != 0) { // Create TMP item with generic type declaration models.Add((T)Activator.CreateInstance(typeof(T))); - // Update object index + // Update object index objIndex = models.Count() - 1; } else @@ -4223,12 +4228,12 @@ namespace CMS_CORE_Library.Fanuc default: break; } - - if(models.Count() == 0) + + if (models.Count() == 0) { // If memory is empty, force exit memoryIndex = byteValues.Count(); - } + } // Check if there is another object else if (objIndex + 1 >= models.Count()) { @@ -4277,7 +4282,7 @@ namespace CMS_CORE_Library.Fanuc CmsError cmsError = MEM_RWInteger(W, 0, MAGAZINES_TOOLING_CMD.MemType, MAGAZINES_TOOLING_CMD.Address, ref val); if (cmsError.IsError()) return cmsError; - + return NO_ERROR; } @@ -4505,7 +4510,7 @@ namespace CMS_CORE_Library.Fanuc } return output; } - + public override CmsError TOOLS_RAdatpivePathStep(ref Byte step) { // Check ACK @@ -4934,13 +4939,11 @@ namespace CMS_CORE_Library.Fanuc private CmsError ReadSerialNumber(ref string serialNum) { - string partProgramPath = ""; string partProgramContent = ""; bool fileEnded = false; int lenght = 256; - // Start read process short nReturn = Focas1.cnc_upstart4(nLibHandle[0], 8, partProgramPath); // 2 parameter = 8, means read maintenance FILE // Return if there's an error @@ -5275,11 +5278,11 @@ namespace CMS_CORE_Library.Fanuc internal static MEMORY_CELL NC_WATCHDOG = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS, 1); // Special language parameter - internal static MEMORY_CELL SPECIAL_LANGUAGE_BIT = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R,STARTING_ADDRESS + 2, 1, 1); + internal static MEMORY_CELL SPECIAL_LANGUAGE_BIT = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2, 1, 1); internal static MEMORY_CELL ACTIVE_WATCHDOG = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 2, 1); internal static MEMORY_CELL FUNCTION_ACCESS = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 5, 8); - + internal static MEMORY_CELL ACTIVE_CLIENT = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, STARTING_ADDRESS + 4, 1); // Alarms @@ -5336,8 +5339,6 @@ namespace CMS_CORE_Library.Fanuc 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); @@ -5377,12 +5378,12 @@ namespace CMS_CORE_Library.Fanuc //old CMS-Control variables internal static MEMORY_CELL HEADS_WORKED_TIMES = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 3060, 4); + internal static MEMORY_CELL HEAD_RESET_WORKED_TIME = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 7217, 4); internal static MEMORY_CELL MACHINE_WORKED_TIME = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 7213, 4); internal static MEMORY_CELL MACHINE_RESET_WORKED_TIME = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 7212, 4); internal static MEMORY_CELL CANDY_MEM = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 7222, 1); internal static MEMORY_CELL EXP_CANDY_MEM = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 7217, 1); internal static MEMORY_CELL SELF_ADAPTIVE_PATH = new MEMORY_CELL(MEMORY_TYPE.Fanuc_D, 8816, 4); - } } \ No newline at end of file