using Aurora.Api; using Aurora.Api.Devices; using Hermes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Markup; namespace AuroraChiller { //우선 Aurora의 SMCChiller를 가져와서 LASA에 필요한 부분을 넣어주자 public interface IMonitoringItems { } public class SmcChiller : SerialPortDevice { public const byte BYTE_STX = 0x02; // 02 public const byte BYTE_ETX = 0x03; // 03 public const byte BYTE_ACK = 0x06; // 06 public const byte BYTE_NAK = 0x15; // 21 public const byte BYTE_0 = 0x30; // 48 public const byte BYTE_1 = 0x31; // 49 public const byte BYTE_5 = 0x35; // 53 public const byte BYTE_CR = 0x0D; public const byte BYTE_LF = 0x0A; public const string CMD_PV1 = "PV1"; public const string CMD_SV1 = "SV1"; public const string CMD_LOC = "LOC"; public const string CMD_STR = "STR"; public const byte BYTE_REQ_READ = 0x52; // 82 public const byte BYTE_REQ_WRITE = 0x57; // 87 public const byte LENGTH_READ_REQUEST_MSG = 8; public const byte LENGTH_WRITE_REQUEST_MSG = 13; public const byte LENGTH_SAVE_REQUEST_MSG = 8; public const byte LENGTH_RESPONSE_MSG = 14; public const byte LENGTH_SLAVE_ADDRESS = 2; public const byte LENGTH_WRITE_ADDRESS = 4; public const byte LENGTH_CMD = 3; public const byte LENGTH_DATA_INTEGER = 4; public const byte LENGTH_DATA_DECIMAL_FRACTION = 1; public const byte LENGTH_DATA = 4; public const byte LENGTH_READ_REGISTER_MSG = 17; public const byte LENGTH_RESPONSE_REGISTER_MSG = 255; private bool bIsSimpleCommMode = false; public SmcChillerConfig _Config { get; set; } public ISmcChiller _SmcChiller { get; set; } #region Simulation private double SimulTargetTemp; private string _DeviceID; public int DeviceNo; #endregion public SmcChiller(string deviceId) : base(deviceId) { _DeviceID = deviceId; } protected override int DoActivate(IDeviceConfig config) { _Config = config as SmcChillerConfig; switch (_Config.Type) { case eChillerType.HRL: _SmcChiller = new SmcChiller_HRL(_DeviceID); break; case eChillerType.HECR: _SmcChiller = new SmcChiller_HECR(_DeviceID); break; case eChillerType.HRS: _SmcChiller = new SmcChiller_HRS(_DeviceID); break; } //임시 if (IsSimul) { return E1.OK; } var result = _SmcChiller.Open(_Config); if (result != E1.OK) { return result; } return Init(); } private int Init() { // Set init vaues from config if (!IsValidSlaveAddress(_Config.SlaveAddress)) { return E1.GENERIC; } if (IsSimul) { SimulTargetTemp = 10; } else { // TargetTemperature 설정은 장치에서 직접 설정한다. // SetTargetTemp(_Config.TargetTemperature); } return E1.OK; } public bool GetConnected() { if (!_SmcChiller.GetConnected()) { Log.E("SMC Chiller Serial Port is NOT Open!"); return false; } return true; } public bool GetChillerRunningFlag() { return _SmcChiller.GetChillerRunningFlag(); } public int UpdateChillerStatus() { return _SmcChiller.UpdateMonitoringItems(); } private bool IsValidSlaveAddress(int slaveAddress) { return (1 <= slaveAddress && slaveAddress <= 99); } protected override int DoDeactivate() { if (IsSimul) { return E1.OK; } else { return _SmcChiller.PortClose(); } } } public interface ISmcChiller { int Open(SmcChillerConfig Config); int PortClose(); int SetTargetTemp(double value); int SetTargetTemp(string channel,double value); int GetTargetTemp(out double temperature); int GetTargetTemp(int Channel, out double temperature); int GetCurrentTemp(int Channel, out double temperature); int SetControlMode(int Value); int SetRunStart(bool bStart); int UpdateMonitoringItems(); bool GetChillerRunningFlag(); bool GetConnected(); IMonitoringItems GetMonitoringItems(); } }