From 8ec2d47de18081f8a99933a3a5438fdcefd43841 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Mon, 22 Oct 2018 15:18:30 +0000 Subject: [PATCH] Added order to fields Added Fanuc offset functions --- CMS_CORE_Application/Form1.cs | 21 +- CMS_CORE_Library/DataStructures.cs | 935 ------------------------- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 135 +++- CMS_CORE_Library/Models/NcToolModel.cs | 66 +- CMS_CORE_Library/Osai/Nc_Osai.cs | 16 +- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 18 +- 6 files changed, 204 insertions(+), 987 deletions(-) delete mode 100644 CMS_CORE_Library/DataStructures.cs diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 32f26e5..6f7c70e 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -138,26 +138,11 @@ namespace CMS_CORE_Application ////////////// SPEED TEST Stopwatch st = new Stopwatch(); sw.Restart(); - // cmsError = N.PLC_RPowerOnData(ref powerOn); - // cmsError = N.PLC_RActiveMessages(ref plcMsg); - //List ints = new List(); - //cmsError = N.MEM_RWIntegerList(false, 0, Nc.MEMORY_TYPE.Fanuc_R, 12000, 2, ref ints); - //N.NC_GetTranslatedPlcMessages("it", ref messages); - //cmsError = N.AXES_RAxesNames(1, ref axes); - //for(byte i = 0; i < 20; i++) - //{ - // byte val = 0; - // int index = 12000 + i; - // // cmsError = N.MEM_RWInteger(true, 0, Nc.MEMORY_TYPE.Fanuc_R, index, ref val); - // cmsError = N.MEM_RWByte(true, 0, Nc.MEMORY_TYPE.Fanuc_R, index, 0, ref val); - //} - List ints = new List(); - cmsError = N.MEM_RWIntegerList(false, 0, Nc.MEMORY_TYPE.Fanuc_R, 12000, 150, ref ints); - ushort[] bytes = new ushort[300]; - Array.Copy(ints.ToArray(), 0, bytes, 0, 300); - // bytes = ints.SelectMany(BitConverter.GetBytes).ToArray(); + OffsetModel offset = new OffsetModel(); + N.TOOLS_ROffset(1, ref offset); + N.TOOLS_WOffset(2, offset); Console.WriteLine("ICON" + sw.ElapsedMilliseconds); sw.Stop(); diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs deleted file mode 100644 index 12ada0f..0000000 --- a/CMS_CORE_Library/DataStructures.cs +++ /dev/null @@ -1,935 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using static CMS_CORE.Nc; - -namespace CMS_CORE_Library -{ - public static class DataStructures - { - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - #region Data structure 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 - - // 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 Cms Errors Codes - - 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 - } - - 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 - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - #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 static IFormatProvider numberFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); - - #endregion Constants - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - #region Siemens Tool Manager Models - - public enum SIEMENS_LIFE_TYPE - { - NONE = 0, - TIME = 1, - COUNT = 2, - WEAR = 4 - } - - 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; - } - - #endregion Siemens Tool Manager Models - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - #region Nc Tool Manager 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; } - } - - #endregion Nc Tool Manager Models - } -} \ No newline at end of file diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index c22825b..0d1f826 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -32,6 +32,9 @@ namespace CMS_CORE_Library.Fanuc private byte FanucLanguage; private DateTime Last_Static_Read; + private static int OFFSET_DECIMAL_DIGITS = 0; + private static int MAX_OFFSET_NUM = 0; + // Paths private const string PLC_MESSAGE_PATH = @"C:\CMS\FANUC\"; @@ -67,11 +70,9 @@ namespace CMS_CORE_Library.Fanuc //Connect Method public override CmsError NC_Connect() - { - short nReturn; - + { // Try to connect to The NC - nReturn = Focas1.cnc_allclibhndl3(Ip, Port, TimeOut, out ushort TempLibHandle); + short nReturn = Focas1.cnc_allclibhndl3(Ip, Port, TimeOut, out ushort TempLibHandle); if (nReturn != 0) return GetNcError(nReturn); else @@ -98,6 +99,28 @@ namespace CMS_CORE_Library.Fanuc if (nReturn != 0) return GetNcError(nReturn); } + // Read offset decimal digits + if(OFFSET_DECIMAL_DIGITS == 0) + { + short[] input = new short[20]; + short[] output = new short[20]; + nReturn = Focas1.cnc_getfigure(nLibHandle[0], 1, out short val, input, output); + if (nReturn != 0) + return GetNcError(nReturn); + + OFFSET_DECIMAL_DIGITS = input[0]; + } + + // Read max number of offsets + if (MAX_OFFSET_NUM == 0) + { + ODBTLINF2 info = new ODBTLINF2(); + nReturn = Focas1.cnc_rdtofsinfo2(nLibHandle[0], info); + if (nReturn != 0) + return GetNcError(nReturn); + + MAX_OFFSET_NUM = info.use_no; + } // Setup the "Connected" value to TRUE Connected = true; @@ -2290,16 +2313,99 @@ namespace CMS_CORE_Library.Fanuc public override CmsError TOOLS_WOptions(ToolManagerOptionsModel options) { - return NO_ERROR; + // Convert class into a single ushort + bool[] boolValues = new bool[13] + { + options.FamilyOpt, + options.ShankOpt, + options.MagPosTypeOpt, + options.OffsetOpt, + options.ReviveOpt, + options.GammaOpt, + options.LifeOpt, + options.TcpOpt, + options.CoolingOpt, + options.MultidimensionalShankOpt, + options.SelfAdaptivePathOpt, + options.DynamicCompensationOpt, + options.BallufOpt + }; + + ushort intValue = 0; + // Convert array into a ushort + for (int i = 0; i < boolValues.Length; i++) + { + if (boolValues[i]) + intValue += (ushort)(1 << i); + } + + // Write & return + return MEM_RWWord(W, 0, TOOL_MANAGER_OPTIONS.MemType, TOOL_MANAGER_OPTIONS.Address, ref intValue); } public override CmsError TOOLS_ROffset(short offsetId, ref OffsetModel offset) { + if (offsetId > MAX_OFFSET_NUM) + return INCORRECT_PARAMETERS_ERROR; + + offset = new OffsetModel() { Id = offsetId }; + ODBTOFS offsetData = new ODBTOFS(); + for(short i = 0; i < 4; i++) + { + // Read data + short nReturn = Focas1.cnc_rdtofs(nLibHandle[0], offsetId, i, 8, offsetData); + if (nReturn != 0) + return GetNcError(nReturn); + + // Change decimal digits + double valueRead = offsetData.data; + valueRead /= Math.Pow(10, OFFSET_DECIMAL_DIGITS); + + // Switch param and set return object + switch (i) + { + case 0: offset.WearRadius = valueRead; break; + case 1: offset.Radius = valueRead; break; + case 2: offset.WearLength = valueRead; break; + case 3: offset.Length = valueRead; break; + } + } + return NO_ERROR; } public override CmsError TOOLS_WOffset(short offsetId, OffsetModel offset) { + List offsets = new List() + { + new NcToolModel(){FamilyId = 88, OffsetId1 = 0, OffsetId2 = 0, OffsetId3 = 0, OffsetLength = 0, ResidualLife = 5, ResidualRevive = 2, ShankId = 66, Status = 1, ToolId = 33} + }; + TOOLS_WObjectInMemory(offsets, 12000, 1); + + if (offsetId > MAX_OFFSET_NUM) + return INCORRECT_PARAMETERS_ERROR; + + double val = 0; + for (short i = 0; i < 4; i++) + { + // Switch param and set return object + switch (i) + { + case 0: val = offset.WearRadius; break; + case 1: val = offset.Radius; break; + case 2: val = offset.WearLength; break; + case 3: val = offset.Length; break; + } + + // 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) + return GetNcError(nReturn); + } + return NO_ERROR; } @@ -2387,18 +2493,16 @@ namespace CMS_CORE_Library.Fanuc PropertyInfo[] properties = typeof(T).GetProperties(); CmsError cmsError = NO_ERROR; - int nextParamIndex = tableIndex; + int nextFieldIndex = tableIndex; foreach (T item in items) - { + { foreach (PropertyInfo property in properties) { - int size = Marshal.SizeOf(property.GetType()); - // Calculate the starting index of the next field - nextParamIndex = size * TOOL_OFFSET + nextParamIndex; + int size = Marshal.SizeOf(property.PropertyType); // Add obj index to the parameter memory - int currentFieldIndex = nextParamIndex + objIndex * size; + int currentFieldIndex = nextFieldIndex + objIndex * size; // Write switch (size) @@ -2413,20 +2517,23 @@ namespace CMS_CORE_Library.Fanuc case 2: { ushort u = Convert.ToUInt16(property.GetValue(item)); - cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, 0, ref u); + cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref u); if (cmsError.IsError()) return cmsError; } break; case 4: { - uint u = Convert.ToUInt32(property.GetValue(item)); - cmsError = MEM_RWDWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, 0, ref u); + uint w = Convert.ToUInt32(property.GetValue(item)); + cmsError = MEM_RWDWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref w); if (cmsError.IsError()) return cmsError; } break; default: break; } + + // Calculate the starting index of the next field + nextFieldIndex += size * TOOL_OFFSET; } } diff --git a/CMS_CORE_Library/Models/NcToolModel.cs b/CMS_CORE_Library/Models/NcToolModel.cs index 9d8dd4f..b82ca0e 100644 --- a/CMS_CORE_Library/Models/NcToolModel.cs +++ b/CMS_CORE_Library/Models/NcToolModel.cs @@ -1,4 +1,6 @@ -namespace CMS_CORE_Library.Models +using System; + +namespace CMS_CORE_Library.Models { public class ToolManagerOptionsModel { @@ -41,24 +43,45 @@ public class NcToolModel { - public int ToolId { get; set; } + [FanucOrder(1)] + [OsaiOrder(1)] + public short ToolId { get; set; } - public int FamilyId { get; set; } - public int ShankId { get; set; } + [FanucOrder(2)] + [OsaiOrder(2)] + public short FamilyId { get; set; } + [FanucOrder(3)] + [OsaiOrder(3)] + public short ShankId { get; set; } + + [FanucOrder(4)] + [OsaiOrder(4)] public byte Status { get; set; } - public int OffsetLength { get; set; } + [FanucOrder(5)] + [OsaiOrder(5)] + public short OffsetLength { get; set; } + [FanucOrder(6)] + [OsaiOrder(6)] public int ResidualLife { get; set; } + + [FanucOrder(7)] + [OsaiOrder(7)] + public uint ResidualRevive { get; set; } - public int OffsetId1 { get; set; } + [FanucOrder(8)] + [OsaiOrder(8)] + public ushort OffsetId1 { get; set; } - public int OffsetId2 { get; set; } + [FanucOrder(9)] + [OsaiOrder(9)] + public ushort OffsetId2 { get; set; } - public int OffsetId3 { get; set; } - - public int ResidualRevive { get; set; } + [FanucOrder(10)] + [OsaiOrder(10)] + public ushort OffsetId3 { get; set; } } public class NcFamilyModel @@ -170,4 +193,27 @@ public byte Disabled { get; set; } } + + // If u need to order properties, use the code below + // properties = properties.OrderBy(x => ((FanucOrderAttribute)x.GetCustomAttribute(typeof(FanucOrderAttribute))).Val).ToArray(); + + public class OsaiOrderAttribute : Attribute + { + public int Val { get; set; } + + public OsaiOrderAttribute(int val) + { + Val = val; + } + } + + public class FanucOrderAttribute : Attribute + { + public int Val { get; set; } + + public FanucOrderAttribute(int val) + { + Val = val; + } + } } \ No newline at end of file diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 7f6d16b..a7de54a 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -3029,16 +3029,16 @@ namespace CMS_CORE_Library.Osai .Select(x => x.Split(';')) .Select(x => new NcToolModel { - ToolId = int.Parse(x[0]), - FamilyId = int.Parse(x[1]), - ShankId = int.Parse(x[2]), + ToolId = short.Parse(x[0]), + FamilyId = short.Parse(x[1]), + ShankId = short.Parse(x[2]), Status = byte.Parse(x[3]), - OffsetLength = ushort.Parse(x[4]), + OffsetLength = short.Parse(x[4]), ResidualLife = byte.Parse(x[5]), - OffsetId1 = ushort.Parse(x[6]), - OffsetId2 = byte.Parse(x[7]), - OffsetId3 = byte.Parse(x[8]), - ResidualRevive = byte.Parse(x[9]) + ResidualRevive = uint.Parse(x[6]), + OffsetId1 = ushort.Parse(x[7]), + OffsetId2 = ushort.Parse(x[8]), + OffsetId3 = ushort.Parse(x[9]), }).ToList(); List shanks = File.ReadAllLines(string.Format(backupFilePath, SHANKS_FILE_NAME)) diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index c710939..667e252 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -522,11 +522,25 @@ namespace CMS_CORE_Library.Siemens ALARMS_STATUS.MemType, ALARMS_STATUS.Address, ALARMS_STATUS.SubAddress, - (ALARMS_STATUS.Size + ALARMS_DATA.Size) / 4, // byte / 4 + (ALARMS_STATUS.Size / 4) + (ALARMS_DATA.Size / 2), // statys_bytes / 4 + data_word / 2 ref readValues); if (cmsError.IsError()) - return cmsError; + alarms.Clear(); + + //List readValues = new List(); + + //// Read on data from memory + //CmsError cmsError = MEM_RWIntegerList(R, 0, + // ALARMS_STATUS.MemType, + // ALARMS_STATUS.Address, + // ALARMS_STATUS.SubAddress, + // (ALARMS_STATUS.Size + ALARMS_DATA.Size) / 4, // byte / 4 + // ref readValues); + + //if (cmsError.IsError()) + // return cmsError; + // Convert integer array into bit array bool[] statusBits = IntToBool(readValues.ToArray());