using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace AuroraLaser.IPG.YLS { #region TCP/IP Communication Format [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCT_COMMAND_REQUEST_HEADER { public UInt16 nCommandCode; public UInt16 nReserve; public UInt32 nDataSize; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCT_COMMAND_REQUEST { public UInt16 nCommandCode; // Code of the command , 2byte public UInt16 nReserve; // Should be 0 , 2byte public UInt32 nDataSize; // Size of data for the command (N) , 4byte } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCT_COMMAND_RESPONSE_HEADER { public UInt16 nAnswerCode; public UInt16 nExecutionCode; public UInt32 nDataSize; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCT_COMMAND_RESPONSE { public UInt16 nAnswerCode; // Code of the answer (↔ command code) , 2byte public UInt16 nExecutionCode; // Execution operation code , 2byte public UInt32 nDataSize; // Size of data for the command (N) , 4byte public byte[] nData; // Data, Max size public UInt16 nCheckSum; // Checksum CRC16 (bytes 0..N+8-1) , 2byte } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCT_COMMAND_RESPONSE_NODATA { public UInt16 nAnswerCode; // Code of the answer (↔ command code) , 2byte public UInt16 nExecutionCode; // Execution operation code , 2byte public UInt32 nDataSize; // Size of data for the command (N) , 4byte public UInt16 nCheckSum; // Checksum CRC16 (bytes 0..N+8-1) , 2byte } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCT_LASER_DATA { // 순서 및 data type 중요. data size 에 맞게 address offset 이 들어감. 임의 수정 금지. public UInt16 Version; // Version of the structure public UInt16 SetILD; // Set current , unit (0.01%) public UInt32 SetPower; // Set power , unit (W) public UInt32 OutputPower; // Current output power , unit (W) public UInt16 TemperatureMean; // Modules average temperature , unit (0.1°C) public UInt16 TemperatureMin; // Modules minimal temperature , unit (0.1°C) public UInt16 TemperatureMax; // Modules maximal temperature , unit (0.1°C) public byte nModuleMinTemp; // Number of module with minimal temperature public byte nModuleMaxTemp; // Number of module with maximal temperature public UInt16 WaterFlow; // Water flow through the laser, unit (0.1 l/min) public UInt32 Status1; // Status 1. See Definition of Bit Mask public UInt32 Status2; // Status 2. See Definition of Bit Mask public UInt32 Alarm1; // Alarm 1. See Definition of Bit Mask public UInt32 Alarm2; // Alarm 2. See Definition of Bit Mask public UInt32 Warning1; // Warning 1. See Definition of Bit Mask public UInt32 Warning2; // Warning 2. See Definition of Bit Mask #region Module 16byte datas // Module 정보. 16byte 씩 되어 있는데, 정의내용이 없다. 4byte 4개씩 정의해주고 안쓰는 방향으로 해야할듯 public UInt32 ModuleUnconnected1; // Modules with communication error public UInt32 ModuleUnconnected2; // public UInt32 ModuleUnconnected3; // public UInt32 ModuleUnconnected4; // public UInt32 ModuleDisabled1; // Disabled modules public UInt32 ModuleDisabled2; // public UInt32 ModuleDisabled3; // public UInt32 ModuleDisabled4; // public UInt32 ModuleReserved1; // Reserved modules public UInt32 ModuleReserved2; // public UInt32 ModuleReserved3; // public UInt32 ModuleReserved4; // public UInt32 ModuleFatalDisabled1; // Modules with critical failure public UInt32 ModuleFatalDisabled2; // public UInt32 ModuleFatalDisabled3; // public UInt32 ModuleFatalDisabled4; // public UInt32 ModuleErrors1; // Modules which have some error public UInt32 ModuleErrors2; // public UInt32 ModuleErrors3; // public UInt32 ModuleErrors4; // public UInt32 ModuleFibersInterlocks1; // Modules interlock state public UInt32 ModuleFibersInterlocks2; // public UInt32 ModuleFibersInterlocks3; // public UInt32 ModuleFibersInterlocks4; // #endregion public UInt32 HardwiringInputs; // Hardwiring interface inputs states public UInt32 HardwiringOutputs; // Hardwiring interface output states public UInt16 RiseTime; // Emission on (rise) time , unit (0.1ms) public UInt16 FallTime; // Emission off (fall) time , unit (0.1ms) public UInt16 ProgramNumber; // Number of current laser program public UInt16 ProgramEndCode; // Program exit code (Table 16.3) public UInt16 ProgramErrorLine; // Number of line in laser program where the error has appeared public UInt16 UControl; // Control voltage value , unit (1mV) public UInt32 ePCStatus; // Table 5.12 public UInt16 FFWaterFlow; // Water flow through the Feeding Fiber , unit (0.1 l/min) public UInt16 SideSpotLaserPower1; // Current output power for side spot 1 , unit (1W) public UInt16 SideSpotLaserPower2; // Current output power for side spot 2 , unit (1W) public UInt16 SetSideSpotLaserPower1; // Set output power for side spot 1. For AMB lasers is set output power of central core. , unit (1W) public UInt16 SetSideSpotLaserPower2; // Set output power for side spot 2. For AMB lasers is set output power of ring core. , unit (1W) public UInt32 OutputPeakPower; // Current output power (Peak) , unit (1W) public UInt32 CustomerOutputPower; // Customer output power , unit (1W) public UInt16 OutputPowerTune; // Output power tune value , unit (0.1%) public UInt16 SetCentralCoreCurrent; // Set output pump current of central core. Valid only for AMB2 lasers , unit (0.1%) public UInt16 SetRingCoreCurrent; // Set output pump current of ring core. Valid only for AMB2 lasers. , unit (0.1%) public UInt16 ParamsChangedCounter; // Counter showing changes in laser parameters or configuration. public UInt16 ExtAnalogControlVoltage1; // External analog control voltage 1 , unit (1mV) public UInt16 ExtAnalogControlVoltage2; // External analog control voltage 2 , unit (1mV) } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCTUREA { public UInt16 Parameter1; public UInt16 Parameter2; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct STRUCTURE_ACCESS_LEVEL_DATA { public ushort Version; // 2 bytes public ushort AccessLevel; // 2 bytes [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] public byte[] Password; // 10 bytes public void SetPassword(string password) { Password = new byte[10]; if (!string.IsNullOrEmpty(password)) { var bytes = Encoding.ASCII.GetBytes(password); int len = Math.Min(bytes.Length, 10); Array.Copy(bytes, Password, len); } } //public string GetPassword() //{ // int len = Array.IndexOf(Password, (byte)0); // if (len < 0) len = Password.Length; // return Encoding.ASCII.GetString(Password, 0, len); //} } #endregion }