80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using Aurora.Api.Devices;
|
|
using System;
|
|
using System.Text;
|
|
|
|
namespace VisionLight {
|
|
/// <summary>
|
|
/// [스트로브 조명 컨트롤러 - 8CH / 시리얼 통신]
|
|
/// Range : (0,4999) us
|
|
/// Baudrate : 115200 bps
|
|
/// DataBit : 8 bit
|
|
/// StopBit : 1 bit
|
|
/// ParityBit : None
|
|
/// </summary>
|
|
internal class Light_TSM_STM16C : LightBase_Serial {
|
|
public static readonly string STX = "" + (char)0x2;
|
|
public static readonly string ETX = "" + (char)0x3;
|
|
public static readonly int PAGE = 1;
|
|
|
|
public Light_TSM_STM16C(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 (Level은 255로 고정, Strobe Time만 변경해서 사용)
|
|
// STXWLI01255ETX : STX/WRITE/LED/INTENSITY/채널_01~16/LEVEL_000~255/ETX
|
|
//int intensity = (level * 255) / 4000; // 000 ~ 255
|
|
//string sendData = string.Format("{0}WLI{1:d2}{2:d3}{3}", " ", channel, intensity, " ");
|
|
|
|
// Strobe Time Set
|
|
// STXWFT0114000ETX : STX/WRITE/FLASH/TIME/채널_01~16/PAGE_01/TIME_0000~4000/ETX
|
|
string msg = string.Format("{0}WFT{1:d2}{2:d1}{3:d4}{4}", STX, channel, PAGE, 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);
|
|
}
|
|
}
|
|
}
|
|
} |