/* * Copyright (c) 2025 LG Electronics Inc. * SPDX-License-Identifier: LicenseRef-LGE-Proprietary */ using Aurora.Api.Devices; using System; using System.Text; namespace VisionLight { /// /// [상시 조명 컨트롤러 - 16CH / 시리얼 통신] /// Range : (0,255) /// Baudrate : /// DataBit : 8 bit /// StopBit : 1 bit /// ParityBit : None /// internal class Light_TSM_I16R : LightBase_Serial { public readonly string STX = "" + (char)0x2; public readonly string ETX = "" + (char)0x3; public readonly int GROUP = 1; public Light_TSM_I16R(string deviceId) : base(deviceId) { } protected override eLightResult SetOnImpl(int channel) { SetLevelImpl(LastChLevels[channel], channel); return eLightResult.OK; } protected override eLightResult SetOffImpl(int channel) { SetLevelImpl(0, channel); return eLightResult.OK; } protected override eLightResult SetLevelImpl(int level, int channel) { try { lock (LockThis) { ClearBuffer(); SendData_StrToByte(level, channel); return eLightResult.OK; } } catch (Exception e) { LOG.FuncE(e.Message); } return eLightResult.NG; } private void SendData_StrToByte(int level, int channel) { try { // Led Level Set // 01WL01125 : /GROUP_01/WRITE/LED/채널_01~16/LEVEL_000~255/ string msg = string.Format("{0}{1:d2}WL{2:d2}{3:d3}{4}", STX, GROUP, channel, level, ETX); byte[] sendData = Encoding.UTF8.GetBytes(msg); SerialConn.Write(sendData, sendData.Length); } catch (Exception e) { LOG.FuncE(e.Message); } } private void ClearBuffer() { try { // SerialPortDevice에 구현 //if (_SerialPort.IsOpen) { // _SerialPort.DiscardInBuffer(); // _SerialPort.DiscardOutBuffer(); //} } catch (Exception e) { LOG.FuncE(e.Message); } } } }