using Aurora.Api.DataType; using Aurora.Api.Devices; using Hermes; using System; using System.Text; namespace AuroraPowerMeter.Coherent { /* * Coherent 는 일반적인 Coherent 사 PowerMax 를 지원함 * _1. PowerMax-USB/RS : PM 30 모델 * 사용처: STC 솔더링, * 비고: 솔더링에서는 연결 확인용으로 시리얼 넘버를 표시해줬는데, 일단 시리얼넘버는 제외함 (필요하면 추후 검토) */ public partial class PowerMeterPowerMax : SerialConn, IPowerMeter { public enum ErrorCode { QueueOverflow = -350, SystemError = -310, NoError = 0, UnrecognizedCommandQuery = 100, InvalidParameter = 101, DataError = 102 } private SerialConnConfig _connConfig; public PowerMeterPowerMax(string deviceId, bool isSimul = false) : base(deviceId, isSimul) { } public int Connect(SerialConnConfig config) { _connConfig = config; if (IsPortOpen()) { return E1.OK; } return Open(config); } public int Disconnect() { return Close(); } public int Reconnect() { // 1. 컴포트가 열려있으면 닫기 Disconnect(); // 2. 연결 if (IsPortOpen()) { return E1.OK; } return Open(_connConfig); } public bool Measure(out double power) { power = 0; var reply = SendAndRepely(CMD_READ); if (string.IsNullOrEmpty(reply)) { return false; } var splitted = reply.Split(','); if (splitted == null || splitted.Length == 0) { return false; } return double.TryParse(splitted[0], out power); } public bool SetZero() { return Send(CMD_SET_ZERO); } private bool Send(string command) { return Write(command + "\r\n"); } private string SendAndRepely(string commnad) { var bytes = Encoding.ASCII.GetBytes(commnad + "\r\n"); var commandAscii = Encoding.ASCII.GetString(bytes); var reply = WriteAndReadLine(commandAscii); if (string.IsNullOrEmpty(reply)) { return null; } // \r, \n, ' ' (공백), 제거 return reply.Trim("\r\n ".ToCharArray()); } public bool Reset() { return Send(CMD_RESET); } public bool RestoreFactorySetting() { return Send(CMD_RESTORE_SYS_FACTORY_SETTING); } public bool CheckSystemStatus(out bool isOk) { isOk = true; var reply = SendAndRepely(CMD_CHECK_SYS_STATUS); if (string.IsNullOrEmpty(reply)) { return false; } if (reply.Equals("T")) { isOk = false; } return true; } public bool CheckErrorCount(out int count) { count = 0; var reply = SendAndRepely(CMD_CHECK_SYS_STATUS); return int.TryParse(reply, out count); } public bool ClearError() { return Send(CMD_CLEAR_ERROR); } public bool WaveLengthCorrection(int nLength) { throw new NotImplementedException(); } } }