using Aurora.Api; using Hermes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace VisionLight { /// /// !!! 반드시 UDP로 통신할 해야 함 !!! /// [스트로브 조명 컨트롤러 - 8CH / 소켓 통신] /// Range : (0,1000) /// SocketProtocol : TCP or UDP /// IpAddress : 192.168.0.231 (예시) /// PortNumber : 50000 (예시) /// public class Light_LVS_ES08_Socket : LightBase_Socket { internal const byte CMD_START_CODE = 0x01; internal const byte CMD_END_CODE = 0x04; internal const byte CMD_OP_CODE_WRITE = 0x00; internal const byte LENGTH_DATA_MSG = 0x01; internal const byte LENGTH_LEVEL_DATA_MSG = 0x02; internal const byte ADDR_PAGE_SELECT = 0x3C; internal const byte ADDR_CHANNEL_SELECT = 0x20; internal const byte ADDR_STEP_VALUE = 0x28; internal const byte LENGTH_SET_PAGE_REQUEST_MSG = 6; internal const byte LENGTH_SET_CHANNEL_REQUEST_MSG = 6; internal const byte LENGTH_SET_LEVEL_REQUEST_MSG = 7; /// /// LVS ES08 Socket 생성자 /// /// 디바이스 ID public Light_LVS_ES08_Socket(string deviceId) : base(deviceId) { DeviceId = deviceId; } /// /// Set On Implement /// /// 채널 /// Light 결과 값 protected override eLightResult SetOnImpl(int channel) { SetLevelImpl(LastChLevels[channel], channel); return eLightResult.OK; } /// /// Set Off Implement /// /// 채널 /// Light 결과 값 protected override eLightResult SetOffImpl(int channel) { SetLevelImpl(0, channel); return eLightResult.OK; } /// /// Set Level Implement /// /// 레벨 /// 채널 /// Light 결과 값 protected override eLightResult SetLevelImpl(int level, int channel) { try { lock (LockThis) { if (PageSelect(1) == E1.OK) { //page의 경우 일단 1로 설정 if (ChannelSelect(channel) == E1.OK) { if (SendData_SetLevel(level) == E1.OK) { return eLightResult.OK; } else { return eLightResult.NG; } } else { return eLightResult.NG; } } else { return eLightResult.NG; } } } catch (Exception e) { LOG.FuncE(e.Message); return eLightResult.NG; } } private int PageSelect(int page) { try { byte[] sendData = CreatePageSelectReqMsg(page); SocketConn.Send(sendData); return E1.OK; } catch (Exception e) { LOG.FuncE(e.Message); } return E1.GENERIC; } private byte[] CreatePageSelectReqMsg(int page) { byte[] requestMsg = new byte[LENGTH_SET_PAGE_REQUEST_MSG]; requestMsg[0] = CMD_START_CODE; requestMsg[1] = CMD_OP_CODE_WRITE; requestMsg[2] = LENGTH_DATA_MSG; requestMsg[3] = ADDR_PAGE_SELECT; requestMsg[4] = (byte)page; requestMsg[5] = CMD_END_CODE; return requestMsg; } private int ChannelSelect(int channel) { try { byte[] sendData = CreateChannelSelectReqMsg(channel); SocketConn.Send(sendData); return E1.OK; } catch (Exception e) { LOG.FuncE(e.Message); } return E1.GENERIC; } private byte[] CreateChannelSelectReqMsg(int channel) { byte[] requestMsg = new byte[LENGTH_SET_CHANNEL_REQUEST_MSG]; requestMsg[0] = CMD_START_CODE; requestMsg[1] = CMD_OP_CODE_WRITE; requestMsg[2] = LENGTH_DATA_MSG; requestMsg[3] = ADDR_CHANNEL_SELECT; requestMsg[4] = (byte)channel; requestMsg[5] = CMD_END_CODE; return requestMsg; } private int SendData_SetLevel(int level) { try { byte[] sendData = CreateSetLevelReqMsg(level); SocketConn.Send(sendData); return E1.OK; } catch (Exception e) { LOG.FuncE(e.Message); } return E1.GENERIC; } private byte[] CreateSetLevelReqMsg(int level) { byte[] requestMsg = new byte[LENGTH_SET_LEVEL_REQUEST_MSG]; requestMsg[0] = CMD_START_CODE; requestMsg[1] = CMD_OP_CODE_WRITE; requestMsg[2] = LENGTH_LEVEL_DATA_MSG; requestMsg[3] = ADDR_STEP_VALUE; requestMsg[4] = (byte)(level % 256); requestMsg[5] = (byte)(level / 256); requestMsg[6] = CMD_END_CODE; return requestMsg; } } }