2026-03-30 17:09:29 +09:00

1040 lines
36 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Aurora.Api;
using Aurora.Api.Devices;
using AuroraTriggerBoard;
using AuroraTriggerBoard.SJT;
using AuroraTriggerBoard.SJTV3;
using Hermes;
//using lge.pri.hislog;
using PropertyTools.DataAnnotations;
namespace AuroraTriggerBoard
{
public class Trigger : Aurora.Api.Device
{
public enum eTriggerType
{
SJT, // version 4
SJTV3,
}
public enum EncoderPositionMap
{
[Description("1:1")]
Normal,
[Description("Custom Table")]
CustomTable
}
public enum EncoderDirection
{
Forward,
Backward
}
public enum TriggerGenMode
{
[Description("Sequence")]
Sequence = 0,
[Description("Direct")]
Direct = 1,
[Description("Timer")]
Timer = 3,
[Description("Ext Input")]
ExternalInput = 4
}
public enum EncoderMode
{
Real,
Simulation
}
public enum ChannelOutMode
{
[Description("SEQBY1TIRG_OUT_MODE")]
SeqBy1Trig,
[Description("Simple")]
Simple,
[Description("Sequence Mask")]
SequenceMask,
[Description("Direct Mask")]
DirectMask
}
public enum FNDMode
{
Encoder,
Trigger,
Toggle
}
public struct TrigSeqSet
{
public double StartPosition;
public double Interval;
public uint Iteration;
public byte Out2_SeqMode_Sel;
public byte WD_Set_Sel;
}
// public class Config : IDeviceConfig
// {
// public int CommPortNumber { get; set; }
// public IConnConfig ConnConfig { get/* => throw new NotImplementedException()*/; set/* => throw new NotImplementedException()*/; }
// }
private readonly bool _IsSimulBySetting;
//private readonly IntPtr TriggerInstance;
private static readonly Logger LOG = new Logger("Trigger");
private TriggerGenMode _ActTrigGenMode; public TriggerGenMode ActTrigGenMode { get => _ActTrigGenMode; set => value = _ActTrigGenMode; }
private long _ActTrigEncCount; public long ActTrigEncCount { get => _ActTrigEncCount; set => value = _ActTrigEncCount; }
private uint _ActTrigTrigCount; public uint ActTrigTrigCount { get => _ActTrigTrigCount; set => value = _ActTrigTrigCount; }
// private const string DriverDLL = "AuroraTrigger4.dll";
//private SJTTrigger _Trigger;
ITrigger _Trigger;
eTriggerType _Type;
//public TriggerConfig _Config{ get; set; }
private Dictionary<ChannelOutMode, uint> ChannelOutModeToValueMap = new Dictionary<ChannelOutMode, uint>
{
{
ChannelOutMode.Simple, 3u
},
{
ChannelOutMode.SequenceMask, 2u
},
{
ChannelOutMode.DirectMask, 1u
},
{
ChannelOutMode.SeqBy1Trig, 0u
}
};
private Dictionary<uint, ChannelOutMode> ValueToChannelOutModeMap = new Dictionary<uint, ChannelOutMode>
{
{
3u,
ChannelOutMode.Simple
},
{
2u,
ChannelOutMode.SequenceMask
},
{
1u,
ChannelOutMode.DirectMask
},
{
0u,
ChannelOutMode.SeqBy1Trig
}
};
public Trigger(string deviceId, eTriggerType type, bool isSimul)
{
_IsSimulBySetting = isSimul;
_Type = type;
//_Config = TriggerConfig.GetDefaultConfig();
try
{
// TriggerInstance = CreateEncoderWrapper();
}
catch (Exception ex)
{
LOG.W("Warning : " + ex.Message, ".ctor");
}
}
~Trigger()
{
//if (TriggerInstance != IntPtr.Zero)
//{
// ReleaseEncoderWrapper(TriggerInstance);
//}
}
protected override int DoActivate(IDeviceConfig config)
{
//var triConfig = config as TriggerConfig;
dynamic triConfig;
switch(_Type) {
case eTriggerType.SJTV3:
triConfig = config as TriggerV3Config;
break;
case eTriggerType.SJT:
default:
triConfig = config as TriggerConfig;
break;
}
var serConfig = triConfig.ConnConfig as SerialConnConfig;
IsSimul = triConfig.IsSimul || _IsSimulBySetting;
//_Config = triConfig;
int nBaudRate = serConfig.BaudRate;
int nBaudRateIdx;
switch (nBaudRate)
{
case 4800: nBaudRateIdx = 0; break;
case 9600: nBaudRateIdx = 1; break;
case 14400: nBaudRateIdx = 2; break;
case 19200: nBaudRateIdx = 3; break;
case 38400: nBaudRateIdx = 4; break;
case 56000: nBaudRateIdx = 5; break;
case 57600: nBaudRateIdx = 6; break;
case 115200:
default: nBaudRateIdx = 7; break;
}
bool flag = false;
try
{
//flag = PortOpen(TriggerInstance, (byte)serConfig.PortNum, (byte)nBaudRateIdx);
//SetLogDir("D:\\SJTLOG");
//_Trigger = new SJTTrigger(DeviceId, IsSimul);
switch (_Type) {
case eTriggerType.SJT:
_Trigger = new SJTTrigger(DeviceId, IsSimul);
break;
case eTriggerType.SJTV3:
_Trigger = new SJTTriggerV3(DeviceId, IsSimul);
break;
}
if (_Trigger.Connect(serConfig) == E1.OK) flag = true;
else flag = false;
}
catch (Exception ex)
{
LOG.W("Warning : " + ex.Message, "DoActivate");
}
if (!flag)
{
return -3000000;
}
return 0;
}
protected override int DoDeactivate()
{
bool flag = false;
try
{
//flag = PortClose(TriggerInstance);
// flag = Disconnect();
if (_Trigger.Disconnect() == E1.OK) flag = true;
else flag = false;
}
catch (Exception ex)
{
LOG.W("Warning : " + ex.Message, "DoDeactivate");
}
if (!flag)
{
return -3000000;
}
return 0;
}
// const string ENCODER_DLL = "CreateEncoderWrapInstance.dll";
// [DllImport(ENCODER_DLL)]
// public static extern IntPtr CreateEncoderWrapper();
// [DllImport(ENCODER_DLL)]
// public static extern void ReleaseEncoderWrapper(IntPtr instance);
// [DllImport(ENCODER_DLL)]
// private static extern bool PortOpen(IntPtr instance, byte portNumber, byte boudrate);
// public bool Connect(int portNumber, int boudrate)
// {
// if (IsSimul) { return true; }
// return PortOpen(TriggerInstance, (byte)portNumber, (byte)boudrate);
// }
// [DllImport(ENCODER_DLL)]
// private static extern void SetLogFolder(IntPtr instance, char[] Path);
// public void SetLogDir(string Path)
// {
// if (IsSimul) { return; }
// SetLogFolder(TriggerInstance, Path.ToCharArray());
// }
// [DllImport(ENCODER_DLL)]
// private static extern void ValueInit(IntPtr instance);
// public void ValueInit()
// {
// if (IsSimul) { return; }
// ValueInit(TriggerInstance);
// }
// [DllImport(ENCODER_DLL)]
// private static extern bool PortClose(IntPtr instance);
// public bool Disconnect()
// {
// if (IsSimul) { return true; }
// return PortClose(TriggerInstance);
// }
// [DllImport(ENCODER_DLL)]
// private static extern ushort GetSJT_DLL_Ver(IntPtr instance, StringBuilder version, int maxLenght);
public ushort GetDllVersion(out string version)
{
if (IsSimul) {
version = "Simul";
return E1.OK;
}
//StringBuilder stringBuilder = new StringBuilder(20);
// ushort dllVersion = GetSJT_DLL_Ver(TriggerInstance, stringBuilder, stringBuilder.Capacity + 1);
char[] dllverstr = new char[20];
ushort dllVersion = _Trigger.GetSJT_DLL_Ver(ref dllverstr);
version = new string(dllverstr);
return dllVersion;
}
// [DllImport(ENCODER_DLL)]
// private static extern ushort GetSJTVersion(IntPtr instance, StringBuilder hwVer, int hwVerMaxLenght, StringBuilder fwVer, int fwVerMaxLength);
public ushort GetHWVersion(out string hwVer, out string fwVer)
{
if (IsSimul) {
hwVer = "Simul";
fwVer = "Simul";
return E1.OK;
}
//StringBuilder stringBuilder = new StringBuilder(50);
//StringBuilder stringBuilder2 = new StringBuilder(50);
//ushort version = GetSJTVersion(TriggerInstance, stringBuilder, stringBuilder.Capacity + 1, stringBuilder2, stringBuilder2.Capacity + 1);
//hwVer = stringBuilder.ToString();
//fwVer = stringBuilder2.ToString();
//return version;
string hwverstr, fmverstr;
short ret = _Trigger.GetSJTVersion(out hwverstr, out fmverstr); // short version = _Trigger.GetSJTVersion(out hwverstr, out fmverstr);
hwVer = hwverstr;
fwVer = fmverstr;
return Convert.ToUInt16(ret < 0 ? -1 * ret : ret); // return Convert.ToUInt16(version);
}
// [DllImport(ENCODER_DLL)]
// private static extern ushort SetTrigCorrectTable(IntPtr instance, double[] positionTable, ulong[] EncoderTable);
public ushort SetTrigCorrectTable(double[] positionTable, ulong[] encoderTable)
{
if (IsSimul) { return E1.OK; }
//return SetTrigCorrectTable(TriggerInstance, positionTable, encoderTable);
return _Trigger.SetTrigCorrectTable(ref positionTable, ref encoderTable);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort DisableTrigCorrectTable(IntPtr instance);
public ushort DisableTrigCorrectTable()
{
if (IsSimul) { return E1.OK; }
//return DisableTrigCorrectTable(TriggerInstance);
return _Trigger.DisableTrigCorrectTable();
}
// [DllImport(ENCODER_DLL)]
// private static extern ushort SetEncDirection(IntPtr instance, uint direction);
public ushort SetEncoderDirection(EncoderDirection direction)
{
if (IsSimul) { return E1.OK; }
uint direction2 = ((direction == EncoderDirection.Forward) ? 1u : 0u);
// return SetEncDirection(TriggerInstance, direction2);
return _Trigger.SetEncDirection(direction2);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetEncDirection(IntPtr instance, uint[] direction);
public ushort GetEncoderDirection(out EncoderDirection direction)
{
if (IsSimul) {
direction = EncoderDirection.Forward;
return E1.OK;
}
//uint[] array = new uint[1];
//ushort encoderDirection = GetEncDirection(TriggerInstance, array);
//direction = ((array[0] != 1) ? EncoderDirection.Backward : EncoderDirection.Forward);
uint encdir = 0;
ushort encoderDirection = _Trigger.GetEncDirection(ref encdir);
direction = ((encdir != 1) ? EncoderDirection.Backward : EncoderDirection.Forward);
return encoderDirection;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetStrobe(IntPtr instance, byte StrobeCh, uint Strobe_Mask, double[] StrobeData_us_pt);
public ushort SetStrobe(byte StrobeCh, uint Strobe_Mask, double[] Trig_Width_Delay_us)
{
if (IsSimul) { return E1.OK; }
// double[] array = new double[16];
// for (int i = 0; i < 8; i++)
// {
// array[i * 2] = width[i];
// array[i * 2 + 1] = delay[i];
// }
//return SetStrobe(TriggerInstance, StrobeCh, Strobe_Mask, Trig_Width_Delay_us);
return _Trigger.SetStrobe(StrobeCh, Strobe_Mask, ref Trig_Width_Delay_us);
}
// public ushort SetStrobe(byte StrobeCh, uint Strobe_Mask, double[] width, double[] delay)
// {
// double[] array = new double[16];
// for (int i = 0; i < 8; i++)
// {
// array[i * 2] = width[i];
// array[i * 2 + 1] = delay[i];
// }
//
// return SetStrobe(TriggerInstance, StrobeCh, Strobe_Mask, array);
// }
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetStrobe(IntPtr instance, byte StrobeCh, uint[] StrobeData_us_pt);
public ushort GetStrobe(byte StrobeCh, ref byte mask, ref double[] width, ref double[] delay)
{
if (IsSimul) { return E1.OK; }
uint[] array = new uint[17];
//ushort strobe = GetStrobe(TriggerInstance, StrobeCh, array);
ushort strobe = _Trigger.GetStrobe(StrobeCh, ref array);
mask = (byte)array[0];
for (int i = 0; i < 8; i++) {
width[i] = (double)array[i * 2 + 1] / 100.0;
delay[i] = (double)array[i * 2 + 2] / 100.0;
}
return strobe;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetTrigMode(IntPtr instance, uint TrigGenMode, uint ChOutMode);
public ushort SetTrigMode(TriggerGenMode TrigGenMode, ChannelOutMode ChOutMode, bool isLineLED = false)
{
if (IsSimul) { return E1.OK; }
//return SetTrigMode(TriggerInstance, (uint)TrigGenMode, ChannelOutModeToValueMap[ChOutMode] | (isLineLED ? 128u : 0u));
ushort ret = _Trigger.SetTrigMode((uint)TrigGenMode, ChannelOutModeToValueMap[ChOutMode] | (isLineLED ? 128u : 0u));
if (ret == SJTTrigger.OK_RETURN) {
ActTrigGenMode = TrigGenMode;
}
return ret;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetTrigMode(IntPtr instance, out uint TrigGenMode, out uint ChOutMode);
public ushort GetTrigMode(out TriggerGenMode TrigGenMode, out ChannelOutMode ChOutMode)
{
if (IsSimul) {
TrigGenMode = 0;
ChOutMode = 0;
return E1.OK;
}
uint TrigGenMode2 = 0;
uint ChOutMode2 = 0;
//ushort trigMode = GetTrigMode(TriggerInstance, out TrigGenMode2, out ChOutMode2);
ushort trigMode = _Trigger.GetTrigMode(ref TrigGenMode2, ref ChOutMode2);
TrigGenMode = (TriggerGenMode)TrigGenMode2;
ChOutMode = ValueToChannelOutModeMap[ChOutMode2];
if (trigMode == SJTTrigger.OK_RETURN) {
ActTrigGenMode = TrigGenMode;
}
return trigMode;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetCntInType(IntPtr instance, uint CntInType);
public ushort SetEncoderMode(EncoderMode CntInType)
{
if (IsSimul) { return E1.OK; }
//return SetCntInType(TriggerInstance, (uint)CntInType);
return _Trigger.SetCntInType((uint)CntInType);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetSimulEnc(IntPtr instance, long StartEnc, int IntervalPerSec);
public ushort SetSimulEnc(long StartEnc, int IntervalPerSec)
{
if (IsSimul) { return E1.OK; }
//return SetSimulEnc(TriggerInstance, StartEnc, IntervalPerSec);
return _Trigger.SetSimulEnc(StartEnc, IntervalPerSec);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetTrigTimerSeq(IntPtr instance, double timerfreq_us);
public ushort SetTrigTimerSeq(double timerfreq_us)
{
if (IsSimul) { return E1.OK; }
//return SetTrigTimerSeq(TriggerInstance, timerfreq_us);
return _Trigger.SetTrigTimerSeq(timerfreq_us);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetSimulTrigLimit(IntPtr instance, uint TrigLimit_Value);
public ushort SetTrigLimit(uint TrigLimit_Value)
{
if (IsSimul) { return E1.OK; }
//return SetSimulTrigLimit(TriggerInstance, TrigLimit_Value);
return _Trigger.SetSimulTrigLimit(TrigLimit_Value);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetMaskSet(IntPtr instance, byte[] TrigSet);
public ushort SetMaskSet(ref byte[] TrigSet)
{
if (IsSimul) { return E1.OK; }
if (TrigSet.Length != 8) {
return 0;
}
//return SetMaskSet(TriggerInstance, TrigSet);
return _Trigger.SetMaskSet(ref TrigSet);
}
public ushort SetMaskSet(uint NumberofMask, ref byte[] TrigSet)
{
if (IsSimul) { return E1.OK; }
if (TrigSet.Length != 8) {
return 0;
}
//return SetMaskSet(TriggerInstance, TrigSet);
return _Trigger.SetMaskSet(NumberofMask, ref TrigSet);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetDirectMask(IntPtr instance, uint NumberofMask, byte[] DirectMask_pt);
public ushort SetDirectMask(uint NumberofMask, ref byte[] DirectMask)
{
if (IsSimul) { return E1.OK; }
if (DirectMask.Length < NumberofMask) {
return 0;
}
//return SetDirectMask(TriggerInstance, NumberofMask, DirectMask);
return _Trigger.SetDirectMask(NumberofMask, ref DirectMask);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SJT_Trigger_Start(IntPtr instance);
public ushort StartTrigger()
{
if (IsSimul) { return E1.OK; }
//return SJT_Trigger_Start(TriggerInstance);
return _Trigger.SJT_Trigger_Start();
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SJT_Trigger_Stop(IntPtr instance);
public ushort StopTrigger()
{
if (IsSimul) { return E1.OK; }
//return SJT_Trigger_Stop(TriggerInstance);
return _Trigger.SJT_Trigger_Stop();
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetCurEncoderCnt(IntPtr instance, out long Cur_EncCnt);
public ushort GetEncoderCount(out long CurrrentEncoderCount)
{
if (IsSimul) {
CurrrentEncoderCount = 0;
return E1.OK;
}
//return GetCurEncoderCnt(TriggerInstance, out CurrrentEncoderCount);
ushort ret = _Trigger.GetCurEncoderCnt(out CurrrentEncoderCount);
if (ret == SJTTrigger.OK_RETURN) {
ActTrigEncCount = CurrrentEncoderCount;
}
return ret;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetENCCnt(IntPtr instance, long EncCnt);
public ushort SetEncoderCount(long EncoderCount)
{
if (IsSimul) { return E1.OK; }
//return SetENCCnt(TriggerInstance, EncoderCount);
ushort ret = _Trigger.SetENCCnt(EncoderCount, 1);
if (ret == SJTTrigger.OK_RETURN) {
ActTrigEncCount = EncoderCount;
}
return ret;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort ENC_CNT_Reset(IntPtr instance);
public ushort ResetEncoderCount()
{
if (IsSimul) { return E1.OK; }
//return ENC_CNT_Reset(TriggerInstance);
ushort ret = _Trigger.ENC_CNT_Reset();
if (ret == SJTTrigger.OK_RETURN) {
ActTrigEncCount = 0;
}
return ret;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SJT_SystemReset(IntPtr instance);
public ushort ResetSystem()
{
if (IsSimul) { return E1.OK; }
//return SJT_SystemReset(TriggerInstance);
ushort ret = _Trigger.SJT_SystemReset();
if (ret == SJTTrigger.OK_RETURN) {
ActTrigEncCount = 0;
ActTrigTrigCount = 0;
}
return ret;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetFNDMode(IntPtr instance, byte FND_Mode);
public ushort SetFNDMode(FNDMode mode)
{
if (IsSimul) { return E1.OK; }
//return SetFNDMode(TriggerInstance, (byte)mode);
return _Trigger.SetFNDMode((byte)mode);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetCurPosition(IntPtr instance, out long Cur_Position);
public ushort GetCurPosition(out long CurrentPosition)
{
if (IsSimul) {
CurrentPosition = 0;
return E1.OK;
}
//return GetCurPosition(TriggerInstance, out CurrentPosition);
return _Trigger.GetCurPosition(out CurrentPosition);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetNextRefCnt(IntPtr instance, out long Next_RefCnt, out uint RefFF_Dcnt, out bool RefFF_pEmp, out bool RefFF_Empty, out ushort RefFF_OutMask, out byte RefFF_WD);
public ushort GetNextRefCount(out long Next_RefCnt, out uint RefFF_Dcnt, out bool RefFF_pEmp, out bool RefFF_Empty, out ushort RefFF_OutMask, out byte RefFF_WD)
{
if (IsSimul) {
Next_RefCnt = 0;
RefFF_Dcnt = 0;
RefFF_pEmp = false;
RefFF_Empty = false;
RefFF_OutMask = 0;
RefFF_WD = 0;
return E1.OK;
}
//return GetNextRefCnt(TriggerInstance, out Next_RefCnt, out RefFF_Dcnt, out RefFF_pEmp, out RefFF_Empty, out RefFF_OutMask, out RefFF_WD);
return _Trigger.GetNextRefCnt(out Next_RefCnt, out RefFF_Dcnt, out RefFF_pEmp, out RefFF_Empty, out RefFF_OutMask, out RefFF_WD);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort Debug_RefFF_Change(IntPtr instance);
public ushort Debug_RefFF_Change()
{
if (IsSimul) { return E1.OK; }
//return Debug_RefFF_Change(TriggerInstance);
return _Trigger.Debug_RefFF_Change();
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort GetTrigNErrCnt(IntPtr instance, uint[] TrigCount, uint[] ErrCount, float[] MaxFreq);
public ushort GetTrigNErrCnt(ref uint[] TrigCount, ref uint[] ErrCount, ref float[] MaxFreq)
{
if (IsSimul) { return E1.OK; }
//return GetTrigNErrCnt(TriggerInstance, TrigCount, ErrCount, MaxFreq);
return _Trigger.GetTrigNErrCnt(TrigCount, ErrCount, MaxFreq);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort TrigCount_Reset(IntPtr instance);
public ushort ResetTriggerCount()
{
if (IsSimul) { return E1.OK; }
//return TrigCount_Reset(TriggerInstance);
ushort ret = _Trigger.TrigCount_Reset();
if (ret == SJTTrigger.OK_RETURN)
{
ActTrigTrigCount = 0;
}
return ret;
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetTrigSet(IntPtr instance, byte NumberOfTrigSet, TrigSeqSet[] TrigSet);
public ushort SetTriggerSet(byte NumberOfTrigSet, ref TrigSeqSet[] TrigSet)
{
if (IsSimul) { return E1.OK; }
if (TrigSet.Length < NumberOfTrigSet) {
return 0;
}
//return SetTrigSet(TriggerInstance, NumberOfTrigSet, TrigSet);
return _Trigger.SetTrigSet(NumberOfTrigSet, ref TrigSet);
}
//[DllImport(ENCODER_DLL)]
//private static extern ushort SetTrigDirect(IntPtr instance, uint NumberOfPosData, long[] TrigDirectEnc, ushort[] TrigDirectChMask, byte[] TrigDirectWDSet);
public ushort SetTrigDirect(uint NumberOfPosData, ref ulong[] TrigDirectEnc, ref ushort[] TrigDirectChMask, ref byte[] TrigDirectWDSet)
{
if (IsSimul) { return E1.OK; }
if (TrigDirectEnc.Length < NumberOfPosData || TrigDirectChMask.Length < NumberOfPosData || TrigDirectWDSet.Length < NumberOfPosData) {
return 0;
}
//return SetTrigDirect(TriggerInstance, NumberOfPosData, TrigDirectEnc, TrigDirectChMask, TrigDirectWDSet);
return _Trigger.SetTrigDirect(NumberOfPosData, ref TrigDirectEnc, ref TrigDirectChMask, ref TrigDirectWDSet);
}
public ushort SetTriggerStartdelay(uint startDelay)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetTriggerStartdelay(startDelay);
}
public ushort GetTriggerStartdelay(ref uint startDelay)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetTriggerStartdelay(ref startDelay);
}
public ushort SetTriggerWidth(uint triggerWidth)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetTriggerWidth(triggerWidth);
}
public ushort GetTriggerWidth(ref uint triggerWidth)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetTriggerWidth(ref triggerWidth);
}
public ushort SetTriggerCnt(uint triggerCnt)
{
if (IsSimul) { return E1.OK; }
ushort ret = _Trigger.SetTriggerCnt(triggerCnt);
if (ret == SJTTrigger.OK_RETURN) {
ActTrigTrigCount = triggerCnt;
}
return ret;
}
public ushort GetTriggerCnt(ref uint triggerCnt)
{
if (IsSimul) { return E1.OK; }
ushort ret = _Trigger.GetTriggerCnt(ref triggerCnt);
if (ret == SJTTrigger.OK_RETURN)
{
ActTrigTrigCount = triggerCnt;
}
return ret;
}
public ushort SetTrigPulse(uint triggerPulse)
{
if (IsSimul) { return E1.OK; }
//return _Trigger.SetTrigPulse(triggerPulse);
return E1.OK;
}
public ushort GetTrigPulse(ref uint triggerPulse)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetTrigPulse(ref triggerPulse);
}
public ushort SetEncEnable(byte encEnable)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetEncEnable(encEnable);
}
public ushort GetEncEnable(ref byte encEnable)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetEncEnable(ref encEnable);
}
public ushort SetRunMode(byte runMode)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetRunMode(runMode);
}
public ushort GetRunMode(ref byte runMode)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetRunMode(ref runMode);
}
public ushort SetInputPol(byte inputPol)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetInputPol(inputPol);
}
public ushort GetInputPol(ref byte inputPol)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetInputPol(ref inputPol);
}
public ushort SetTriggerPol(byte triggerPol)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetTriggerPol(triggerPol);
}
public ushort GetTriggerPol(ref byte triggerPol)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetTriggerPol(ref triggerPol);
}
public ushort SetStrobeStartdelay(uint startDelay)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetStrobeStartdelay(startDelay);
}
public ushort GetStrobeStartdelay(ref uint startDelay)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetStrobeStartdelay(ref startDelay);
}
public ushort SetStrobeWidth(uint strobeWidth)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetStrobeWidth(strobeWidth);
}
public ushort GetStrobeWidth(ref uint strobeWidth)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetStrobeWidth(ref strobeWidth);
}
public ushort SetStrobePol(byte strobePol)
{
if (IsSimul) { return E1.OK; }
return _Trigger.SetStrobePol(strobePol);
}
public ushort GetStrobePol(ref byte strobePol)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetStrobePol(ref strobePol);
}
public ushort GetEndTrigger(ref byte endTrigger)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetEndTrigger(ref endTrigger);
}
public ushort GetError(ref byte errorCode)
{
if (IsSimul) { return E1.OK; }
return _Trigger.GetError(ref errorCode);
}
// <HairPinTwister> 에서 사용
public bool SetTriggerSettingFlow(double _triggerPos, double _triggerInterbal, uint _iterationNum, bool _3DUse = true)
{
int rtn = -1;
rtn = StopTrigger();
if (E1.OK == rtn) {
rtn = SetEncoderDirection(EncoderDirection.Forward);
if (E1.OK == rtn) {
rtn = ResetEncoderCount();
if (E1.OK == rtn) {
//rtn = ResetSystem();
if (E1.OK == rtn) {
rtn = SetTrigMode(TriggerGenMode.Sequence, ChannelOutMode.Simple);
if (E1.OK == rtn) {
rtn = SetEncoderMode(EncoderMode.Real); // TODO:: Real:외부 엔코더 입력 신호 사용, Simulation:내부 가상 엔코더 사용
if (E1.OK == rtn) {
rtn = SetTrigLimit(0); // TODO": 동기 신호 출력 개수, “0”으로 설정될 경우 Limits 이 없이 정지 할 때까지.
if (E1.OK == rtn) {
TrigSeqSet[] TrigCmdSet = new TrigSeqSet[254]; //0~253개 까지 테이블 구성 가능
double TrigStart_Pos = 0; //0도 위치 부터 시작
double TrigInterbal = _triggerInterbal; //7.5도 마다 83.3주기 발생 (단위는 모르는 상태..)
uint Iteration_Num = _iterationNum; // 최대 Trigger 신호, Bead 개수가 총 48개로 구성되어 있음
TrigCmdSet[0].StartPosition = TrigStart_Pos; //시작 위치
TrigCmdSet[0].Interval = TrigInterbal; // 발생 주기
TrigCmdSet[0].Iteration = Iteration_Num; // 총 발생 개수
TrigCmdSet[0].Out2_SeqMode_Sel = 0; // 0~6 MaskSeqSet
TrigCmdSet[0].WD_Set_Sel = 0; // Width Delay Set select
rtn = SetTriggerSet(1, ref TrigCmdSet);
if (E1.OK == rtn) {
double[] Trig_Width_Delay_us = new double[16];
if (_3DUse) {
Trig_Width_Delay_us[0] = 150;
Trig_Width_Delay_us[1] = 0;
} else {
Trig_Width_Delay_us[0] = 1000;
Trig_Width_Delay_us[1] = 10;
}
rtn = SetStrobe(0, 1, Trig_Width_Delay_us); //Ch:0, Mask:1, Width:1000/Delay:100
if (E1.OK == rtn) {
rtn = SetStrobe(1, 1, Trig_Width_Delay_us); //TODO::Trigger 추가로 추가, Ch:1, Mask:1, Width:1000/Delay:100
if (E1.OK == rtn) {
rtn = SetStrobe(2, 1, Trig_Width_Delay_us); //TODO::Trigger 추가로 추가, Ch:2, Mask:1, Width:1000/Delay:100
if (E1.OK == rtn) {
rtn = StartTrigger();
if (E1.OK == rtn) {
return true;
}
}
}
}
}
}
}
}
}
}
}
}
return false;
}
public ushort GetTrigTimeFreq(out uint TrigTimeFreq_10ns)
{
TrigTimeFreq_10ns = 0;
if (IsSimul) { return E1.OK; }
return _Trigger.GetTrigTimeFreq(out TrigTimeFreq_10ns);
}
public ushort GetTrigTimeLimit(out uint TrigTimeLimit)
{
TrigTimeLimit = 0;
if (IsSimul) { return E1.OK; }
return _Trigger.GetTrigTimeLimit(out TrigTimeLimit);
}
public ushort GetEncPosMapTableUse(out EncoderPositionMap encposmapuse)
{
encposmapuse = EncoderPositionMap.Normal;
if (IsSimul) { return E1.OK; }
return _Trigger.GetEncPosMapTableUse(out encposmapuse);
}
public ushort GetCntInType(out uint CntInType)
{
CntInType = 0;
if (IsSimul) { return E1.OK; }
return _Trigger.GetCntInType(out CntInType);
}
}
}