163 lines
5.6 KiB
C#
163 lines
5.6 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace VisionLight {
|
|
/// <summary>
|
|
/// MagnetAttach strobe 조명으로 사용.
|
|
/// light 관련 time delay 필요했던 조명
|
|
/// 조명 Mode를 변경할 경우 늦게 반영되는 경우가 많아, 자주 변경할 경우 GrabSeq와 별개로 별도로 호출해서도 사용 하였음 ( eLightMode )
|
|
/// !주의! 다른 Light와는 상대적으로 Thread sleep이 자주 호출됨. ( 추후 재검증 시 확인 후 주석 처리 할 것 )
|
|
/// </summary>
|
|
public class Light_iPulse_ModbusSerial : LightBase_ModbusSerial {
|
|
/// <summary>
|
|
/// Light Mode
|
|
/// </summary>
|
|
public enum eLIGHT_MODE {
|
|
/// <summary>
|
|
/// Off
|
|
/// </summary>
|
|
Off = 0x00,
|
|
/// <summary>
|
|
/// Continous
|
|
/// </summary>
|
|
Continous = 0x01,
|
|
/// <summary>
|
|
/// Strobe
|
|
/// </summary>
|
|
Strobe = 0x02,
|
|
}
|
|
|
|
private const int _SetLightMode = 0x0300;
|
|
private const int _SetDuration = 0x0310;
|
|
private const int _SetPeriod = 0x0312;
|
|
private const int _SetContinuousBrigtness = 0x0330;
|
|
private const int _SetPulseBrigtness = 0x0340;
|
|
/// <summary>
|
|
/// Light IPlus Modbus Serial 생성자
|
|
/// </summary>
|
|
/// <param name="deviceId">디바이스 Id</param>
|
|
public Light_iPulse_ModbusSerial(string deviceId) : base(deviceId) {
|
|
DeviceId = deviceId;
|
|
}
|
|
/// <summary>
|
|
/// Set Level Implement
|
|
/// </summary>
|
|
/// <param name="level">레벨</param>
|
|
/// <param name="channel">채널</param>
|
|
/// <returns></returns>
|
|
protected override eLightResult SetLevelImpl(int level, int channel) {
|
|
LOG.FuncI();
|
|
int ret = 0;
|
|
int opmode = 0;
|
|
(ret, opmode) = ReadWord(_SetLightMode);
|
|
|
|
Thread.Sleep(100);
|
|
//if (_config.LightType == eLightType.Continuous) {
|
|
if (opmode == (short)eLIGHT_MODE.Continous) {
|
|
ret = WriteWord(_SetContinuousBrigtness, (short)level);
|
|
if (ret != 0)
|
|
return eLightResult.NG;
|
|
}
|
|
else {
|
|
ret = WriteWord(_SetPulseBrigtness, (short)level);
|
|
if (ret != 0)
|
|
return eLightResult.NG;
|
|
}
|
|
Thread.Sleep(100);
|
|
return eLightResult.OK;
|
|
}
|
|
/// <summary>
|
|
/// Set Off Implement
|
|
/// </summary>
|
|
/// <param name="channel">채널</param>
|
|
/// <returns>Light 결과 값</returns>
|
|
protected override eLightResult SetOffImpl(int channel) {
|
|
LOG.FuncI();
|
|
WriteWord(_SetLightMode, (short)eLIGHT_MODE.Off);
|
|
Thread.Sleep(100);
|
|
return eLightResult.OK;
|
|
}
|
|
/// <summary>
|
|
/// Set On Implement
|
|
/// </summary>
|
|
/// <param name="channel">채널</param>
|
|
/// <returns>Light 결과값</returns>
|
|
protected override eLightResult SetOnImpl(int channel) {
|
|
LOG.FuncI();
|
|
WriteWord(_SetLightMode, (short)eLIGHT_MODE.Strobe);
|
|
Thread.Sleep(100);
|
|
return eLightResult.OK;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 모드 변경
|
|
/// </summary>
|
|
/// <param name="mode">Light Mode</param>
|
|
/// <returns>Light 결과 값</returns>
|
|
public eLightResult ModeChange(eLIGHT_MODE mode) {
|
|
int opmode = 0;
|
|
int ret = 0;
|
|
(ret, opmode) = ReadWord(_SetLightMode);
|
|
|
|
Thread.Sleep(100);
|
|
// 임시 사용을 위해 Ch1 = strobe, ch2 = continous 사용
|
|
//if (_config.LightType == eLightType.Continuous) {
|
|
if (mode == eLIGHT_MODE.Continous) {
|
|
if (opmode != (short)eLIGHT_MODE.Continous) {
|
|
ret = WriteWord(_SetLightMode, (short)eLIGHT_MODE.Continous);
|
|
Thread.Sleep(100);
|
|
if (ret != 0)
|
|
return eLightResult.NG;
|
|
}
|
|
}
|
|
else if (mode == eLIGHT_MODE.Off) {
|
|
if (opmode != (short)eLIGHT_MODE.Off) {
|
|
ret = WriteWord(_SetLightMode, (short)eLIGHT_MODE.Off);
|
|
Thread.Sleep(100);
|
|
if (ret != 0)
|
|
return eLightResult.NG;
|
|
}
|
|
}
|
|
else {
|
|
if (mode == eLIGHT_MODE.Strobe) {
|
|
ret = WriteWord(_SetLightMode, (short)eLIGHT_MODE.Strobe);
|
|
Thread.Sleep(100);
|
|
if (ret != 0)
|
|
return eLightResult.NG;
|
|
}
|
|
}
|
|
return eLightResult.OK;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Duration Setting
|
|
/// </summary>
|
|
/// <param name="duration">continous duriation setting</param>
|
|
/// <returns></returns>
|
|
public eLightResult SetDuration(double duration) {
|
|
int opmode = 0;
|
|
int ret = 0;
|
|
(ret, opmode) = ReadWord(_SetLightMode);
|
|
Thread.Sleep(100);
|
|
|
|
// 임시 사용을 위해 Ch1 = strobe, ch2 = continous 사용
|
|
//if (_config.LightType == eLightType.Continuous) {
|
|
ret = WriteReal(_SetDuration, (float)duration);
|
|
if (ret != 0)
|
|
return eLightResult.NG;
|
|
Thread.Sleep(100);
|
|
|
|
return eLightResult.OK;
|
|
}
|
|
|
|
|
|
}
|
|
}
|