using Aurora.Api; using Aurora.Api.Devices; using Hermes; using System; using System.Text; namespace AuroraLaser.Ekspla { public class NL202 : SerialConn { public enum SendParam { NL202_Set_Run = 0, // - NL202_Set_Stop, // - NL202_Set_ResetFAULT, // - NL202_Set_OutLev, // OFF, Adjustment, Maximum NL202_Set_PumpLevel, // 0..100 NL202_Set_Wavelength, // 1064nm, 532nm NL202_Set_BurstMode, // OFF, ON NL202_Set_Burstlenth, // 1..65535 NL202_Set_TriggerBurst, // Burst Mode Shot NL202_Set_AdjDelay, // 100..1000 NL202_Set_TTec1, // 15.00 .. 35.00 NL202_Set_SyncMode, // Internal, External NL202_Set_SH1Temp, // 30.00 .. 70.0 NL202_Set_AttnTrans, // 0..100 NL202_Set_RepetitionRate, // Frq 1..1000 NL202_Set_MaxCnt }; public enum ReadParam { NL202_Get_State = 0, // Idle, Running, Error, NotInitialized NL202_Get_FaultCode, // 1..65535 NL202_Get_FaultMsg, // %s NL202_Get_PumpLevel, // 0..100 NL202_Get_Wavelenth, // 1064nm, 532nm NL202_Get_EnergyLevel, // OFF, Adjustment, Maximum NL202_Get_TTec1, // 15.00 .. 35.00 NL202_Get_BurstMode, // OFF, ON NL202_Get_QSWAdjDelay, // 100..1000 NL202_Get_BurstLenth, // 1..65535 NL202_Get_SyncMode, // Internal, External NL202_Get_SH1Temp, // 30.00 .. 70.0 NL202_Get_AttnTrans, // 0..100 NL202_Get_RepetitionRate, // 확인필요 메뉴얼에는 없는내용임. NL202_Get_ShotCnt, // 확인필요 메뉴얼에는 없는내용임. NL202_Get_MaxCnt }; //protected List ComPortString = new List { // "\\\\.\\COM0", // "\\\\.\\COM1", // "\\\\.\\COM2", // "\\\\.\\COM3", // "\\\\.\\COM4", // "\\\\.\\COM5", // "\\\\.\\COM6", // "\\\\.\\COM7", // "\\\\.\\COM8", // "\\\\.\\COM9", // "\\\\.\\COM10", // "\\\\.\\COM11", // "\\\\.\\COM12", // "\\\\.\\COM13", // "\\\\.\\COM14", // "\\\\.\\COM15", // "\\\\.\\COM16" //}; protected const int MAX_PORT_NUMBER = 16; protected LaserConfig _config; protected string LOG_TAG = "NL202"; protected readonly Logger LOG = new Logger("NL202"); public NL202(string deviceId, LaserConfig config, bool isSimul = false) : base(deviceId, isSimul) { _config = config; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // NL202 Serial Interfaces public int RS232_OpenComport() { var connConfig = _config.ConnConfig as SerialConnConfig; if (!IsConnected()) { if (connConfig.PortNum >= 0 && connConfig.PortNum <= MAX_PORT_NUMBER) { return Open(connConfig); } } return 0; } public int RS232_ReadBytes(ref byte[] readBuff, int size) { return Read(readBuff); } public const Int16 BUF_MAX = 32; protected const Int16 FAIL = -1; public int RS232_SendBuf(byte[] sendBuff, int length) { if (Write(sendBuff, length)) { return E1.OK; } else { return FAIL; } } public int RS232_SendByte(byte sendByte) { byte[] sendBuff = new byte[1]; sendBuff[0] = sendByte; return RS232_SendBuf(sendBuff, 1); } public int RS232_SendString(SendParam index, double dValue = 0) // RS232_cputs -> string으로 변경 { string sendStr = GetSendCommand(index, dValue); if (sendStr.Length > 0) { byte[] sendBuff = Encoding.UTF8.GetBytes(sendStr); return RS232_SendBuf(sendBuff, sendBuff.Length); } return FAIL; } public int RS232_SendString(ReadParam index) // RS232_cputs -> string으로 변경 { string sendStr = GetReadCommand(index); if (sendStr.Length > 0) { byte[] sendBuff = Encoding.UTF8.GetBytes(sendStr); return RS232_SendBuf(sendBuff, sendBuff.Length); } return FAIL; } public void RS232_CloseComport() { Close(); } // 미사용 함수 (WINAPI 사용) : 구현 X //public int RS232_IsDCDEnabled() //public int RS232_IsCTSEnabled() //public int RS232_IsDSREnabled() //public void RS232_enableDTR() //public void RS232_disableDTR() //public void RS232_enableRTS() //public void RS232_disableRTS() //public int RS232_GetPortDeviceName(ref string portNumber) //clear buffers : Aurora의 Serialconn은 Write 전에 내부적으로 ClearSerialPortInOutBuffers 수행하므로 불필요 //public void RS232_flushRX() //{ // ClearSerialPortInBuffers(); //} //public void RS232_flushTX() //{ // ClearSerialPortOutBuffers(); //} //public void RS232_flushRXTX() //{ // ClearSerialPortInOutBuffers(); //} public string GetSendCommand(SendParam index, double dValue) { switch (index) { case NL202.SendParam.NL202_Set_Run: return "/?EXE/Run\r\n"; case NL202.SendParam.NL202_Set_Stop: return "/?EXE/Stop\r\n"; case NL202.SendParam.NL202_Set_ResetFAULT: return "/?EXE/ResetFAULT\r\n"; case NL202.SendParam.NL202_Set_OutLev: if ((int)dValue == 0) return "/?EXE/SetOutLev/OFF\r\n"; else if ((int)dValue == 1) return "/?EXE/SetOutLev/Adjustment\r\n"; else if ((int)dValue == 2) return "/?EXE/SetOutLev/Maximum\r\n"; break; case NL202.SendParam.NL202_Set_PumpLevel: return "/?EXE/SetPumpLevel/" + ((int)dValue).ToString() + "\r\n"; case NL202.SendParam.NL202_Set_Wavelength: if ((int)dValue == 0) return "/?EXE/SetWavelength/1064nm\r\n"; if ((int)dValue == 1) return "/?EXE/SetWavelength/532nm\r\n"; break; case NL202.SendParam.NL202_Set_BurstMode: if ((int)dValue == 0) return "/?EXE/SetBurstMode/OFF\r\n"; else if ((int)dValue == 1) return "/?EXE/SetBurstMode/ON\r\n"; break; case NL202.SendParam.NL202_Set_Burstlenth: return "/?EXE/SetBurstLength/" + ((int)dValue + 1).ToString() + "\r\n"; case NL202.SendParam.NL202_Set_TriggerBurst: return "/?EXE/TriggerBurst/Trigger\r\n"; case NL202.SendParam.NL202_Set_AdjDelay: return "/?EXE/SetAdjDelay/" + ((int)dValue).ToString() + "\r\n"; case NL202.SendParam.NL202_Set_TTec1: return "/?EXE/SetTTec1/" + ((int)dValue).ToString() + "\r\n"; case NL202.SendParam.NL202_Set_SyncMode: //Internal, External if ((int)dValue == 0) return "/?EXE/SetSyncMode/Internal\r\n"; else if ((int)dValue == 1) return "/?EXE/SetSyncMode/External\r\n"; break; case NL202.SendParam.NL202_Set_SH1Temp: return "/?EXE/SetSH1Temp/" + ((int)dValue).ToString() + "\r\n"; case NL202.SendParam.NL202_Set_AttnTrans: return "/?EXE/SetAttnTrans/" + dValue.ToString("F2") + "\r\n"; case NL202.SendParam.NL202_Set_RepetitionRate: return "/?EXE/SetRepetitionRate/" + ((int)dValue).ToString() + "\r\n"; default: break; } return ""; } public string GetReadCommand(ReadParam index) { switch (index) { case NL202.ReadParam.NL202_Get_State: return "/?RDVAR/State\r\n"; //prepare command case NL202.ReadParam.NL202_Get_FaultCode: return "/?RDVAR/FaultCode\r\n"; //prepare command case NL202.ReadParam.NL202_Get_FaultMsg: return "/?RDVAR/FaultMsg\r\n"; //prepare command case NL202.ReadParam.NL202_Get_PumpLevel: return "/?RDVAR/PumpLevel\r\n"; //prepare command case NL202.ReadParam.NL202_Get_Wavelenth: return "/?RDVAR/Wavelength\r\n"; //prepare command case NL202.ReadParam.NL202_Get_EnergyLevel: return "/?RDVAR/EnergyLevel\r\n"; //prepare command case NL202.ReadParam.NL202_Get_TTec1: return "/?RDVAR/Temperature_TTec1\r\n"; //prepare command case NL202.ReadParam.NL202_Get_BurstMode: return "/?RDVAR/BurstMode\r\n"; //prepare command case NL202.ReadParam.NL202_Get_QSWAdjDelay: return "/?RDVAR/QSWAdjDelay\r\n"; //prepare command case NL202.ReadParam.NL202_Get_BurstLenth: return "/?RDVAR/BurstLength\r\n"; //prepare command case NL202.ReadParam.NL202_Get_SyncMode: return "/?RDVAR/SyncMode\r\n"; //prepare command case NL202.ReadParam.NL202_Get_SH1Temp: return "/?RDVAR/SH1Temp\r\n"; //prepare command case NL202.ReadParam.NL202_Get_AttnTrans: return "/?RDVAR/AttenTrans\r\n"; //prepare command case NL202.ReadParam.NL202_Get_RepetitionRate: return "/?RDVAR/RepetitionRate\r\n"; //prepare command case NL202.ReadParam.NL202_Get_ShotCnt: ///?RDVAR/TotalOpticalShots return "/?RDVAR/TotalOpticalShots\r\n"; //prepare command default: break; } return ""; } } }