using Aurora.Api; using Aurora.Api.DataType; using Aurora.Api.Devices; using AuroraLight.ALT; using AuroraLight.ERI; using AuroraLight.LvsPn; using Hermes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AuroraLight { public enum eLight { LvsPn, ALT_4CH, ALT_8CH, ERI, } public class LightDevice : Device { Logger Log; internal eLight _lightType; internal ILight _light; public LightDevice(string deviceId, eLight light) { DeviceId = deviceId; CommType = CommunicationType.Serial; // 추후 필요 시 DoActivate 할때 IConnConfig 에서 처리하게끔 추가 필요. Type = DeviceType.Light; Log = new Logger(deviceId); _lightType = light; } protected override int DoActivate(IDeviceConfig config) { var l_config = config as LightConfig; if (IsSimul) { return E1.OK; } else { switch (_lightType) { case eLight.LvsPn: _light = new LvsPnLight(DeviceId, IsSimul, l_config); break; case eLight.ALT_4CH: _light = new ALTLight(DeviceId, IsSimul, eALTLightType.Light_4CH); break; case eLight.ALT_8CH: _light = new ALTLight(DeviceId, IsSimul, eALTLightType.Light_8CH); break; case eLight.ERI: _light = new ERILight(DeviceId, IsSimul, 4); // Channel Count 를 config 에 어떻게 넣을 것인가. break; } return _light.InitInternal(config.ConnConfig as SerialConnConfig) ? E1.OK : E2.NOT_CONNECTED; } } protected override int DoDeactivate() { if (IsSimul) { return E1.OK; } else { if (_lightType == eLight.ERI) { for (int i = 0; i < 4; i++) { _light.SetLightValueInternal(i, 0); } } return (_light as SerialConn).Close(); } } #region Common bool Init(SerialConnConfig conn) { return _light.InitInternal(conn); } public int SetLightValue(List values) { return _light.SetLightValueInternal(values); } public int SetLightValue(int iChannel, int iValue) { if (IsSimul) { return E1.OK; } return _light.SetLightValueInternal(iChannel, iValue); } int OffLight() { return _light.OffLightInternal(); } int OffLight(int iChannel) { return _light.OffLightInternal(iChannel); } bool IsPortError() { return _light.IsPortErrorInternal(); } bool IsConnected() { return (_light as SerialConn).IsConnected(); } #endregion #region LvsPnLight int GetMaxValue() { if (!TypeCheck(eLight.LvsPn)) { throw new NotImplementedException(); } return (_light as ILvsPnLight).GetMaxValueInternal(); } #endregion #region Util private bool TypeCheck(eLight type) { if (type == _lightType) { return true; } else { Log.E("This method does not support the assigned light type differently."); return false; } } #endregion } }