using Aurora.Api; using Aurora.Api.Devices; using VisionCommon; using Hermes; namespace VisionLight { /// /// 시리얼 조명 베이스 클래스 /// public abstract class LightBase_Serial : LightBase { /// 시리얼 통신 protected SerialConn SerialConn = null; /// /// 생성자 /// EquipmentInfo.SimulationMode로 시뮬레이션 상태를 설정한다. /// /// 디바이스 ID protected LightBase_Serial(string deviceId) : base(deviceId) { LightConnType = eLightConnType.Serial; } /// /// 생성자 /// /// 디바이스 ID /// 시뮬레이션 상태 protected LightBase_Serial(string deviceId, bool isSimul) : base(deviceId, isSimul) { LightConnType = eLightConnType.Serial; } /// /// 디바이스 Activate /// /// 디바이스 컨피그 /// protected override int DoActivate(IDeviceConfig config) { SetLightConfig(config as LightConfig); InitLastChParams(); var lightConfig_Serial = (LightConfig_Serial)LightConfig; if (IsSimul) { return E1.OK; } else { if (SerialConn == null) { SerialConn = new SerialConn(DeviceId); } else if (SerialConn.IsPortOpen()) { return E1.OK; } } int res = SerialConn.Open(lightConfig_Serial.SerialConnConfig); if (res == E1.OK) { SetOnAllInternal(); // 시작시 모든 조명 On (Default) } return res; } /// /// 디바이스 Deactivate /// /// protected override int DoDeactivate() { ClearLastChParams(); if (EquipAdapter.Instance.EquipMode.IsSimulMode()) { return E1.OK; } else { if (SerialConn != null) { return SerialConn.Close(); } } return E1.OK; } /// /// 조명 켜기 /// /// 채널 번호 /// 조명 제어 결과 public eLightResult SetOn(int channel = -1) { if (!IsConnected()) { return eLightResult.NG; } return base.SetOn(channel); } /// /// 조명 끄기 /// /// 채널 번호 /// 조명 제어 결과 public new eLightResult SetOff(int channel = -1) { if (!IsConnected()) { return eLightResult.NG; } return base.SetOff(channel); } /// /// 조명 상태 가져오기 /// /// 채널 번호 /// 조명 상태 (on : true, off : false) public new bool GetOnOff(int channel) { return base.GetOnOff(channel); } /// /// 조명 값 가져오기 /// /// 채널 번호 /// 조명 값 public new int GetLevel(int channel) { if (!IsConnected()) { return 0; } return base.GetLevel(channel); } /// /// 조명 값 제어 (개별) /// /// 레벨 /// 채널 번호 /// 조명 제어 결과 public new eLightResult SetLevel(int level, int channel = -1) { if (!IsConnected()) { return eLightResult.NG; } return base.SetLevel(level, channel); } private bool IsConnected() { if (EquipAdapter.Instance.EquipMode.IsSimulMode()) { return true; } else if (SerialConn != null && SerialConn.IsConnected()) { return true; } else { return false; } } } }