From e14a8cc30e30e6408beed1eb17331fc089c1f021 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Thu, 27 Sep 2018 16:00:05 +0000 Subject: [PATCH] Refactor models --- CMS_CORE_Application/Form1.cs | 19 +- CMS_CORE_Library/CMS_CORE_Library.csproj | 9 +- .../Demo/DemoEdgesConfiguration.cs | 4 +- CMS_CORE_Library/Demo/ILibraryService.cs | 41 ++- CMS_CORE_Library/Demo/Models/FamilyModel.cs | 2 +- CMS_CORE_Library/Demo/Models/FileModel.cs | 2 +- CMS_CORE_Library/Demo/Models/NcAlarmModel.cs | 2 +- CMS_CORE_Library/Demo/Models/NcAxisModel.cs | 2 +- CMS_CORE_Library/Demo/Models/NcDataModel.cs | 2 +- .../Demo/Models/NcProcessModel.cs | 2 +- CMS_CORE_Library/Demo/Models/ToolDataModel.cs | 7 +- CMS_CORE_Library/Demo/Nc_Demo.cs | 52 ++- CMS_CORE_Library/Exceptions/Nc_Exception.cs | 2 +- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 7 +- CMS_CORE_Library/Models/CmsError.cs | 59 ++++ CMS_CORE_Library/Models/DataStructures.cs | 334 ++++++++++++++++++ CMS_CORE_Library/Models/NcToolModel.cs | 173 +++++++++ .../Models/PreAndPostPowerOnModels.cs | 142 ++++++++ CMS_CORE_Library/Models/SiemensToolModels.cs | 222 ++++++++++++ CMS_CORE_Library/Nc.cs | 22 +- CMS_CORE_Library/Osai/Nc_Osai.cs | 73 ++-- CMS_CORE_Library/Osai/OSAIErrMgr.cs | 2 +- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 36 +- .../Siemens/SiemensEdgesConfigurations.cs | 4 +- CMS_CORE_Library/ToolConfigurations.cs | 5 +- CMS_CORE_Library/Utils/Nc_Utils.cs | 4 +- 26 files changed, 1092 insertions(+), 137 deletions(-) create mode 100644 CMS_CORE_Library/Models/CmsError.cs create mode 100644 CMS_CORE_Library/Models/DataStructures.cs create mode 100644 CMS_CORE_Library/Models/NcToolModel.cs create mode 100644 CMS_CORE_Library/Models/PreAndPostPowerOnModels.cs create mode 100644 CMS_CORE_Library/Models/SiemensToolModels.cs diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 65d834f..3999f2c 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -1,9 +1,10 @@ -using CMS_CORE; -using CMS_CORE.Demo; -using CMS_CORE.Fanuc; -using CMS_CORE.Osai; -using CMS_CORE.Siemens; +using CMS_CORE_Library.Demo; +using CMS_CORE_Library.Fanuc; +using CMS_CORE_Library.Osai; +using CMS_CORE_Library.Siemens; using CMS_CORE_Application.ToolDatabase; +using CMS_CORE_Library; +using CMS_CORE_Library.Models; using System; using System.Collections.Generic; using System.Diagnostics; @@ -12,7 +13,7 @@ using System.Linq; using System.Threading; using System.Windows.Forms; using static CMS_CORE_Application.ToolDatabase.ToolModels; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Models.DataStructures; namespace CMS_CORE_Application { @@ -72,7 +73,7 @@ namespace CMS_CORE_Application PreAndPostPowerOnModel powerOn = new PreAndPostPowerOnModel(); List ncAlarms = new List(); List Lines = new List(); - + N = SetNcByType(); CmsError cmsError = N.NC_Connect(); @@ -145,7 +146,7 @@ namespace CMS_CORE_Application // cmsError = N.MEM_RWByteList(false, 0, Nc.MEMORY_TYPE.Fanuc_R, 0,0, 2048, ref listB); // cmsError = N.MEM_RWIntegerList(false, 0, Nc.MEMORY_TYPE.Osai_GW, 0, 512, ref list); // cmsError = N.MEM_RWWordList(false, 0, Nc.MEMORY_TYPE.Fanuc_R, 0, 512, ref listS); - cmsError = N.MEM_RWIntegerList(false, 0, Nc.MEMORY_TYPE.Siemens_DB, 258, 0, 512, ref list); + cmsError = N.MEM_RWIntegerList(false, 0, Nc.MEMORY_TYPE.Siemens_DB, 258, 0, 512, ref list); st.Stop(); Console.WriteLine(st.ElapsedMilliseconds); @@ -337,7 +338,7 @@ namespace CMS_CORE_Application { TXTip.Enabled = true; TXTport.Enabled = true; - // TXTip.Text = "192.168.139.1"; + // TXTip.Text = "192.168.139.1"; TXTip.Text = "192.168.157.2"; TXTport.Text = "8080"; } diff --git a/CMS_CORE_Library/CMS_CORE_Library.csproj b/CMS_CORE_Library/CMS_CORE_Library.csproj index 1acb674..081bdd6 100644 --- a/CMS_CORE_Library/CMS_CORE_Library.csproj +++ b/CMS_CORE_Library/CMS_CORE_Library.csproj @@ -129,7 +129,8 @@ True Reference.svcmap - + + @@ -144,6 +145,9 @@ + + + @@ -911,5 +915,8 @@ Always + + + \ No newline at end of file diff --git a/CMS_CORE_Library/Demo/DemoEdgesConfiguration.cs b/CMS_CORE_Library/Demo/DemoEdgesConfiguration.cs index 8f327a9..df1fe5a 100644 --- a/CMS_CORE_Library/Demo/DemoEdgesConfiguration.cs +++ b/CMS_CORE_Library/Demo/DemoEdgesConfiguration.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using static CMS_CORE_Library.DataStructures; +using CMS_CORE_Library.Models; +using System.Collections.Generic; namespace CMS_CORE_Library.Demo { diff --git a/CMS_CORE_Library/Demo/ILibraryService.cs b/CMS_CORE_Library/Demo/ILibraryService.cs index c1967a2..cc00d84 100644 --- a/CMS_CORE_Library/Demo/ILibraryService.cs +++ b/CMS_CORE_Library/Demo/ILibraryService.cs @@ -1,15 +1,15 @@ -using System; +using CMS_CORE_Library.Demo.Models; +using CMS_CORE_Library.Demo.Models; +using CMS_CORE_Library.Models; +using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Web; -using System.Collections.Generic; -using CMS_CORE.Demo.Models; -using CMS_CORE_Library.Demo.Models; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Models.DataStructures; namespace Nc_Demo_Application.Server.Service { [ServiceContract] - interface ILibraryService + internal interface ILibraryService { [OperationContract] @@ -17,6 +17,7 @@ namespace Nc_Demo_Application.Server.Service [WebGet(UriTemplate = "cn/name/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetName(out string name); + [WebGet(UriTemplate = "cn/language/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetLanguage(out string language); @@ -44,7 +45,9 @@ namespace Nc_Demo_Application.Server.Service [WebGet(UriTemplate = "plc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void PlcAlarms(out List alarms); - #endregion + #endregion Nc Data API + + #region Process API @@ -62,12 +65,15 @@ namespace Nc_Demo_Application.Server.Service [WebGet(UriTemplate = "processes/alarms/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetProcessesAlarms(out List alarms); - #endregion + + #endregion Process API #region Process Axes API + [WebGet(UriTemplate = "process/{id}/axes/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetAxesPosition(string id, out List axes); - #endregion + + #endregion Process Axes API #region Binary Memory @@ -106,9 +112,11 @@ namespace Nc_Demo_Application.Server.Service [WebInvoke(Method = "PUT", UriTemplate = "binary_memory/dword/{index}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] void PutDWord(string index, BinaryMemoryModel body); - #endregion + + #endregion Binary Memory #region Binary Memory List + [WebGet(UriTemplate = "binary_memory/byte/{index}/list/{number}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetByteList(string index, string number, out List byteList); @@ -138,7 +146,8 @@ namespace Nc_Demo_Application.Server.Service [WebInvoke(Method = "PUT", UriTemplate = "binary_memory/dword/{index}/list", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] void PutDWordList(string index, BinaryMemoryModel body); - #endregion + + #endregion Binary Memory List #region File Management @@ -171,7 +180,8 @@ namespace Nc_Demo_Application.Server.Service [WebGet(UriTemplate = "translation/{language}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetTranslations(string language, out Dictionary fileContent); - #endregion + + #endregion File Management #region Family @@ -187,7 +197,7 @@ namespace Nc_Demo_Application.Server.Service [WebInvoke(Method = "DELETE", UriTemplate = "tool_table/family/{name}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] void DeleteFamily(string name); - #endregion + #endregion Family #region Tools @@ -254,7 +264,6 @@ namespace Nc_Demo_Application.Server.Service [WebInvoke(Method = "PUT", UriTemplate = "tool_table/offset", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] void PutOffset(ref OffsetModel offsetData); - #endregion - + #endregion Tools } -} +} \ No newline at end of file diff --git a/CMS_CORE_Library/Demo/Models/FamilyModel.cs b/CMS_CORE_Library/Demo/Models/FamilyModel.cs index 4f28c61..5e4a6f7 100644 --- a/CMS_CORE_Library/Demo/Models/FamilyModel.cs +++ b/CMS_CORE_Library/Demo/Models/FamilyModel.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { public class DemoFamilyModel { diff --git a/CMS_CORE_Library/Demo/Models/FileModel.cs b/CMS_CORE_Library/Demo/Models/FileModel.cs index 977b971..fadf63b 100644 --- a/CMS_CORE_Library/Demo/Models/FileModel.cs +++ b/CMS_CORE_Library/Demo/Models/FileModel.cs @@ -5,7 +5,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { [DataContract] class TransferFileModel diff --git a/CMS_CORE_Library/Demo/Models/NcAlarmModel.cs b/CMS_CORE_Library/Demo/Models/NcAlarmModel.cs index c52aa6d..b21bcb7 100644 --- a/CMS_CORE_Library/Demo/Models/NcAlarmModel.cs +++ b/CMS_CORE_Library/Demo/Models/NcAlarmModel.cs @@ -5,7 +5,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { [DataContract] class NcAlarmModel diff --git a/CMS_CORE_Library/Demo/Models/NcAxisModel.cs b/CMS_CORE_Library/Demo/Models/NcAxisModel.cs index a1e188a..f36b5ff 100644 --- a/CMS_CORE_Library/Demo/Models/NcAxisModel.cs +++ b/CMS_CORE_Library/Demo/Models/NcAxisModel.cs @@ -5,7 +5,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { [DataContract] class NcAxisModel diff --git a/CMS_CORE_Library/Demo/Models/NcDataModel.cs b/CMS_CORE_Library/Demo/Models/NcDataModel.cs index 1d75dd4..9124494 100644 --- a/CMS_CORE_Library/Demo/Models/NcDataModel.cs +++ b/CMS_CORE_Library/Demo/Models/NcDataModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { class NcDataModel { diff --git a/CMS_CORE_Library/Demo/Models/NcProcessModel.cs b/CMS_CORE_Library/Demo/Models/NcProcessModel.cs index 8df4576..038b070 100644 --- a/CMS_CORE_Library/Demo/Models/NcProcessModel.cs +++ b/CMS_CORE_Library/Demo/Models/NcProcessModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { class NcProcessModel { diff --git a/CMS_CORE_Library/Demo/Models/ToolDataModel.cs b/CMS_CORE_Library/Demo/Models/ToolDataModel.cs index 092adfc..95a7d22 100644 --- a/CMS_CORE_Library/Demo/Models/ToolDataModel.cs +++ b/CMS_CORE_Library/Demo/Models/ToolDataModel.cs @@ -1,7 +1,8 @@ -using System.Collections.Generic; -using static CMS_CORE_Library.DataStructures; +using CMS_CORE_Library.Models; +using System.Collections.Generic; +using static CMS_CORE_Library.Models.DataStructures; -namespace CMS_CORE.Demo.Models +namespace CMS_CORE_Library.Demo.Models { public class DemoToolsDataModel { diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index c6f76b4..77647e5 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -1,7 +1,6 @@ -using CMS_CORE.Demo.Models; -using CMS_CORE.Utils; -using CMS_CORE_Library.Demo; -using CMS_CORE_Library.Demo.Models; +using CMS_CORE_Library.Demo.Models; +using CMS_CORE_Library.Models; +using CMS_CORE_Library.Utils; using Nc_Demo_Application.Server.Service; using System; using System.Collections; @@ -12,13 +11,13 @@ using System.Linq; using System.ServiceModel; using System.ServiceModel.Description; using System.Threading; -using static CMS_CORE.Demo.MEMORY_ADDRESS; -using static CMS_CORE.Nc; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Demo.MEMORY_ADDRESS; +using static CMS_CORE_Library.Models.DataStructures; +using static CMS_CORE_Library.Nc; using static CMS_CORE_Library.ToolConfigurations; -using static CMS_CORE.Utils.Nc_Utils; +using static CMS_CORE_Library.Utils.Nc_Utils; -namespace CMS_CORE.Demo +namespace CMS_CORE_Library.Demo { public class Nc_Demo : Nc { @@ -254,9 +253,9 @@ namespace CMS_CORE.Demo } public override CmsError NC_WLanguage(CultureInfo Language) - { + { return NO_ERROR; - } + } public override CmsError NC_RActiveAlarms(ref List alarms) { @@ -1103,7 +1102,7 @@ namespace CMS_CORE.Demo try { serverService.GetAxesPosition(process.ToString(), out List demoAxes); - + // Parse response get distance to go foreach (NcAxisModel demoAxis in demoAxes) { @@ -1690,7 +1689,7 @@ namespace CMS_CORE.Demo } public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel data) - { + { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); if (cmsError.IsError()) @@ -1806,7 +1805,7 @@ namespace CMS_CORE.Demo int processId = 0; // Foreach value - foreach(var val in ints) + foreach (var val in ints) { byte[] bytes = BitConverter.GetBytes(val); @@ -1852,7 +1851,7 @@ namespace CMS_CORE.Demo StartStopQueueEnabled = bytes[2] == 1, ProcessId = processId }; - + return NO_ERROR; } @@ -1886,10 +1885,19 @@ namespace CMS_CORE.Demo CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - + return NO_ERROR; } + //public override CmsError FILES_WUploadJobMain(int processId) + //{ + // CmsError cmsError = CheckConnection(); + // if (cmsError.IsError()) + // return cmsError; + + // return NO_ERROR; + //} + #endregion File Management /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1942,6 +1950,14 @@ namespace CMS_CORE.Demo config.MagPositionOptionActive = demoConf.MagPositionOption; config.MaxOffsets = 5; + // Get magazine status + Dictionary magazineStatus = new Dictionary(); + CmsError cmsError = TOOLS_RMagazineStatus(ref magazineStatus); + if (cmsError.IsError()) + return cmsError; + + MagazineConfig.ForEach(x => x.LoadingIsActive = magazineStatus[x.Id]); + config.Magazines = MagazineConfig; } catch (Exception ex) @@ -2729,6 +2745,7 @@ namespace CMS_CORE.Demo /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Nc Tool Manager + public override CmsError TOOLS_RMagazineConfig(ref List config) { config = new List() @@ -2744,7 +2761,7 @@ namespace CMS_CORE.Demo Id = 2, MaxPositions = 10, Type = NC_MAGAZINE_TYPE.DISK - }, + }, new NcMagazineConfigModel() { Id = 3, @@ -2795,7 +2812,6 @@ namespace CMS_CORE.Demo return ManageException(ex); } - return NO_ERROR; } diff --git a/CMS_CORE_Library/Exceptions/Nc_Exception.cs b/CMS_CORE_Library/Exceptions/Nc_Exception.cs index c285313..084dc4c 100644 --- a/CMS_CORE_Library/Exceptions/Nc_Exception.cs +++ b/CMS_CORE_Library/Exceptions/Nc_Exception.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CMS_CORE.Exceptions +namespace CMS_CORE_Library.Exceptions { public class Nc_Exception : Exception { diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 163519b..34c0b06 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -1,4 +1,5 @@ -using CMS_CORE.Utils; +using CMS_CORE_Library.Models; +using CMS_CORE_Library.Utils; using System; using System.Collections.Generic; using System.Globalization; @@ -6,11 +7,11 @@ using System.IO; using System.Linq; using System.Threading; using System.Windows.Forms; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Models.DataStructures; #pragma warning disable 1591 -namespace CMS_CORE.Fanuc +namespace CMS_CORE_Library.Fanuc { public class Nc_Fanuc : Nc { diff --git a/CMS_CORE_Library/Models/CmsError.cs b/CMS_CORE_Library/Models/CmsError.cs new file mode 100644 index 0000000..6df4c9c --- /dev/null +++ b/CMS_CORE_Library/Models/CmsError.cs @@ -0,0 +1,59 @@ +namespace CMS_CORE_Library.Models +{ + public class CmsError + { + public CMS_ERROR_CODES errorCode; + public string localizationKey; + + public CmsError(CMS_ERROR_CODES errorCode, string message) + { + this.errorCode = errorCode; + this.localizationKey = message; + } + + public bool IsError() + { + if (errorCode == CMS_ERROR_CODES.OK) + return false; + else + return true; + } + + public static CmsError InternalError(string message) + { + return new CmsError(CMS_ERROR_CODES.INTERNAL_ERROR, message); + } + + public static CmsError NcError(string message) + { + return new CmsError(CMS_ERROR_CODES.NC_PROD_ERROR, message); + } + } + + public enum CMS_ERROR_CODES : uint + { + OK = 0, + NC_PROD_ERROR = 1, + NOT_CONNECTED = 2, + PROC_NOT_FOUND = 3, + FUNCTION_NOT_ALLOWED = 4, + BIT_NOT_IN_RANGE = 5, + BYTE_NOT_IN_RANGE = 6, + INTERNAL_ERROR = 7, + INCORRECT_PARAMETERS = 8, + NC_LANGUAGE_ERROR = 9, + SIEMENS_ENVIRONMENT_NOT_FOUND = 10, + SIEMENS_HMI_NOT_RUNNING = 11, + MAX_TOOL_REACHED = 12, + MAX_EDGES_PER_TOOL_REACHED = 13, + MAX_FAMILY_REACHED = 14, + MAX_MULTITOOL_REACHED = 15, + MAX_TOOLS_PER_MULTITOOL_REACHED = 16, + MAX_MULTITOOL_LOCATION_REACHED = 17, + MAG_POS_OCCUPIED = 18, + MAGAZINE_OCCUPIED = 19, + TOOL_IS_MOUNTED = 20, + TOOL_AND_POSITION_NOT_MATCHING = 21, + FILE_NOT_FOUND = 22 + } +} \ No newline at end of file diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs new file mode 100644 index 0000000..55cb261 --- /dev/null +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -0,0 +1,334 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using static CMS_CORE_Library.Nc; + +namespace CMS_CORE_Library.Models +{ + public class DataStructures + { + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region Data structure models + + // R-W MEMORY Cell + internal struct MEMORY_CELL + { + public readonly MEMORY_TYPE MemType; + public readonly int Address; + public readonly int SubAddress; //Only for Siemens + public readonly int Size; + + public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int SubAddr, int Sz) + { + MemType = MType; + Address = Addr; + SubAddress = SubAddr; + Size = Sz; + } + + public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int Sz) + { + MemType = MType; + Address = Addr; + SubAddress = 0; + Size = Sz; + } + } + + public class AlarmModel + { + public uint Id; + public string Message; + public bool IsWarning; + public int Process; + public DateTime DateTime; + } + + public class PlcAlarmModel + { + public uint Id; + public bool IsWarning; + public bool RestorationIsActive; + public List Process; + } + + public class ProcessDataModel + { + public uint Id; + public string Type; + public bool IsInAlarm; + public string PartProgramName; + public string Status; + public bool Visible; + public ushort Reps; + public bool IsSelected; + } + + public class FunctionalityModel + { + public uint Id; + public bool IsActive; + } + + public struct StrobeModel + { + public uint Id; + public bool IsActive; + } + + public class AxisResetDataModel + { + public bool IsActive; + public int Percentage; + + public AxisResetDataModel() + { + IsActive = false; + Percentage = 0; + } + + public override bool Equals(object obj) + { + var item = obj as AxisResetDataModel; + + if (IsActive == item.IsActive && Percentage == item.Percentage) + return true; + else + return false; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public struct CounterModel + { + public uint Id; + public uint Value; + } + + public class SoftKeysModel + { + public uint Id; + public bool Active; + public bool Value; + } + + public class HeadDataModel + { + public uint Id; + public byte Process; + public byte Override; + public ushort Load_Abrasive; + public int ActualSpeed_Pressure; + public short MountedTool_Vacum; + + public bool IsActive; + public bool IsSelected; + public bool OverrideEditable; + public bool AbrasiveIsActive; + } + + public class AxisModel + { + public int Id; + public string Name; + } + + public class PreviewFileModel + { + public string Name; + public string Path; + public string AbsolutePath; + public bool IsDirectory; + } + + public class InfoFile + { + public string Name; + public DateTime CreationDate; + public DateTime LastModDate; + public List Content; + public string PreviewBase64; + public string AbsolutePath; + } + + public class ActiveProgramDataModel + { + public string Path { get; set; } + public List IsoLines { get; set; } + public DateTime TimeLeft { get; set; } + } + + public class QueueStatusModel + { + public int ProcessId; + public bool LoadNextProgram; + public QUEUE_STATUS Status; + public bool StartStopQueueEnabled; + } + + public enum QUEUE_STATUS + { + NOT_ACTIVE = 0, + RUNNING = 1, + WAITING_OPERATOR = 2, + CLOSING = 3 + } + + #endregion Data structure models + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + #region Constants + + public static readonly string[] VALID_PP_FORMATS = { ".txt", ".cnc", ".ini" }; + public static readonly string[] VALID_IMAGE_FORMATS = { ".jpg", ".jpeg", ".png" }; + + public static readonly string IMAGES_PATH = @"C:\CMS\STEP\pp_img\"; + + public const int USER_SOFTKEYS_NUMBER = 128; + public const int NC_SOFTKEYS_NUMBER = 32; + public const int PROCESS_NUMBER = 6; + public const int ALARMS_NUMBER = 1024; + public const int HEADS_NUMBER = 20; + + public enum HEAD_OVERRIDE_SIGN + { + PLUS = 0, + MINUS = 1 + } + + /** Process-Status */ + + public enum PROC_STATUS : ushort + { + /** Idle-Status */ + IDLE = 1, + /** Run-Status */ + RUN = 2, + /** Hold-Status */ + HOLD = 3, + /** Error-Status */ + ERROR = 4, + /** Reset-Status */ + RESET = 5, + /** Emergency-Status */ + EMERG = 6 + }; + + /** CMS-Process-Mode */ + + public enum PROC_MODE : ushort + { + /** Automatic-Mode */ + AUTO = 1, + /** Edit-Mode */ + EDIT = 2, + /** Mdi-Mode */ + MDI = 3, + /** Remote-Mode */ + REMOTE = 4, + /** Teach-Mode */ + TEACH = 5, + /** Ref-Mode */ + REF = 6, + /** Jog-Mode */ + JOG = 7, + /** Joginc-Mode */ + JOGINC = 8, + /** Ret_on_Profile-Mode */ + RETPROF = 9, + /** Handle-Mode */ + HANDLE = 10, + /** Restart-Mode */ + RESTART = 11, + /** Error-Mode */ + ERROR = 12 + }; + + public enum MAGAZINE_ACTIONS + { + NONE = 0, + LOADING = 1, + UNLOADING = 2, + TRANSFER = 4, + GENERIC = 5 + } + + public enum SIEMENS_MAGAZINE_TYPE + { + CHAIN = 1, + REVOLVER = 3, + BOX_MAGAZINE = 5, + MAGAZINE_TOOL_BUFFER = 7, + MAGAZINE_LOADING_STATION = 9 + } + + public enum NC_MAGAZINE_TYPE + { + BOX_MAGAZINE = 0, + DISK = 1, + CHAIN = 2, + } + + public enum POSITION_TYPE + { + MAGAZINE_LOCATION = 1, + SPINDLE = 2, + GRIPPER = 3, + LOADER = 4, + TRANSFER_LOCATION = 5, + LOADING_STATION = 6, + LOADING_POINT = 7 + } + + public enum ROTATION + { + NONE = 0, + CLOCKWHISE = 1, + COUNTERCLOCKWHISE = 2 + } + + public enum SIEMENS_LIFE_TYPE + { + NONE = 0, + TIME = 1, + COUNT = 2, + WEAR = 4 + } + + public static IFormatProvider numberFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); + + #region Cms Errors Codes + + public static CmsError NO_ERROR = new CmsError(CMS_ERROR_CODES.OK, ""); + public static CmsError NOT_CONNECTED_ERROR = new CmsError(CMS_ERROR_CODES.NOT_CONNECTED, "error_not_connected"); + public static CmsError PROC_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_process_not_found"); + public static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_function_not_allowed"); + public static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BIT_NOT_IN_RANGE, "error_bit_not_in_range"); + public static CmsError BYTE_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BYTE_NOT_IN_RANGE, "error_byte_not_in_range"); + public static CmsError INCORRECT_PARAMETERS_ERROR = new CmsError(CMS_ERROR_CODES.INCORRECT_PARAMETERS, "error_incorrect_parameters"); + public static CmsError INCORRECT_LANGUAGE_ERROR = new CmsError(CMS_ERROR_CODES.NC_LANGUAGE_ERROR, "error_invalid_language"); + public static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND, "error_siemens_enviroment_not_found_error"); + public static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "error_siemens_hmi_not_running"); + public static CmsError MAX_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOL_REACHED, "error_max_tool_reached"); + public static CmsError MAX_EDGES_PER_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_EDGES_PER_TOOL_REACHED, "error_max_edges_per_tool_reached"); + public static CmsError MAX_FAMILY_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_FAMILY_REACHED, "error_max_family_reached"); + public static CmsError MAX_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_MULTITOOL_REACHED, "error_max_multitools_reached"); + public static CmsError MAX_TOOLS_PER_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOLS_PER_MULTITOOL_REACHED, "error_max_tools_per_multitool_reached"); + public static CmsError MAX_MULTITOOL_LOCATION_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_MULTITOOL_LOCATION_REACHED, "error_max_multitools_location_reached"); + public static CmsError MAGAZINE_POSITION_OCCUPIED_ERROR = new CmsError(CMS_ERROR_CODES.MAG_POS_OCCUPIED, "error_magazine_position_occupied"); + public static CmsError MAGAZINE_BUSY_ERROR = new CmsError(CMS_ERROR_CODES.MAGAZINE_OCCUPIED, "error_magazine_occupied"); + public static CmsError TOOL_IS_MOUNTED_ERROR = new CmsError(CMS_ERROR_CODES.TOOL_IS_MOUNTED, "error_tool_mounted"); + public static CmsError TOOL_AND_POSITION_NOT_MATCHING_ERROR = new CmsError(CMS_ERROR_CODES.TOOL_IS_MOUNTED, "error_tool_and_position_not_matching"); + public static CmsError FILE_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FILE_NOT_FOUND, "error_file_not_found"); + + #endregion Cms Errors Codes + + #endregion Constants + } +} \ No newline at end of file diff --git a/CMS_CORE_Library/Models/NcToolModel.cs b/CMS_CORE_Library/Models/NcToolModel.cs new file mode 100644 index 0000000..9d8dd4f --- /dev/null +++ b/CMS_CORE_Library/Models/NcToolModel.cs @@ -0,0 +1,173 @@ +namespace CMS_CORE_Library.Models +{ + public class ToolManagerOptionsModel + { + public bool FamilyOpt { get; set; } + public bool ShankOpt { get; set; } + public bool MagPosTypeOpt { get; set; } + public bool OffsetOpt { get; set; } + public bool ReviveOpt { get; set; } + public bool GammaOpt { get; set; } + public bool LifeOpt { get; set; } + public bool TcpOpt { get; set; } + public bool CoolingOpt { get; set; } + public bool MultidimensionalShankOpt { get; set; } + public bool SelfAdaptivePathOpt { get; set; } + public bool DynamicCompensationOpt { get; set; } + public bool BallufOpt { get; set; } + } + + public class OffsetModel + { + public short Id { get; set; } + public double Length { get; set; } + public double Radius { get; set; } + public double WearLength { get; set; } + public double WearRadius { get; set; } + } + + public class NcShankModel + { + public int ShankId { get; set; } + + public int Balluf { get; set; } + + public byte MagazineId { get; set; } + + public byte PositionId { get; set; } + + public byte MagazinePositionType { get; set; } + } + + public class NcToolModel + { + public int ToolId { get; set; } + + public int FamilyId { get; set; } + public int ShankId { get; set; } + + public byte Status { get; set; } + + public int OffsetLength { get; set; } + + public int ResidualLife { get; set; } + + public int OffsetId1 { get; set; } + + public int OffsetId2 { get; set; } + + public int OffsetId3 { get; set; } + + public int ResidualRevive { get; set; } + } + + public class NcFamilyModel + { + public int FamilyId { get; set; } + + public byte ToolType { get; set; } + + public byte TcpTable { get; set; } + + public byte Gamma { get; set; } + + public byte RotationType { get; set; } + + public byte CoolingByte { get; set; } + + public ushort MaxSpeed { get; set; } + + public byte MaxLoad { get; set; } + + public byte MinLoadPctAutoload { get; set; } + + public byte MaxLoadPctAutoload { get; set; } + + public ushort DynamicCompensation { get; set; } + + public byte MinLoadDynamicCompensation { get; set; } + + public byte MaxLoadDynamicCompensation { get; set; } + + public byte LifeType { get; set; } + + public int NominalLife { get; set; } + + public ushort ReviveDelta { get; set; } + + public byte RightSize { get; set; } + + public byte LeftSize { get; set; } + } + + internal class NcFamilyFileModel + { + public int Id { get; set; } + public byte ToolType { get; set; } + public byte TcpTable { get; set; } + public byte Gamma { get; set; } + public byte RotationType { get; set; } + public byte CoolingByte { get; set; } + public ushort MaxSpeed { get; set; } + public byte MaxLoad { get; set; } + public byte MinLoadPctAutoload { get; set; } + public byte MaxLoadPctAutoload { get; set; } + public ushort DynamicCompensation { get; set; } + public byte MinLoadDynamicCompensation { get; set; } + public byte MaxLoadDynamicCompensation { get; set; } + public byte LifeType { get; set; } + public int NominalLife { get; set; } + public ushort ReviveDelta { get; set; } + + public static explicit operator NcFamilyFileModel(NcFamilyModel obj) + { + return new NcFamilyFileModel() + { + Id = obj.FamilyId, + ToolType = obj.ToolType, + TcpTable = obj.TcpTable, + Gamma = obj.Gamma, + RotationType = obj.RotationType, + CoolingByte = obj.CoolingByte, + MaxSpeed = obj.MaxSpeed, + MaxLoad = obj.MaxLoad, + MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation, + MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation, + MaxLoadPctAutoload = obj.MaxLoadPctAutoload, + MinLoadPctAutoload = obj.MinLoadPctAutoload, + DynamicCompensation = obj.DynamicCompensation, + LifeType = obj.LifeType, + NominalLife = obj.NominalLife, + ReviveDelta = obj.ReviveDelta + }; + } + } + + internal class NcFamilySizeFileModel + { + public int Id { get; set; } + public byte RightSize { get; set; } + public byte LeftSize { get; set; } + + public static explicit operator NcFamilySizeFileModel(NcFamilyModel obj) + { + return new NcFamilySizeFileModel() + { + Id = obj.FamilyId, + RightSize = obj.RightSize, + LeftSize = obj.LeftSize + }; + } + } + + public class NcMagazinePositionModel + { + public byte MagazineId { get; set; } + + public byte PositionId { get; set; } + + public byte Type { get; set; } + + public byte Disabled { get; set; } + } +} \ No newline at end of file diff --git a/CMS_CORE_Library/Models/PreAndPostPowerOnModels.cs b/CMS_CORE_Library/Models/PreAndPostPowerOnModels.cs new file mode 100644 index 0000000..6f6b9fd --- /dev/null +++ b/CMS_CORE_Library/Models/PreAndPostPowerOnModels.cs @@ -0,0 +1,142 @@ +namespace CMS_CORE_Library.Models +{ + #region Pre and Post Power on Models + + public class PreAndPostPowerOnModel + { + public PrePowerOnModel PrePowerOn { get; set; } + public PostPowerOnModel PostPowerOn { get; set; } + + public PreAndPostPowerOnModel() + { + PrePowerOn = new PrePowerOnModel(); + PostPowerOn = new PostPowerOnModel(); + } + + public override bool Equals(object obj) + { + var item = obj as PreAndPostPowerOnModel; + + if (item == null) + return false; + + if (!PrePowerOn.Equals(item.PrePowerOn) || !PostPowerOn.Equals(item.PostPowerOn)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public class PrePowerOnModel + { + public PowerOnDataModel PowerOn { get; set; } + public PowerOnDataModel AirPressure { get; set; } + public PowerOnDataModel ProtectionStatus { get; set; } + public PowerOnDataModel EmergencyButtons { get; set; } + public PowerOnDataModel SettingMode { get; set; } + public PowerOnDataModel StartingKey { get; set; } + + public PrePowerOnModel() + { + PowerOn = new PowerOnDataModel(); + AirPressure = new PowerOnDataModel(); + ProtectionStatus = new PowerOnDataModel(); + EmergencyButtons = new PowerOnDataModel(); + SettingMode = new PowerOnDataModel(); + StartingKey = new PowerOnDataModel(); + } + + public override bool Equals(object obj) + { + var item = obj as PrePowerOnModel; + + if (item == null) + return false; + + if (!PowerOn.Equals(item.PowerOn) || + !AirPressure.Equals(item.AirPressure) || + !ProtectionStatus.Equals(item.ProtectionStatus) || + !EmergencyButtons.Equals(item.EmergencyButtons) || + !SettingMode.Equals(item.SettingMode) || + !StartingKey.Equals(item.StartingKey)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public class PostPowerOnModel + { + public PowerOnDataModel AxisReset { get; set; } + public PowerOnDataModel WaterjetPump { get; set; } + + public PostPowerOnModel() + { + AxisReset = new PowerOnDataModel(); + WaterjetPump = new PowerOnDataModel(); + } + + public override bool Equals(object obj) + { + var item = obj as PostPowerOnModel; + + if (item == null) + return false; + + if (!AxisReset.Equals(item.AxisReset) || + !WaterjetPump.Equals(item.WaterjetPump)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public class PowerOnDataModel + { + public uint Id { get; set; } + public bool Active { get; set; } + public bool Clickable { get; set; } + + public PowerOnDataModel() + { + Id = 0; + Active = false; + Clickable = false; + } + + public override bool Equals(object obj) + { + var item = obj as PowerOnDataModel; + + if (item == null) + return false; + + if (Id != item.Id || Active != item.Active || Clickable != item.Clickable) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + #endregion Pre and Post Power on Models +} \ No newline at end of file diff --git a/CMS_CORE_Library/Models/SiemensToolModels.cs b/CMS_CORE_Library/Models/SiemensToolModels.cs new file mode 100644 index 0000000..41ae8ab --- /dev/null +++ b/CMS_CORE_Library/Models/SiemensToolModels.cs @@ -0,0 +1,222 @@ +using System.Collections.Generic; +using static CMS_CORE_Library.Models.DataStructures; + +namespace CMS_CORE_Library.Models +{ + public class SiemensToolModel + { + public int Id; + public string FamilyName; + public int ChildId; + public SIEMENS_LIFE_TYPE LifeType; + public int MagazinePositionType; + public int ToolType; + public int LeftSize; + public int RightSize; + public ROTATION Rotation; + public bool Cooling1; + public bool Cooling2; + public bool IsEnabled; + public bool IsActive; + public bool InFixedPlace; + public bool IsInhibited; + public bool IsMeasured; + public bool InChangeTool; + public bool IsInUse; + public bool PreAlarm; + public double MaxSpeed; + public double MaxAcceleration; + public int MagazineId; + public int PositionId; + public int MultitoolId; + public List EdgesData; + + public SiemensToolModel() + { + EdgesData = new List(); + } + } + + public class EdgeModel + { + public int Id; + public double ResidualLife; + public double NominalLife; + public double PreAlmLife; + public Dictionary EdgeAdditionalParams; + + public EdgeModel() + { + EdgeAdditionalParams = new Dictionary(); + } + } + + public class ShankModel + { + public int Id; + public string Name; + public bool IsEnabled; + public bool IsInhibited; + public bool InChangeTool; + public bool InFixedPlace; + public bool InUse; + public int LeftSize; + public int RightSize; + public int MagazinePositionType; + public int MaxChilds; + public int MagazineId; + public int PositionId; + public List ChildsTools; + + public ShankModel() + { + ChildsTools = new List(); + } + } + + public class ShankChildModel + { + public int Id; + public int MultitoolId; + public string FamilyName; + public int ToolType; + } + + public class FamilyModel + { + public string Name; + public List ChildTools; + + public FamilyModel() + { + ChildTools = new List(); + } + } + + public class FamilyChildModel + { + public int Id; + public int ChildId; + public int ToolType; + } + + public class PositionModel + { + public int PositionId; + public int MagazineId; + public POSITION_TYPE PhysicalType; + public int Type; + public bool Disabled; + } + + public class EdgeConfigModel + { + public string Name; + public string Path; + public int Number; + } + + public class MountedToolModel + { + public int PositionId; + public int MagazineId; + public int ToolId; + public SiemensToolModel ChildTool; + public ShankModel ChildShank; + } + + public class NewToolInMagazineModel + { + public int PositionId; + public int ToolId; + } + + public class MagazineActionModel + { + public MAGAZINE_ACTIONS Action; + public int OriginMagazine; + public int OriginPosition; + public int DestinationMagazine; + public int DestinationPosition; + public MagazineActionToolModel Tool; + } + + public class MagazineActionToolModel + { + public int Id; + public int ToolType; + public string Name; + public bool IsMultitool; + } + + ///////////////// Tools Configuration + + public class FieldsConfiguration + { + public string Name; + public string Type; + public string Category; + public bool ReadOnly; + public Dictionary SelectValues; + public uint MinValue; + public uint MaxValue; + } + + public class FamiliesConfiguration + { + public List FamilyConfiguration; + public List FamilyReadOnlyConfiguration; + public List ToolsConfiguration; + } + + public class ShanksConfiguration + { + public List ShankConfiguration; + public List ToolsConfiguration; + } + + public class EdgesConfiguration + { + public List EdgeConfiguration; + public Dictionary> EdgesAdditionalParamsConfiguration; + } + + public class NcMagazineConfigModel + { + public byte Id; + public NC_MAGAZINE_TYPE Type; + public int MaxPositions; + } + + public class SiemensMagazineConfigModel + { + public byte Id; + public SIEMENS_MAGAZINE_TYPE Type; + public int MaxPositions; + public string Name; + public bool LoadingIsActive; + public int LoadPosition; + } + + public class ToolTableConfiguration + { + public int MaxTools; + public int MaxEdgesPerTools; + public int MaxToolsPerFamily; + public int MaxMultitools; + public int MaxToolsPerMultitools; + public int MaxOffsets; + + public bool MultitoolOptionActive; + public bool FamilyOptionActive; + public bool MagPositionOptionActive; + public bool OffsetOptionActive; + + public List Magazines; + public List ToolsConfiguration; + public FamiliesConfiguration FamiliesConfiguration; + public ShanksConfiguration ShanksConfiguration; + public List MagazinePosConfiguration; + public EdgesConfiguration EdgesConfiguration; + } +} \ No newline at end of file diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index aadbba8..7ebd29c 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1,12 +1,13 @@ -using System; +using CMS_CORE_Library.Models; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Models.DataStructures; -namespace CMS_CORE +namespace CMS_CORE_Library { public abstract partial class Nc { @@ -320,6 +321,7 @@ namespace CMS_CORE * */ public abstract CmsError NC_RLanguage(ref CultureInfo Language); + /** * * Write the configured language of the NC @@ -362,8 +364,6 @@ namespace CMS_CORE public abstract CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary messages); - - /** * * Set the screen page visible of the NC @@ -377,7 +377,6 @@ namespace CMS_CORE public abstract CmsError NC_SetScreenVisible(SCREEN_PAGE screen); - #endregion NC High-level data (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1373,9 +1372,8 @@ namespace CMS_CORE public abstract CmsError FILES_WStartQueue(); public abstract CmsError FILES_WStopQueue(); - - public abstract CmsError FILES_WLoadNextPartProgram(string localPath, string ncFileName); + public abstract CmsError FILES_WLoadNextPartProgram(string localPath, string ncFileName); #endregion File Management (To override) @@ -1692,6 +1690,7 @@ namespace CMS_CORE /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Nc Tool Manager + public abstract CmsError TOOLS_WOptions(ToolManagerOptionsModel options); public abstract CmsError TOOLS_ROffset(short offsetId, ref OffsetModel offset); @@ -1861,12 +1860,13 @@ namespace CMS_CORE internal const ushort OSAI_DISTTOGO = 5; internal const ushort OSAI_MACHINEPOS = 6; - /** Nc Screen */ + public enum SCREEN_PAGE { //Siemens Siemens_Machine = 100, + Siemens_Parameter = 101, Siemens_Program = 102, Siemens_ProgramManager = 103, @@ -1875,6 +1875,7 @@ namespace CMS_CORE //Fanuc Fanuc_Pos = 201, + Fanuc_Prog = 202, Fanuc_Offset = 203, Fanuc_Message = 204, @@ -1882,8 +1883,8 @@ namespace CMS_CORE Fanuc_Custom1 = 206, Fanuc_Custom2 = 207, Fanuc_System = 208 - } + #endregion CONSTANTS (Struct and Enum are Static for definition) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1893,6 +1894,7 @@ namespace CMS_CORE // TODO REMOVE //Lingua CN internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_TYPE.Null, 3281, 0, 1); + internal MEMORY_CELL PARAM_LING_FANUC_W = new MEMORY_CELL(MEMORY_TYPE.Fanuc_G, 581, 0, 1); //Matricola Macchina diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 78dbebe..9263130 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -1,6 +1,7 @@ -using CMS_CORE.Exceptions; -using CMS_CORE.Utils; +using CMS_CORE_Library.Exceptions; +using CMS_CORE_Library.Models; using CMS_CORE_Library.OPENControl; +using CMS_CORE_Library.Utils; using CndexLinkDotNet; using System; using System.Collections; @@ -9,17 +10,16 @@ using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; -using System.Security.Cryptography; using System.ServiceModel; using System.Text; using System.Threading; -using static CMS_CORE.Nc; -using static CMS_CORE.Osai.MEMORY_ADDRESS; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Models.DataStructures; +using static CMS_CORE_Library.Nc; +using static CMS_CORE_Library.Osai.MEMORY_ADDRESS; using static CMS_CORE_Library.ToolConfigurations; -using static CMS_CORE.Utils.Nc_Utils; +using static CMS_CORE_Library.Utils.Nc_Utils; -namespace CMS_CORE.Osai +namespace CMS_CORE_Library.Osai { public class Nc_Osai : Nc { @@ -39,8 +39,10 @@ namespace CMS_CORE.Osai private static Dictionary PlcMessages; private const string TOOL_MANAGER_DIRECTORY_PATH = @"STEP\"; + // private const string TOOL_MANAGER_DIRECTORY_PATH = @"test\OEM\CMS\SYS\STEP\"; private const string NC_PROGRAM_PATH = @"CAMBIO\"; + private const string NC_PROGRAM_UPLOAD_PATH = @"CAMBIO\UPLOADED_PP\"; private static List EXT_PP = new List() { "", "TXT", "CNC", "INI" }; private static List EXT_IMG = new List() { "PNG", "JPG", "JPEG" }; @@ -116,7 +118,6 @@ namespace CMS_CORE.Osai Connected = true; else Connected = false; - } catch (Exception ex) { @@ -130,9 +131,9 @@ namespace CMS_CORE.Osai public override CmsError NC_Disconnect() { //Set Connected to FALSE and close the session - if(Connected) + if (Connected) OpenNC.Close(); - Connected = false; + Connected = false; return NO_ERROR; } @@ -1223,7 +1224,6 @@ namespace CMS_CORE.Osai //Fill all the List foreach (GETINTDATA ax in Pos) { - if (ax.AxisName > 0) { AxName = ((char)ax.AxisName).ToString(); @@ -1282,7 +1282,6 @@ namespace CMS_CORE.Osai //Fill all the List foreach (GETINTDATA ax in Pos) { - if (ax.AxisName > 0) { AxName = ((char)ax.AxisName).ToString(); @@ -1341,7 +1340,6 @@ namespace CMS_CORE.Osai //Fill all the List foreach (GETINTDATA ax in Pos) { - if (ax.AxisName > 0) { AxName = ((char)ax.AxisName).ToString(); @@ -1400,7 +1398,6 @@ namespace CMS_CORE.Osai //Fill all the List foreach (GETINTDATA ax in Pos) { - if (ax.AxisName > 0) { AxName = ((char)ax.AxisName).ToString(); @@ -1459,7 +1456,6 @@ namespace CMS_CORE.Osai //Fill all the List foreach (GETINTDATA ax in Pos) { - if (ax.AxisName > 0) { AxName = ((char)ax.AxisName).ToString(); @@ -1948,7 +1944,6 @@ namespace CMS_CORE.Osai public override CmsError FILES_RGetFileList(string path, ref List files) { - ushort nReturn; String temppath; uint findHandler; @@ -1986,15 +1981,12 @@ namespace CMS_CORE.Osai //If there's an error if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); - } while (found); - nReturn = OpenNC.LogFSFindClose(findHandler, out errorClass, out errorNum); //If there's an error if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); - } return NO_ERROR; } @@ -2057,11 +2049,11 @@ namespace CMS_CORE.Osai CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - + //Fix the Path temppath = filePath; temppath = temppath.TrimStart('\\'); - + ushort nReturn; try { @@ -2098,7 +2090,6 @@ namespace CMS_CORE.Osai //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); - } catch (Exception ex) { @@ -2106,7 +2097,6 @@ namespace CMS_CORE.Osai } return NO_ERROR; - } public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel data) @@ -2371,12 +2361,18 @@ namespace CMS_CORE.Osai if (cmsError.IsError()) return cmsError; + // Get magazine status + Dictionary magazineStatus = new Dictionary(); + cmsError = TOOLS_RMagazineStatus(ref magazineStatus); + if (cmsError.IsError()) + return cmsError; + config.Magazines = conf.Select(x => new SiemensMagazineConfigModel() { Id = x.Id, - Type = (SIEMENS_MAGAZINE_TYPE) x.Type, + Type = (SIEMENS_MAGAZINE_TYPE)x.Type, Name = x.Id.ToString(), - LoadingIsActive = true, + LoadingIsActive = magazineStatus[x.Id], MaxPositions = x.MaxPositions }).ToList(); @@ -2544,7 +2540,7 @@ namespace CMS_CORE.Osai public override CmsError TOOLS_WOptions(ToolManagerOptionsModel options) { // Convert class into a single ushort - bool[] boolValues = new bool[13] + bool[] boolValues = new bool[13] { options.FamilyOpt, options.ShankOpt, @@ -2646,7 +2642,7 @@ namespace CMS_CORE.Osai bool[] bits = IntToBool(status); - for(int i = 0; i < bits.Length; i++) + for (int i = 0; i < bits.Length; i++) { magazineStatus.Add(i + 1, bits[i]); } @@ -2736,7 +2732,7 @@ namespace CMS_CORE.Osai return cmsError; } - if(File.Exists(string.Format(backupFilePath, MAG_POSITION_FILE_NAME))) + if (File.Exists(string.Format(backupFilePath, MAG_POSITION_FILE_NAME))) { fileContent = File.ReadAllText(string.Format(backupFilePath, MAG_POSITION_FILE_NAME)); cmsError = FILES_WProgram(string.Format(filePath, MAG_POSITION_FILE_NAME), fileContent); @@ -2991,7 +2987,7 @@ namespace CMS_CORE.Osai // Insert into the new lives list updatedLives.Add(toolId, life); - // Setup ack/strobe indexes + // Setup ack/strobe indexes // if i > (32) + 15 then index = next word strobeByteIndex = i > 47 ? TOOL_LIFE_UPDATED_CMD.Address + 1 : TOOL_LIFE_UPDATED_CMD.Address; ackByteIndex = i > 47 ? TOOL_LIFE_UPDATED_ACK.Address + 1 : TOOL_LIFE_UPDATED_CMD.Address; @@ -3043,13 +3039,12 @@ namespace CMS_CORE.Osai .Where(x => x != String.Empty) .Select(x => x.Split(';')) // Split line .Select(x => new NcFamilySizeFileModel // Setup new model for each line - { + { Id = ushort.Parse(x[0]), RightSize = byte.Parse(x[1]), LeftSize = byte.Parse(x[2]), }).ToList(); - List tools = File.ReadAllLines(string.Format(backupFilePath, TOOLS_FILE_NAME)) .Where(x => x != String.Empty) .Select(x => x.Split(';')) @@ -3514,7 +3509,7 @@ namespace CMS_CORE.Osai //private CmsError FILE_PPImage(string PP_Name, ref string base64Image) //{ // base64Image = ""; - + // //Check if exists the file // DirectoryInfo DirToSearch = new DirectoryInfo(IMAGES_PATH); // FileInfo[] filesInDir = DirToSearch.GetFiles(PP_Name + ".*"); @@ -3523,22 +3518,21 @@ namespace CMS_CORE.Osai // { // if(EXT_IMG.Contains(foundFile.Extension.TrimStart('.').ToUpper())) // { - // base64Image = "data:image/" + foundFile.Extension + ";base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes(foundFile.FullName)); // break; // } // } - + // return NO_ERROR; //} - + //Get Program Path without extension private string GetFilepathWithoutExt(string path) { String name = path.Split('\\').LastOrDefault(); String ext = name.Split('.').LastOrDefault(); - if (String.IsNullOrWhiteSpace(ext) || name==ext) + if (String.IsNullOrWhiteSpace(ext) || name == ext) return path; else return path.Remove(path.LastIndexOf("." + ext)); @@ -3738,7 +3732,6 @@ namespace CMS_CORE.Osai internal static class MEMORY_ADDRESS { - internal const int STARTING_ADDRESS = 12000; internal static MEMORY_CELL MATR_MACCH_OSAI = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 3403, 0, 1); internal static MEMORY_CELL FUNCTION_ACCESS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12003, 8); @@ -3784,9 +3777,9 @@ namespace CMS_CORE.Osai // Tool manager areas internal static MEMORY_CELL TOOL_MANAGER_COMMAND = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13000, 2); - + internal static MEMORY_CELL TOOL_MANAGER_STATUS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13001, 2); - + internal static MEMORY_CELL TOOL_MANAGER_OPTIONS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13002, 2); internal static MEMORY_CELL MAGAZINE_TYPES = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13062, 4); diff --git a/CMS_CORE_Library/Osai/OSAIErrMgr.cs b/CMS_CORE_Library/Osai/OSAIErrMgr.cs index 50fcbc1..f877c06 100644 --- a/CMS_CORE_Library/Osai/OSAIErrMgr.cs +++ b/CMS_CORE_Library/Osai/OSAIErrMgr.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using CMS_CORE_Library.OPENControl; -namespace CMS_CORE.Osai +namespace CMS_CORE_Library.Osai { partial class NativeConstants { diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 439925a..9726828 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -1,4 +1,5 @@ using CMS_CORE_Library; +using CMS_CORE_Library.Models; using CMS_CORE_Library.Siemens; using Siemens.Sinumerik.Operate.Services; using System; @@ -11,14 +12,14 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Xml.Linq; -using static CMS_CORE.Nc; -using static CMS_CORE.Siemens.MEMORY_ADDRESS; -using static CMS_CORE.Utils.Nc_Utils; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Siemens.MEMORY_ADDRESS; +using static CMS_CORE_Library.Utils.Nc_Utils; +using static CMS_CORE_Library.Models.DataStructures; +using static CMS_CORE_Library.Nc; using static CMS_CORE_Library.ToolConfigurations; using static Siemens.Sinumerik.Operate.Services.ToolMngmntSvc; -namespace CMS_CORE.Siemens +namespace CMS_CORE_Library.Siemens { public class Nc_Siemens : Nc { @@ -407,7 +408,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - //Set the NC Language public override CmsError NC_WLanguage(CultureInfo Language) { @@ -530,8 +530,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - #endregion High level methods /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1961,10 +1959,10 @@ namespace CMS_CORE.Siemens return FILE_NOT_FOUND_ERROR; // Check if file is stored on NC - if(filePath.StartsWith(BASE_FILE_PATH)) + if (filePath.StartsWith(BASE_FILE_PATH)) fileSvc.Select(selectedNode, processId); else - fileSvc.SelectExtern(selectedNode, processId); + fileSvc.SelectExtern(selectedNode, processId); return FILES_RActiveProgramData(processId, ref data); } @@ -2150,7 +2148,6 @@ namespace CMS_CORE.Siemens public override CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId) { return NO_ERROR; } - public override CmsError FILES_WStartQueue() { return NO_ERROR; @@ -2166,7 +2163,6 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - private IEnumerable GetLinesFromString(string text) { string line; @@ -2721,7 +2717,7 @@ namespace CMS_CORE.Siemens List ids = Enumerable.Range(1, MAX_EDGES_PER_TOOL).ToList(); - foreach(var edgeVal in tool.EdgesData) + foreach (var edgeVal in tool.EdgesData) { ids.Remove(edgeVal.Id); } @@ -3558,7 +3554,7 @@ namespace CMS_CORE.Siemens { return language.ThreeLetterWindowsLanguageName; } - + private int SwapIntEndianFormat(int value) { var b1 = (value >> 0) & 0xff; @@ -3624,8 +3620,6 @@ namespace CMS_CORE.Siemens // } //} - - private string ConvertStepToSiemensScreen(SCREEN_PAGE page) { switch (page) @@ -4157,11 +4151,11 @@ namespace CMS_CORE.Siemens // If Exist if (paramConfig != null) { - // Add additional param - tool - .EdgesData[edgeIndex] - .EdgeAdditionalParams - .Add(paramConfig.Name, Convert.ToDouble(actualString.Split('=').LastOrDefault(), numberFormat)); + // Add additional param + tool + .EdgesData[edgeIndex] + .EdgeAdditionalParams + .Add(paramConfig.Name, Convert.ToDouble(actualString.Split('=').LastOrDefault(), numberFormat)); } } } diff --git a/CMS_CORE_Library/Siemens/SiemensEdgesConfigurations.cs b/CMS_CORE_Library/Siemens/SiemensEdgesConfigurations.cs index 74ce564..2634a3b 100644 --- a/CMS_CORE_Library/Siemens/SiemensEdgesConfigurations.cs +++ b/CMS_CORE_Library/Siemens/SiemensEdgesConfigurations.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using static CMS_CORE_Library.DataStructures; +using CMS_CORE_Library.Models; +using System.Collections.Generic; namespace CMS_CORE_Library.Siemens { diff --git a/CMS_CORE_Library/ToolConfigurations.cs b/CMS_CORE_Library/ToolConfigurations.cs index c84356f..48a7d8c 100644 --- a/CMS_CORE_Library/ToolConfigurations.cs +++ b/CMS_CORE_Library/ToolConfigurations.cs @@ -1,5 +1,6 @@ -using System.Collections.Generic; -using static CMS_CORE_Library.DataStructures; +using CMS_CORE_Library.Models; +using System.Collections.Generic; +using static CMS_CORE_Library.Models.DataStructures; namespace CMS_CORE_Library { diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index cba6838..ca370c0 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -3,9 +3,9 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; -using static CMS_CORE_Library.DataStructures; +using static CMS_CORE_Library.Models.DataStructures; -namespace CMS_CORE.Utils +namespace CMS_CORE_Library.Utils { public static class Nc_Utils {