614 lines
17 KiB
C#
614 lines
17 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using AuroraDeviceCommon;
|
|
using AuroraLaser.Coherent.Arm;
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AuroraLaser.Amplitude.Satsuma
|
|
{
|
|
public enum eLaserTrigger : int
|
|
{
|
|
INTERNAL,
|
|
EXTERNAL,
|
|
}
|
|
|
|
public enum eLaserGate : int
|
|
{
|
|
INTERNAL,
|
|
EXTERNAL,
|
|
}
|
|
|
|
public enum eLaserAlignment : int
|
|
{
|
|
NO,
|
|
YES,
|
|
}
|
|
|
|
|
|
public enum eLaserTransmission : int
|
|
{
|
|
Software,
|
|
AnalogInput,
|
|
}
|
|
|
|
public enum eLaserPowerTransmission : int
|
|
{
|
|
RF_POWER,
|
|
LASER_POWER_TRANS,
|
|
LASER_POWER,
|
|
}
|
|
|
|
public class LaserDeviceSatsumaDisplay : ModbusDevice, ILaserDeviceAmplitude
|
|
{
|
|
Logger Log = new Logger("LaserDeviceSatsumaDisplay");
|
|
|
|
public enum e_COIL_INPUT
|
|
{
|
|
e_SYSTEM_STOP,
|
|
e_LASER_ON_STANDBY,
|
|
e_PULSE_PICKER_TRIGGER_SYNC,
|
|
e_EXTERNAL_MODULATOR_TRIGGER_SYNC,
|
|
e_EXTERNAL_MODULATOR_GATE_SYNC,
|
|
e_PULSE_PICKER_ALIGNMENT_SYNC,
|
|
e_EXTERNAL_MODULATOR_ALIGNMENT_SYNC,
|
|
e_EXTERNAL_MODULATOR_EFFICIENCY_MODE,
|
|
e_COMPRESSOR_MODE,
|
|
e_MAX,
|
|
}
|
|
|
|
public enum e_DISCRETE_INPUT
|
|
{
|
|
e_OSCILLATOR_READY,
|
|
e_INTERLOCK,
|
|
e_KEY,
|
|
e_MODE_LOCK,
|
|
e_FRONT_END_READY,
|
|
e_SHUTTER,
|
|
e_MAX,
|
|
}
|
|
|
|
public enum e_HOLDING_REGISTER
|
|
{
|
|
e_RESET,
|
|
e_AMPLIFIER_LD_SET_CURRENT,
|
|
e_BURST_MODE,
|
|
e_PULSE_PICKER_FREQUENCY_SET,
|
|
e_EXTERNAL_MODULATOR_WIDTH,
|
|
e_EXTERNAL_MODULATOR_DELAY,
|
|
e_EXTERNAL_MODULATOR_FREQUENCY_SET,
|
|
e_EXTERNAL_MODULATOR_EFFICIENCY,
|
|
|
|
e_MAX = 11,
|
|
}
|
|
|
|
public enum e_INPUT_REGISTER
|
|
{
|
|
e_DIODE_AMPLIFIER_RUNTIME,
|
|
e_OSCILLATOR_LD_CURRENT,
|
|
e_OSCILLATOR_LD_TEMP,
|
|
e_OSCILLATOR_LD_POWER,
|
|
|
|
e_PREAMP1_LD_CURRENT,
|
|
e_PREAMP1_LD_TEMP,
|
|
e_PREAMP1_LD_POWER,
|
|
|
|
e_AMPLIFIER_LD_CURRENT,
|
|
e_AMPLIFIER_LD_POWER,
|
|
e_AMPLIFIER_LD_TEMP,
|
|
|
|
e_PULSE_PICKER_FREQUENCY,
|
|
e_EXTERNAL_MODULATOR_FREQUENCY,
|
|
|
|
e_OUTPUPT_POWER = 12,
|
|
|
|
e_MAX = 19,
|
|
}
|
|
|
|
bool[] m_bCoilInputs = new bool[(int)e_COIL_INPUT.e_MAX];
|
|
int[] m_bCoilInputs_For_Write = new int[(int)e_COIL_INPUT.e_MAX] { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
|
|
|
|
|
bool[] m_bDiscreteInputs = new bool[(int)e_DISCRETE_INPUT.e_MAX];
|
|
ushort[] m_usHoldingRegisteres = new ushort[(int)e_HOLDING_REGISTER.e_MAX];
|
|
short[] m_usHoldingRegisteres_For_Write = new short[(int)e_HOLDING_REGISTER.e_MAX] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
|
ushort[] m_usInputRegisteres = new ushort[(int)e_INPUT_REGISTER.e_MAX];
|
|
|
|
public bool[] CoilInputs {
|
|
get { return m_bCoilInputs; }
|
|
set { m_bCoilInputs = value; }
|
|
}
|
|
|
|
public int[] CoilInputs_For_Write {
|
|
get { return m_bCoilInputs_For_Write; }
|
|
set { m_bCoilInputs_For_Write = value; }
|
|
}
|
|
|
|
public bool[] DiscreteInputs {
|
|
get { return m_bDiscreteInputs; }
|
|
set { m_bDiscreteInputs = value; }
|
|
}
|
|
|
|
public ushort[] HoldingRegisteres {
|
|
get { return m_usHoldingRegisteres; }
|
|
set { m_usHoldingRegisteres = value; }
|
|
}
|
|
|
|
public short[] HoldingRegisteres_For_Write {
|
|
get { return m_usHoldingRegisteres_For_Write; }
|
|
set { m_usHoldingRegisteres_For_Write = value; }
|
|
}
|
|
|
|
public ushort[] InputRegisteres {
|
|
get { return m_usInputRegisteres; }
|
|
set { m_usInputRegisteres = value; }
|
|
}
|
|
|
|
private bool IsRunning = false;
|
|
public int RetryCount = 0;
|
|
private object m_SyncLock = new object();
|
|
private int MaxCount;
|
|
public LaserSatsumaConfig Config { get; set; }
|
|
|
|
public LaserDeviceSatsumaDisplay(string deviceId) : base(deviceId)
|
|
{
|
|
DeviceId = deviceId;
|
|
CommType = CommunicationType.ModbusTCP;
|
|
}
|
|
|
|
protected override int DoActivate(IDeviceConfig config)
|
|
{
|
|
Config = (config as LaserSatsumaConfig);
|
|
return ActivateDevice();
|
|
|
|
//if (IsActivated) {
|
|
// return E1.OK;
|
|
//}
|
|
|
|
//var satsumaConfig = (config as LaserSatsumaConfig);
|
|
//MaxCount = satsumaConfig.RetryCount;
|
|
|
|
//if (IsSimul) {
|
|
// return E1.OK;
|
|
//}
|
|
|
|
//var res = base.DoActivate(config);
|
|
//if (res == E1.OK) {
|
|
// RunMonitor(satsumaConfig.ScanIntervalMS);
|
|
//} else {
|
|
// IsCommError = true;
|
|
//}
|
|
|
|
//return res;
|
|
}
|
|
|
|
protected override int DoDeactivate()
|
|
{
|
|
return DeactivateDevice();
|
|
|
|
//IsRunning = false;
|
|
|
|
//if (!IsActivated || IsSimul) {
|
|
// return E1.OK;
|
|
//}
|
|
|
|
//return base.DoDeactivate();
|
|
}
|
|
|
|
public int ActivateDevice()
|
|
{
|
|
if (IsActivated || IsActivated_InAllLaserDevice) {
|
|
return E1.OK;
|
|
}
|
|
|
|
MaxCount = Config.RetryCount;
|
|
|
|
if (IsSimul) {
|
|
return E1.OK;
|
|
}
|
|
|
|
var res = base.DoActivate(Config);
|
|
if (res == E1.OK) {
|
|
RunMonitor(Config.ScanIntervalMS);
|
|
} else {
|
|
IsCommError = true;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
public int DeactivateDevice()
|
|
{
|
|
IsRunning = false;
|
|
|
|
if (IsSimul) {
|
|
return E1.OK;
|
|
}
|
|
if (!IsActivated && !IsActivated_InAllLaserDevice) {
|
|
return E1.OK;
|
|
}
|
|
|
|
return base.DoDeactivate();
|
|
}
|
|
|
|
public void StopMonitor()
|
|
{
|
|
IsRunning = false;
|
|
}
|
|
|
|
public void RunMonitor(int scanIntervalMS)
|
|
{
|
|
IsRunning = true;
|
|
// 실시간 update
|
|
Task.Run(() => {
|
|
|
|
while (IsActivated && IsRunning && !IsCommError) {
|
|
int res = E1.OK;
|
|
|
|
res |= ModbusTcpMasterRead();
|
|
res |= ModbusTcpMasterWrite();
|
|
|
|
if (res != E1.OK) {
|
|
RetryCount++;
|
|
} else {
|
|
RetryCount = 0;
|
|
}
|
|
|
|
CheckRetryCount();
|
|
Thread.Sleep(scanIntervalMS);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void CheckRetryCount()
|
|
{
|
|
if (MaxCount < RetryCount) {
|
|
IsCommError = true;
|
|
} else {
|
|
IsCommError = false;
|
|
}
|
|
}
|
|
|
|
private int ModbusTcpMasterRead()
|
|
{
|
|
int res = E1.OK;
|
|
|
|
// Read Coil
|
|
var bCoilInput = ReadBitBlock(0, (int)e_COIL_INPUT.e_MAX);
|
|
lock (m_SyncLock) {
|
|
Buffer.BlockCopy(bCoilInput.bits, 0, m_bCoilInputs, 0, (int)e_COIL_INPUT.e_MAX);
|
|
}
|
|
res |= bCoilInput.err;
|
|
|
|
// Read Discrete Input
|
|
var bDiscreteInput = ReadInputBitBlock(0, (int)e_DISCRETE_INPUT.e_MAX);
|
|
if (bDiscreteInput.err == E1.OK) {
|
|
Buffer.BlockCopy(bDiscreteInput.bits, 0, m_bDiscreteInputs, 0, (int)e_DISCRETE_INPUT.e_MAX);
|
|
}
|
|
res |= bDiscreteInput.err;
|
|
|
|
// Read Holding Register
|
|
var usHoldingRegister = ReadWordBlock(0, (int)e_HOLDING_REGISTER.e_MAX);
|
|
lock (m_SyncLock) {
|
|
Buffer.BlockCopy(usHoldingRegister.words, 0, m_usHoldingRegisteres, 0, (int)e_HOLDING_REGISTER.e_MAX * 2);
|
|
}
|
|
res |= usHoldingRegister.err;
|
|
|
|
// Read Input Register
|
|
var usInputRegister = ReadInputWordBlock(0, (int)e_INPUT_REGISTER.e_MAX);
|
|
lock (m_SyncLock) {
|
|
Buffer.BlockCopy(usInputRegister.words, 0, m_usInputRegisteres, 0, (int)e_INPUT_REGISTER.e_MAX * 2);
|
|
}
|
|
res |= usHoldingRegister.err;
|
|
|
|
return res;
|
|
}
|
|
|
|
private int ModbusTcpMasterWrite()
|
|
{
|
|
int res = E1.OK;
|
|
for (int i = 0; i < (int)e_COIL_INPUT.e_MAX; i++) {
|
|
if (CoilInputs_For_Write[i] != -1) {
|
|
if (CoilInputs_For_Write[i] == 0) {
|
|
res |= WriteBit((ushort)i, CoilInputs_For_Write[i] == 1);
|
|
}
|
|
CoilInputs_For_Write[i] = -1;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < (int)e_HOLDING_REGISTER.e_MAX; i++) {
|
|
if (m_usHoldingRegisteres_For_Write[i] != -1) {
|
|
res |= WriteWord((ushort)i, m_usHoldingRegisteres_For_Write[i]);
|
|
m_usHoldingRegisteres_For_Write[i] = -1;
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
public void SetPulsePickerAlignment(eLaserAlignment eAlignment)
|
|
{
|
|
if (eAlignment == eLaserAlignment.NO) {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_PULSE_PICKER_ALIGNMENT_SYNC] = 0;
|
|
} else {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_PULSE_PICKER_ALIGNMENT_SYNC] = 1;
|
|
}
|
|
}
|
|
|
|
public void SetTrigger(eLaserTrigger eTrigger)
|
|
{
|
|
if (eTrigger == eLaserTrigger.EXTERNAL) {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_TRIGGER_SYNC] = 0;
|
|
} else {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_TRIGGER_SYNC] = 1;
|
|
}
|
|
}
|
|
|
|
public void SetPulsePickerTrigger(eLaserTrigger eTrigger)
|
|
{
|
|
if (eTrigger == eLaserTrigger.EXTERNAL) {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_PULSE_PICKER_TRIGGER_SYNC] = 0;
|
|
} else {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_PULSE_PICKER_TRIGGER_SYNC] = 1;
|
|
}
|
|
}
|
|
|
|
public void SetGate(eLaserGate eGate)
|
|
{
|
|
if (eGate == eLaserGate.EXTERNAL) {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_GATE_SYNC] = 0;
|
|
} else {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_GATE_SYNC] = 1;
|
|
}
|
|
}
|
|
|
|
public void SetAlignment(eLaserAlignment eAlignment)
|
|
{
|
|
if (eAlignment == eLaserAlignment.NO) {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_ALIGNMENT_SYNC] = 0;
|
|
} else {
|
|
CoilInputs_For_Write[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_ALIGNMENT_SYNC] = 1;
|
|
}
|
|
}
|
|
|
|
public int SetWidth(short usValue)
|
|
{
|
|
HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_WIDTH] = usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public int SetDelay(short usValue)
|
|
{
|
|
HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_DELAY] = usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public int SetFrequency(short usValue)
|
|
{
|
|
HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_FREQUENCY_SET] = usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public int SetPulsePickerFrequencyMin(ushort usValue)
|
|
{
|
|
//HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_FREQUENCY_SET] = usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public int SetTransmissionPercent(ushort usValue)
|
|
{
|
|
HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_EFFICIENCY] = (short)usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public int SetPulsePickerFrequency(short usValue)
|
|
{
|
|
HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_PULSE_PICKER_FREQUENCY_SET] = usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public int SetBurstMode(short usValue)
|
|
{
|
|
HoldingRegisteres_For_Write[(int)e_HOLDING_REGISTER.e_BURST_MODE] = usValue;
|
|
|
|
return 1;
|
|
}
|
|
|
|
public ushort GetPulsePickerFrequency()
|
|
{
|
|
return HoldingRegisteres[(int)e_HOLDING_REGISTER.e_PULSE_PICKER_FREQUENCY_SET];
|
|
}
|
|
|
|
public bool GetPulsePickerTrigger()
|
|
{
|
|
return CoilInputs[(int)e_COIL_INPUT.e_PULSE_PICKER_TRIGGER_SYNC];
|
|
}
|
|
|
|
public bool GetPulsePickerAlignment()
|
|
{
|
|
return CoilInputs[(int)e_COIL_INPUT.e_PULSE_PICKER_ALIGNMENT_SYNC];
|
|
}
|
|
|
|
public ushort GetBurstMode()
|
|
{
|
|
return HoldingRegisteres[(int)e_HOLDING_REGISTER.e_BURST_MODE];
|
|
}
|
|
|
|
public ushort GetWidth()
|
|
{
|
|
return HoldingRegisteres[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_WIDTH];
|
|
}
|
|
|
|
public ushort GetDelay()
|
|
{
|
|
return HoldingRegisteres[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_DELAY];
|
|
}
|
|
|
|
public ushort GetFrequency()
|
|
{
|
|
return HoldingRegisteres[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_FREQUENCY_SET];
|
|
}
|
|
|
|
public bool GetTrigger()
|
|
{
|
|
return CoilInputs[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_TRIGGER_SYNC];
|
|
}
|
|
|
|
public bool GetGate()
|
|
{
|
|
return CoilInputs[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_GATE_SYNC];
|
|
}
|
|
|
|
public bool GetAlignment()
|
|
{
|
|
return CoilInputs[(int)e_COIL_INPUT.e_EXTERNAL_MODULATOR_ALIGNMENT_SYNC];
|
|
}
|
|
|
|
public ushort GetTransmissionPercent()
|
|
{
|
|
return HoldingRegisteres[(int)e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_EFFICIENCY];
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Laser Interface 추가
|
|
|
|
// All LaserDevice 에서 선택하여 Device 가 생성될 때 사용되며, All LaserDevice 가 Activated 일 때만 true 가 됨.
|
|
public bool IsActivated_InAllLaserDevice = false;
|
|
private bool CanCallLaserFunction()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int LaserOn()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int LaserOff()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int PilotLaserOn()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int PilotLaserOff()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool GetPilotLaserStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool GetLaserReady()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool GetPilotLaserSetBitStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool GetConnected()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int SetData(int nTarget, int value)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int ResetLaser()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
public string GetControlMode()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
public bool GetControlModeSetStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public bool GetEmissionStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public bool GetEStop()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public bool GetInitCommunication()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
public bool GetLaserError()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public bool GetLaserResetSetBitStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public bool GetLaserStartSetBitStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public string GetPowerCenter()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
public string GetPowerRing()
|
|
{
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
public bool GetStartLaserSetBitStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool GetWarningStatus()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
public bool GetLaserInterlock()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|