using System;
|
using System.Collections;
|
using log4net;
|
using System.Threading;
|
|
namespace SA_LTT.Module
|
{
|
#region Enum
|
public enum SourcesType
|
{
|
INT,
|
EXT,
|
}
|
|
public enum TemperaturePointType
|
{
|
SHG = 0x00,
|
THG = 0x01,
|
LD1 = 0x02,
|
LD2 = 0x03,
|
LD3 = 0x04,
|
}
|
|
public enum BurstFiringModeType
|
{
|
Continuous = 0x00,
|
SingleShot = 0x01
|
}
|
|
public enum BurstTriggerSourceType
|
{
|
Command = 0x00,
|
Gate = 0x01,
|
}
|
|
public enum DutyControlModeType
|
{
|
Fixed = 0x00,
|
Track = 0x01,
|
}
|
#endregion
|
|
// Laser Set Current, Gate Source 말고는 다 고정값으로 사용함.
|
// 나머지는 사용 못하게 막으면됨. UI는 상태값만 표시.
|
/// <summary>
|
/// Company : Photonics Industries International, Inc.
|
/// Site : www.Photonix.com.
|
/// PI laser control class.
|
/// </summary>
|
public class PiLaser : ComPort
|
{
|
#region Enum
|
public enum WriteCommand
|
{
|
EnableShutter = 0x04,
|
SystemReset = 0x07,
|
EnableLDD = 0x10,
|
SetCurrent = 0x11,
|
MaxCurrent = 0x14,
|
PRF = 0x21,
|
PRFSource = 0x23,
|
GateSource = 0x24,
|
PECSource = 0x25,
|
FPKEnable = 0x27,
|
FPKRampTime = 0x28,
|
FPKRampRate = 0x29,
|
LPKEnable = 0x2B,
|
LPKRampTime = 0x2C,
|
LPKRampRate = 0x2D,
|
TemperatureSetPoint = 0x31,
|
DutyControl = 0x53,
|
DutyControlWidth = 0x54,
|
PECLevel = 0x55,
|
BurstStatus = 0x56,
|
BurstCount = 0x57,
|
BurstRate = 0x58,
|
BurstCycles = 0x59,
|
BurstFiringMode = 0x67,
|
BurstTriggerSource = 0x68,
|
DutyControlMode = 0x69,
|
}
|
|
public enum ReadCommand
|
{
|
EnableShutter = 0x04,
|
ReadSoftFaults = 0x0C,
|
ReadBoardFaults = 0x0D,
|
ReadStatus = 0x0F,
|
EnableLDD = 0x10,
|
SetCurrent = 0x11,
|
ReadActualCurrent = 0x12,
|
ReadDiodeVoltage = 0x13,
|
MaxCurrent = 0x14,
|
LDDHours = 0x15,
|
PRF = 0x21,
|
PRFSource = 0x23,
|
GateSource = 0x24,
|
PECSource = 0x25,
|
FPKEnable = 0x27,
|
FPKRampTime = 0x28,
|
FPKRampRate = 0x29,
|
LPKEnable = 0x2B,
|
LPKRampTime = 0x2C,
|
LPKRampRate = 0x2D,
|
TemperatureSetPoint = 0x31,
|
ActualTemperature = 0x32,
|
DutyControl = 0x53,
|
DutyControlWidth = 0x54,
|
PECLevel = 0x55,
|
BurstStatus = 0x56,
|
BurstCount = 0x57,
|
BurstRate = 0x58,
|
BurstCycles = 0x59,
|
BurstFiringMode = 0x67,
|
BurstTriggerSource = 0x68,
|
DutyControlMode = 0x69,
|
PowerMonitorReading = 0x71,
|
FlowReading = 0x74,
|
HumidityReading = 0x76,
|
NetworkAddress = 0x98,
|
}
|
#endregion
|
|
#region Property
|
/// <summary>
|
/// Current pi laser status.
|
/// </summary>
|
public PiLaserStatus CurrentPiLaserStatus
|
{
|
get
|
{
|
return _currentPiLaserStatus;
|
}
|
|
private set
|
{
|
_currentPiLaserStatus = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private ILog _piLaserLogger = LogManager.GetLogger("PiLaser");
|
private IEnumerator _piLaserReadCommands;
|
|
private PiLaserStatus _currentPiLaserStatus;
|
|
private Equipment _equipment;
|
private Thread t_statusUpdate;
|
private object _lockObject;
|
private bool _isLock;
|
#endregion
|
|
#region Construct
|
public PiLaser(Equipment equipment)
|
{
|
serialPort.PortName = "COM12";
|
serialPort.BaudRate = 115200;
|
serialPort.Parity = System.IO.Ports.Parity.None;
|
serialPort.DataBits = 8;
|
serialPort.StopBits = System.IO.Ports.StopBits.One;
|
Terminator = "\r";
|
|
_equipment = equipment;
|
|
_lockObject = new object();
|
_currentPiLaserStatus = new PiLaserStatus();
|
|
t_statusUpdate = new Thread(statusUpdate);
|
t_statusUpdate.Start();
|
}
|
#endregion
|
|
#region Function
|
public void statusUpdate()
|
{
|
while (_equipment.IsDisposed == false)
|
{
|
try
|
{
|
Thread.Sleep(10);
|
|
if (IsOpen)
|
{
|
if (_piLaserReadCommands == null || !_piLaserReadCommands.MoveNext())
|
{
|
_piLaserReadCommands = PiLaserReads();
|
}
|
else
|
{
|
bool value = (bool)_piLaserReadCommands.Current;
|
|
if (value == false)
|
{
|
// Alarm : Communication Alarm.
|
}
|
}
|
}
|
else
|
{
|
// Interlock : Connection Alarm 발생시 동작 안되도록 변경.
|
if (!Open())
|
{
|
// Alarm : Connection Alarm.
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
EquipmentLogManager.Instance.WriteExceptionLog(e.StackTrace);
|
}
|
}
|
}
|
|
private void CheckSoftFaults()
|
{
|
|
if (CurrentPiLaserStatus.CurrentSoftFaults.HfSync)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0100_LASER_SOFT_FAULT_HFSYNC);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSoftFaults.LddInterlock)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0101_LASER_SOFT_FAULT_LDD_INTERLOCK);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSoftFaults.ShutterInterlock)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0102_LASER_SOFT_FAULT_SHUTTER_INTERLOCK);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSoftFaults.LowExtFrequency)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0103_LASER_SOFT_FAULT_LOW_EXT_FREQUENCY);
|
}
|
}
|
|
private void CheckBoardFaults()
|
{
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Main)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0103_LASER_SOFT_FAULT_LOW_EXT_FREQUENCY);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Common)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0105_LASER_BOARD_FAULT_COMMON);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Temperature)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0106_LASER_BOARD_FAULT_TEMPERATURE);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Sensor)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0107_LASER_BOARD_FAULT_SENSOR);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.PowerMonitor)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0108_LASER_BOARD_FAULT_POWER_MONITOR);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Pulse)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0109_LASER_BOARD_FAULT_PULSE);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Ldd)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0110_LASER_BOARD_FAULT_LDD);
|
}
|
|
if (CurrentPiLaserStatus.CurrentBoardFaults.Motor)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0111_LASER_BOARD_FAULT_MOTOR);
|
}
|
}
|
|
private void CheckSystemFaults()
|
{
|
if (CurrentPiLaserStatus.CurrentSystemFaults.Memory)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0112_LASER_SYSTEM_FAULT_MEMORY);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSystemFaults.SdCard)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0113_LASER_SYSTEM_FAULT_SDCARD);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSystemFaults.BoardCommunication)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0114_LASER_SYSTEM_FAULT_BOARD_COMMUNICATION);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSystemFaults.BoardState)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0115_LASER_SYSTEM_FAULT_BOARD_STATE);
|
}
|
}
|
|
private void CheckGeneralAlarms()
|
{
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.Ldd1)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0116_LASER_GENERAL_ALARM_LDD1);
|
}
|
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.Ldd2)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0117_LASER_GENERAL_ALARM_LDD2);
|
}
|
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.Qsw)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0118_LASER_GENERAL_ALARM_QSW);
|
}
|
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.Flow)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0119_LASER_GENERAL_ALARM_FLOW);
|
}
|
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.Wet)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0120_LASER_GENERAL_ALARM_WET);
|
}
|
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.Humidity)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0121_LASER_GENERAL_ALARM_HUMIDITY);
|
}
|
|
if (CurrentPiLaserStatus.CurrentGeneralAlarms.HfSync)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0122_LASER_GENERAL_ALARM_HFSYNC);
|
}
|
}
|
|
private void CheckTemperatureFaults()
|
{
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault0)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0123_LASER_TEMPERATURE_FAULT_0);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault1)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0124_LASER_TEMPERATURE_FAULT_1);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault2)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0125_LASER_TEMPERATURE_FAULT_2);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault3)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0126_LASER_TEMPERATURE_FAULT_3);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault4)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0127_LASER_TEMPERATURE_FAULT_4);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault5)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0128_LASER_TEMPERATURE_FAULT_5);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault6)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0129_LASER_TEMPERATURE_FAULT_6);
|
}
|
|
if (CurrentPiLaserStatus.CurrentTemperatureControlFaults.TemperatureControlFault7)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0130_LASER_TEMPERATURE_FAULT_7);
|
}
|
}
|
|
private void CheckSystemStateFaults()
|
{
|
if(CurrentPiLaserStatus.CurrentSystemState.SoftFault)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0131_LASER_SOFT_FAULT);
|
}
|
|
if (CurrentPiLaserStatus.CurrentSystemState.HardFault)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0132_LASER_HARD_FAULT);
|
}
|
}
|
|
//=============================== Write ==========================================
|
/// <summary>
|
/// Write enable shutter.
|
/// </summary>
|
/// <param name="enable">true : Enable, false : Disable</param>
|
/// <returns></returns>
|
public bool WriteEnableShutter(bool enable)
|
{
|
if (_equipment.piLaser.CurrentPiLaserStatus.EnableShutter && enable == false)
|
{
|
if (_equipment.piLaser.CurrentPiLaserStatus.SetCurrent > 0)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0080_SET_CURRENT_IS_NOT_ZERO);
|
return false;
|
}
|
}
|
|
var bytesData = new byte[1];
|
|
if (enable)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.EnableShutter, bytesData);
|
}
|
|
/// <summary>
|
/// System reset.
|
/// </summary>
|
/// <returns></returns>
|
public bool WriteSystemReset()
|
{
|
return WriteData(WriteCommand.SystemReset);
|
}
|
|
/// <summary>
|
/// Write enable laser diode driver.
|
/// </summary>
|
/// <param name="enable">true : Enable, false : Disable</param>
|
/// <returns></returns>
|
public bool WriteEnableLdd(bool enable)
|
{
|
if (_equipment.piLaser.CurrentPiLaserStatus.EnableLdd && enable == false)
|
{
|
if (_equipment.piLaser.CurrentPiLaserStatus.SetCurrent > 0)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0080_SET_CURRENT_IS_NOT_ZERO);
|
return false;
|
}
|
}
|
|
var bytesData = new byte[1];
|
|
if (enable)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.EnableLDD, bytesData);
|
}
|
|
/// <summary>
|
/// Write set current.
|
/// </summary>
|
/// <param name="ampere"> 0 - 100 (A)</param>
|
public bool WriteSetCurrent(double ampere)
|
{
|
if (CurrentPiLaserStatus.CurrentSystemStatus.LddOn == false)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0078_LDD_IS_NOT_ON);
|
return false;
|
}
|
|
if (CurrentPiLaserStatus.CurrentSystemStatus.ShutterEnabled == false)
|
{
|
_equipment.alarmManager.Occur(AlarmCode.AL_0079_SHUTTER_IS_NOT_OPEN);
|
return false;
|
}
|
|
//Unit : 0.01A
|
ampere = ampere * 100;
|
|
if (ampere > 10000) ampere = 10000;
|
else if (ampere < 0) ampere = 0;
|
|
var ushortAmpere = ushort.Parse(ampere.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortAmpere);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.SetCurrent, bytesData);
|
}
|
|
/// <summary>
|
/// Write max current.
|
/// </summary>
|
/// <param name="ampere"> 0 - 100 (A)</param>
|
public bool WriteMaxCurrent(double ampere)
|
{
|
//Unit : 0.01A
|
ampere = ampere * 100;
|
|
if (ampere > 10000) ampere = 10000;
|
else if (ampere < 0) ampere = 0;
|
|
var ushortAmpere = ushort.Parse(ampere.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortAmpere);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.MaxCurrent, bytesData);
|
}
|
|
/// <summary>
|
/// Write pulse repetition frequency.
|
/// </summary>
|
/// <param name="hz"> 0 - 1000000 Hz</param>
|
public bool WritePrf(int pulseRepetitionFrequency)
|
{
|
if (pulseRepetitionFrequency > 1000000) pulseRepetitionFrequency = 1000000;
|
else if (pulseRepetitionFrequency < 0) pulseRepetitionFrequency = 0;
|
|
var bytesData = new byte[3];
|
|
var bytesPulseRepetitionFrequency = BitConverter.GetBytes(pulseRepetitionFrequency);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesPulseRepetitionFrequency);
|
|
bytesData[0] = bytesPulseRepetitionFrequency[1];
|
bytesData[1] = bytesPulseRepetitionFrequency[2];
|
bytesData[2] = bytesPulseRepetitionFrequency[3];
|
|
return WriteData(WriteCommand.PRF, bytesData);
|
}
|
|
/// <summary>
|
/// Write pulse repetition frequency source.
|
/// </summary>
|
/// <param name="source">Source type</param>
|
/// <returns></returns>
|
public bool WritePrfSource(SourcesType source)
|
{
|
var bytesData = new byte[1];
|
|
if (source == SourcesType.EXT)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.PRFSource, bytesData);
|
}
|
|
/// <summary>
|
/// Write gate source.
|
/// </summary>
|
/// <param name="source">Source type</param>
|
/// <returns></returns>
|
public bool WriteGateSource(SourcesType source)
|
{
|
var bytesData = new byte[1];
|
|
if (source == SourcesType.EXT)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.GateSource, bytesData);
|
}
|
|
/// <summary>
|
/// Write pulse energy control source.
|
/// </summary>
|
/// <param name="source">Source type</param>
|
/// <returns></returns>
|
public bool WritePecSource(SourcesType source)
|
{
|
var bytesData = new byte[1];
|
|
if (source == SourcesType.EXT)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.PECSource, bytesData);
|
}
|
|
/// <summary>
|
/// Write first pulse kill enable.
|
/// </summary>
|
/// <param name="enable">true : Enable, false : Disable</param>
|
/// <returns></returns>
|
public bool WriteFpkEnable(bool enable)
|
{
|
var bytesData = new byte[1];
|
|
if (enable)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.FPKEnable, bytesData);
|
}
|
|
/// <summary>
|
/// Write first pulse kill ramp time.
|
/// </summary>
|
/// <param name="rampTime"> 0 - 655350 (ns)</param>
|
public bool WriteFpkRampTime(int rampTime)
|
{
|
//Units : 10ns
|
rampTime = (int)(rampTime * 0.1);
|
|
if (rampTime > 65535) rampTime = 65535;
|
else if (rampTime < 0) rampTime = 0;
|
|
var ushortRampTime = ushort.Parse(rampTime.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortRampTime);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.FPKRampTime, bytesData);
|
}
|
|
/// <summary>
|
/// Write first pulse kill ramp rate.
|
/// </summary>
|
/// <param name="rampRate"> 0 - 6553500 (ns)</param>
|
public bool WriteFpkRampRate(int rampRate)
|
{
|
//Units : 100ns
|
rampRate = (int)(rampRate * 0.01);
|
|
if (rampRate > 65535) rampRate = 65535;
|
else if (rampRate < 0) rampRate = 0;
|
|
var ushortRampRate = ushort.Parse(rampRate.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortRampRate);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.FPKRampRate, bytesData);
|
}
|
|
/// <summary>
|
/// Write lpk enable.
|
/// </summary>
|
/// <param name="enable">true : Enable, false : Disable</param>
|
/// <returns></returns>
|
public bool WriteLpkEnable(bool enable)
|
{
|
byte[] bytesData = new byte[1];
|
|
if (enable)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.LPKEnable, bytesData);
|
}
|
|
/// <summary>
|
/// Write lpk ramp time.
|
/// </summary>
|
/// <param name="rampTime"> 0 - 655350 (ns)</param>
|
public bool WriteLpkRampTime(double rampTime)
|
{
|
//Units : 10ns.
|
rampTime = rampTime * 0.1f;
|
|
if (rampTime > 65535) rampTime = 65535;
|
else if (rampTime < 0) rampTime = 0;
|
|
var ushortRampTime = ushort.Parse(rampTime.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortRampTime);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.LPKRampTime, bytesData);
|
}
|
|
/// <summary>
|
/// Write lpk ramp rate.
|
/// </summary>
|
/// <param name="rampRate"> 0 - 6553500 (ns)</param>
|
public bool WriteLpkRampRate(int rampRate)
|
{
|
//Units : 100ns
|
rampRate = (int)(rampRate * 0.01);
|
|
if (rampRate > 65535) rampRate = 65535;
|
else if (rampRate < 0) rampRate = 0;
|
|
var ushortRampRate = ushort.Parse(rampRate.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortRampRate);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.LPKRampRate, bytesData);
|
}
|
|
/// <summary>
|
/// Write temperature set point.
|
/// </summary>
|
/// <param name="temperaturePoint">Temperature point</param>
|
/// <param name="temperature"> 0 - 160 ℃</param>
|
/// <returns></returns>
|
public bool WriteTemperatureSetPoint(TemperaturePointType temperaturePoint, double temperature)
|
{
|
//Units : 0.01℃
|
temperature = temperature * 100;
|
if (temperature > 16000) temperature = 16000;
|
else if (temperature < 0) temperature = 0;
|
|
var ushortTemperature = ushort.Parse(temperature.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortTemperature);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.TemperatureSetPoint, bytesData, (int)temperaturePoint);
|
}
|
|
/// <summary>
|
/// Write duty contorl.
|
/// </summary>
|
/// <param name="enable"> true : Enable, false : Disable </param>
|
/// <returns></returns>
|
public bool WriteDutyControl(bool enable)
|
{
|
var bytesData = new byte[1];
|
|
if (enable)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.DutyControl, bytesData);
|
}
|
|
/// <summary>
|
/// Write duty control width.
|
/// </summary>
|
/// <param name="dutyControlWidth">0 - (1/PRF - 0.1us)</param>
|
public bool WriteDutyControlWidth(double dutyControlWidth)
|
{
|
//Units : 0.1us
|
dutyControlWidth = dutyControlWidth * 10;
|
|
if (dutyControlWidth > 16777215) dutyControlWidth = 16777215;
|
else if (dutyControlWidth < 0) dutyControlWidth = 0;
|
|
var intDutyControlWidth = int.Parse(dutyControlWidth.ToString("F0"));
|
|
var bytesData = new byte[3];
|
|
var bytesDutyControlWidth = BitConverter.GetBytes(intDutyControlWidth);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesDutyControlWidth);
|
|
bytesData[0] = bytesDutyControlWidth[1];
|
bytesData[1] = bytesDutyControlWidth[2];
|
bytesData[2] = bytesDutyControlWidth[3];
|
|
return WriteData(WriteCommand.DutyControlWidth, bytesData);
|
}
|
|
/// <summary>
|
/// Write pulse energy control level.
|
/// </summary>
|
/// <param name="pecLevel">0 - 100%</param>
|
/// <returns></returns>
|
public bool WritePecLevel(double pulseEnergyControlLevel)
|
{
|
//Units : 0.1%
|
pulseEnergyControlLevel = pulseEnergyControlLevel * 10;
|
|
if (pulseEnergyControlLevel > 1000) pulseEnergyControlLevel = 1000;
|
else if (pulseEnergyControlLevel < 0) pulseEnergyControlLevel = 0;
|
|
var ushortPulseEnergyControlLevel = ushort.Parse(pulseEnergyControlLevel.ToString("F0"));
|
|
var bytesData = BitConverter.GetBytes(ushortPulseEnergyControlLevel);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.PECLevel, bytesData);
|
}
|
|
/// <summary>
|
/// Write burst status.
|
/// </summary>
|
/// <param name="burstStatus">true : Enable, false : Disable</param>
|
/// <returns></returns>
|
public bool WriteBurstStatus(bool burstStatus)
|
{
|
var bytesData = new byte[1];
|
|
if (burstStatus)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.BurstStatus, bytesData);
|
}
|
|
/// <summary>
|
/// Write burst count.
|
/// </summary>
|
/// <param name="burstCount">from 1 to (Burst Rate -1)</param>
|
public bool WriteBurstCount(ushort burstCount)
|
{
|
if (burstCount > 65535) burstCount = 65535;
|
else if (burstCount < 1) burstCount = 1;
|
|
var bytesData = BitConverter.GetBytes(burstCount);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.BurstCount, bytesData);
|
}
|
|
/// <summary>
|
/// Write burst rate.
|
/// </summary>
|
/// <param name="rate">from 1 to 65535</param>
|
public bool WriteBurstRate(ushort burstRate)
|
{
|
// integer divisor of PRF
|
if (burstRate > 65535) burstRate = 65535;
|
else if (burstRate < 1) burstRate = 1;
|
|
var bytesData = BitConverter.GetBytes(burstRate);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.BurstRate, bytesData);
|
}
|
|
/// <summary>
|
/// Write burst cycles.
|
/// </summary>
|
/// <param name="rate">from 1 to 65535 (number of bursts)</param>
|
public bool WriteBurstCycles(ushort burstCycles)
|
{
|
if (burstCycles > 65535) burstCycles = 65535;
|
else if (burstCycles < 1) burstCycles = 1;
|
|
var bytesData = BitConverter.GetBytes(burstCycles);
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
return WriteData(WriteCommand.BurstCycles, bytesData);
|
}
|
|
/// <summary>
|
/// Write burst firing mode.
|
/// </summary>
|
/// <param name="burstFiringMode">Brust firing mode</param>
|
/// <returns></returns>
|
public bool WriteBurstFiringMode(BurstFiringModeType burstFiringMode)
|
{
|
var bytesData = new byte[1];
|
|
if (burstFiringMode == BurstFiringModeType.SingleShot)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.BurstFiringMode, bytesData);
|
}
|
|
/// <summary>
|
/// Write burst trigger source.
|
/// </summary>
|
/// <param name="source">Burst trigger source</param>
|
/// <returns></returns>
|
public bool WriteBurstTriggerSource(BurstTriggerSourceType burstTriggerSource)
|
{
|
var bytesData = new byte[1];
|
|
if (burstTriggerSource == BurstTriggerSourceType.Gate)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.BurstTriggerSource, bytesData);
|
}
|
|
/// <summary>
|
/// Write duty control mode.
|
/// </summary>
|
/// <param name="dutyControlMode">Duty control mode</param>
|
/// <returns></returns>
|
public bool WriteDutyControlMode(DutyControlModeType dutyControlMode)
|
{
|
var bytesData = new byte[1];
|
|
if (dutyControlMode == DutyControlModeType.Track)
|
bytesData[0] = 0x01;
|
else
|
bytesData[0] = 0x00;
|
|
return WriteData(WriteCommand.DutyControlMode, bytesData);
|
}
|
|
//=============================== Read ==========================================
|
/// <summary>
|
/// Read enable shutter.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadEnableShutter()
|
{
|
var bytesData = ReadData(ReadCommand.EnableShutter);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.EnableShutter = bytesData[0] == 0x01;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read soft fauls.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadSoftFaults()
|
{
|
var bytesdata = ReadData(ReadCommand.ReadSoftFaults);
|
|
if (bytesdata == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.ChangeSoftFaults(bytesdata[1]);
|
CheckSoftFaults();
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read board faults.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBoardFaults()
|
{
|
var bytesData = ReadData(ReadCommand.ReadBoardFaults);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.ChangeBoardFaults(bytesData[1]);
|
CheckBoardFaults();
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read status.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadStatus()
|
{
|
var bytesData = ReadData(ReadCommand.ReadStatus);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.ChangeSystemStatus(bytesData[0]);
|
_currentPiLaserStatus.ChangeSystemFaults(bytesData[1]);
|
_currentPiLaserStatus.ChangeGeneralAlarms(bytesData[2]);
|
_currentPiLaserStatus.ChangeTemperatureControlFaults(bytesData[3]);
|
_currentPiLaserStatus.ChangeSystemState(bytesData[4]);
|
|
CheckSystemFaults();
|
CheckGeneralAlarms();
|
CheckTemperatureFaults();
|
CheckSystemStateFaults();
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read enable ldd.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadEnableLdd()
|
{
|
var bytesData = ReadData(ReadCommand.EnableLDD);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.EnableLdd = bytesData[0] == 0x01;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read set current.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadSetCurrent()
|
{
|
var bytesData = ReadData(ReadCommand.SetCurrent);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian)
|
Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.SetCurrent = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read actual current.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadActualCurrent()
|
{
|
var bytesData = ReadData(ReadCommand.ReadActualCurrent);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.ActualCurrent = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read diode voltage.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadDiodeVoltage()
|
{
|
var bytesData = ReadData(ReadCommand.ReadDiodeVoltage);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.DiodeVoltage = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read max current.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadMaxCurrent()
|
{
|
var bytesData = ReadData(ReadCommand.MaxCurrent);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.MaxCurrent = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read laser diode diver hours.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadLddHours()
|
{
|
var bytesData = ReadData(ReadCommand.LDDHours);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.LddHours = BitConverter.ToInt32(bytesData, 0) * 0.1f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read pulse repetition frequency.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadPrf()
|
{
|
var bytesData = ReadData(ReadCommand.PRF);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
var bytesPulseRepetitionFrequency = new byte[4];
|
|
bytesPulseRepetitionFrequency[0] = 0;
|
bytesPulseRepetitionFrequency[1] = bytesData[0];
|
bytesPulseRepetitionFrequency[2] = bytesData[1];
|
bytesPulseRepetitionFrequency[3] = bytesData[2];
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesPulseRepetitionFrequency);
|
|
_currentPiLaserStatus.Prf = BitConverter.ToInt32(bytesPulseRepetitionFrequency, 0);
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read pulse repetition frequency source.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadPRFSource()
|
{
|
var bytesData = ReadData(ReadCommand.PRFSource);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.PrfSource = bytesData[0] == 0x01 ? SourcesType.EXT : SourcesType.INT;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read gate source.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadGateSource()
|
{
|
var bytesData = ReadData(ReadCommand.GateSource);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.GateSource = bytesData[0] == 0x01 ? SourcesType.EXT : SourcesType.INT;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read pulse energy control source.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadPecSource()
|
{
|
var bytesData = ReadData(ReadCommand.PECSource);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.PecSource = bytesData[0] == 0x01 ? SourcesType.EXT : SourcesType.INT;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read first pulse kill enable.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadFPKEnable()
|
{
|
var data_bytes = ReadData(ReadCommand.FPKEnable);
|
|
if (data_bytes == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.FpkEnable = data_bytes[0] == 0x01;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read first pulse kill ramp time.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadFpkRampTime()
|
{
|
var bytesData = ReadData(ReadCommand.FPKRampTime);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.FpkRampTime = BitConverter.ToUInt16(bytesData, 0) * 10;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read first pulse kill ramp rate.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadFpkRampRate()
|
{
|
var bytesData = ReadData(ReadCommand.FPKRampRate);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.FpkRampRate = BitConverter.ToUInt16(bytesData, 0) * 100;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read lpk enable.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadLpkEnable()
|
{
|
var bytesData = ReadData(ReadCommand.LPKEnable);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.LpkEnable = bytesData[0] == 0x01;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read lpk ramp time.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadLpkRampTime()
|
{
|
var bytesData = ReadData(ReadCommand.LPKRampTime);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.LpkRampTime = BitConverter.ToUInt16(bytesData, 0) * 10;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read lpk ramp rate.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadLpkRampRate()
|
{
|
var bytesData = ReadData(ReadCommand.LPKRampRate);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.LpkRampRate = BitConverter.ToUInt16(bytesData, 0) * 100;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read temperature set point.
|
/// </summary>
|
/// <param name="temperaturePoint">Temperature point</param>
|
/// <returns></returns>
|
public bool ReadTemperatureSetPoint(TemperaturePointType temperaturePoint)
|
{
|
var bytesData = ReadData(ReadCommand.TemperatureSetPoint, (byte)temperaturePoint);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
if(temperaturePoint == TemperaturePointType.SHG)
|
_currentPiLaserStatus.ShgTemperatureSetPoint = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
if (temperaturePoint == TemperaturePointType.THG)
|
_currentPiLaserStatus.ThgTemperatureSetPoint = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
if (temperaturePoint == TemperaturePointType.LD1)
|
_currentPiLaserStatus.LdTemperatureSetPoint = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read actual temperature.
|
/// </summary>
|
/// <param name="temperaturePoint">Temperature point</param>
|
/// <returns></returns>
|
public bool ReadActualTemperature(TemperaturePointType temperaturePoint)
|
{
|
var bytesData = ReadData(ReadCommand.ActualTemperature, (byte)temperaturePoint);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
if (temperaturePoint == TemperaturePointType.SHG)
|
_currentPiLaserStatus.ShgActualTemperature = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
if (temperaturePoint == TemperaturePointType.THG)
|
_currentPiLaserStatus.ThgActualTemperature = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
if (temperaturePoint == TemperaturePointType.LD1)
|
_currentPiLaserStatus.LdActualTemperature = BitConverter.ToInt16(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read duty control.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadDutyControl()
|
{
|
var bytesData = ReadData(ReadCommand.DutyControl);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.DutyControl = bytesData[0] == 0x01;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read duty control width.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadDutyControlWidth()
|
{
|
var bytesData = ReadData(ReadCommand.DutyControlWidth);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
var bytesDutyControlWidth = new byte[4];
|
|
bytesDutyControlWidth[0] = 0;
|
bytesDutyControlWidth[1] = bytesData[0];
|
bytesDutyControlWidth[2] = bytesData[1];
|
bytesDutyControlWidth[3] = bytesData[2];
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesDutyControlWidth);
|
|
_currentPiLaserStatus.DutyControlWidth = BitConverter.ToInt32(bytesDutyControlWidth, 0) * 0.1f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read pulse energy control level.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadPecLevel()
|
{
|
var bytesData = ReadData(ReadCommand.PECLevel);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
if (bytesData.Length < 2)
|
{
|
|
}
|
else
|
{
|
_currentPiLaserStatus.PecLevel = BitConverter.ToInt16(bytesData, 0) * 0.1f;
|
}
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read burst status.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBurstStatus()
|
{
|
var bytesData = ReadData(ReadCommand.BurstStatus);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.BurstStatus = bytesData[0] == 0x01;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read burst count.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBurstCount()
|
{
|
var bytesData = ReadData(ReadCommand.BurstCount);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.BurstCount = BitConverter.ToUInt16(bytesData, 0);
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read burst rate.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBurstRate()
|
{
|
var bytesData = ReadData(ReadCommand.BurstRate);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.BurstRate = BitConverter.ToUInt16(bytesData, 0);
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read burst cycles.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBurstCycles()
|
{
|
var bytesData = ReadData(ReadCommand.BurstCycles);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.BurstCycles = BitConverter.ToUInt16(bytesData, 0);
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read burst firing mode.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBurstFiringMode()
|
{
|
var bytesData = ReadData(ReadCommand.BurstFiringMode);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.BurstFiringMode = bytesData[0] == 0x01 ? BurstFiringModeType.SingleShot : BurstFiringModeType.Continuous;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read burst trigger source.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadBurstTriggerSource()
|
{
|
var bytesData = ReadData(ReadCommand.BurstTriggerSource);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.BurstTriggerSource = bytesData[0] == 0x01 ? BurstTriggerSourceType.Gate : BurstTriggerSourceType.Command;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read duty control mode.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadDutyControlMode()
|
{
|
var bytesData = ReadData(ReadCommand.DutyControlMode);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
_currentPiLaserStatus.DutyControlMode = bytesData[0] == 0x01 ? DutyControlModeType.Fixed : DutyControlModeType.Track;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read power monitor reading.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadPowerMonitorReading()
|
{
|
var bytesData = ReadData(ReadCommand.PowerMonitorReading);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.PowerMonitorReading = BitConverter.ToInt32(bytesData, 0) * 0.01f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read flow reading.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadFlowReading()
|
{
|
var bytesData = ReadData(ReadCommand.FlowReading);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.FlowReading = BitConverter.ToUInt16(bytesData, 0) * 0.1f;
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read humidity reading.
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadHumidityReading()
|
{
|
var bytesData = ReadData(ReadCommand.HumidityReading);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.HumidityReading = BitConverter.ToUInt16(bytesData, 0);
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// Read network address
|
/// </summary>
|
/// <returns></returns>
|
public bool ReadNetworkAddress()
|
{
|
var bytesData = ReadData(ReadCommand.NetworkAddress);
|
|
if (bytesData == null)
|
{
|
return false;
|
}
|
else
|
{
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesData);
|
|
_currentPiLaserStatus.IpAddress = $"{bytesData[0]:D3}.{bytesData[1]:D3}.{bytesData[2]:D3}.{bytesData[3]:D3}";
|
_currentPiLaserStatus.SubnetMask = $"{bytesData[4]:D3}.{bytesData[5]:D3}.{bytesData[6]:D3}.{bytesData[7]:D3}";
|
_currentPiLaserStatus.Gateway = $"{bytesData[8]:D3}.{bytesData[9]:D3}.{bytesData[10]:D3}.{bytesData[11]:D3}";
|
return true;
|
}
|
}
|
|
//=============================== 데이터 전송 기본 함수 ==========================================
|
/// <summary>
|
/// 기존 데이터에 Checksum 추가하여 byte배열로 반환.
|
/// </summary>
|
/// <param name="data"></param>
|
/// <returns></returns>
|
private byte[] AddChecksum(byte[] data)
|
{
|
var bytesChecksum = new byte[data.Length + 2];
|
|
data.CopyTo(bytesChecksum, 0);
|
|
var checksum = new byte[2];
|
|
int sum = 0;
|
|
foreach(byte value in data)
|
{
|
sum = sum + value;
|
}
|
|
checksum[0] = (byte)(sum / 256);
|
checksum[1] = (byte)(sum % 256);
|
|
checksum.CopyTo(bytesChecksum, data.Length);
|
|
return bytesChecksum;
|
}
|
|
/// <summary>
|
/// 기존 데이터에 Checksum 추가하여 string 형태로 반환.
|
/// </summary>
|
/// <param name="data"></param>
|
/// <returns></returns>
|
private string AddChecksum(string data)
|
{
|
string strChecksum = string.Empty;
|
|
int byteLength = data.Length / 2;
|
|
var bytes = new byte[byteLength];
|
|
for(int i = 0; i < byteLength; i++)
|
{
|
bytes[i] = Convert.ToByte(data.Substring(i * 2, 2), 16);
|
}
|
|
var checksum_bytes = AddChecksum(bytes);
|
|
for(int i = 0; i < checksum_bytes.Length; i++)
|
{
|
strChecksum += $"{checksum_bytes[i]:X2}";
|
}
|
|
return strChecksum;
|
}
|
|
/// <summary>
|
/// Read 후 받은 데이터와 보낸 데이터의 Command가 일치하는지 확인.
|
/// </summary>
|
/// <param name="data"></param>
|
/// <param name="commands"></param>
|
/// <returns></returns>
|
private bool CheckCommand(byte data, Array commands)
|
{
|
foreach(var value in commands)
|
{
|
if(data == (int)value)
|
{
|
return true;
|
}
|
}
|
|
return false;
|
}
|
|
/// <summary>
|
/// Read후 받은 데이터의 Checksum이 정확한지 확인.
|
/// </summary>
|
/// <param name="datas"></param>
|
/// <returns></returns>
|
private bool CheckChecksum(byte[] datas)
|
{
|
int dataSum = 0;
|
int checksumSum = 0;
|
|
var bytesChecksum = new byte[4];
|
bytesChecksum[0] = 0;
|
bytesChecksum[1] = 0;
|
bytesChecksum[2] = datas[datas.Length - 2];
|
bytesChecksum[3] = datas[datas.Length - 1];
|
|
if (BitConverter.IsLittleEndian) Array.Reverse(bytesChecksum);
|
|
checksumSum = BitConverter.ToInt32(bytesChecksum, 0);
|
|
for(int i = 0; i < datas.Length - 2; i++)
|
{
|
dataSum += datas[i];
|
}
|
|
if(dataSum == checksumSum)
|
return true;
|
else
|
return false;
|
}
|
|
/// <summary>
|
/// Laser에 Read 명령어를 보낼 때 사용.
|
/// </summary>
|
/// <param name="command"></param>
|
/// <param name="addressCode"></param>
|
/// <returns></returns>
|
private byte[] ReadData(ReadCommand command, int addressCode = -1)
|
{
|
if (!IsOpen)
|
{
|
//SicLogger.WritePiLaserLog($"================ Pi laser ({PortName}) is not opened. ===============");
|
return null;
|
}
|
|
lock (_lockObject)
|
{
|
try
|
{
|
while (_isLock)
|
{
|
Monitor.Wait(_lockObject);
|
}
|
|
_isLock = true;
|
|
while ((DateTime.Now - checkDate).TotalSeconds < 0.1)
|
{
|
|
}
|
|
string strReceivedData = string.Empty;
|
|
string sendData;
|
|
if (addressCode == -1)
|
sendData = $"010000{(int)command:X2}";
|
else
|
sendData = $"0100{addressCode:X2}{(int)command:X2}";
|
|
sendData = AddChecksum(sendData) + "\r";
|
|
//SicLogger.WritePiLaserLog($"================ Read Data ===============");
|
//SicLogger.WritePiLaserLog($"[Send] >>> {sendData.Replace("\r", "")}");
|
|
var bytesReceivedData = WriteRead(sendData);
|
|
if (bytesReceivedData == null)
|
{
|
//SicLogger.WritePiLaserLog($"[Recv] <<< Recv is fail");
|
return null;
|
}
|
else
|
{
|
strReceivedData = bytesReceivedData.Replace("\r", "");
|
}
|
|
//SicLogger.WritePiLaserLog($"[Recv] <<< {strReceivedData}");
|
|
var bytesReceivedFormatData = new byte[strReceivedData.Length / 2];
|
|
for (int i = 0; i < bytesReceivedFormatData.Length; i++)
|
{
|
bytesReceivedFormatData[i] = Convert.ToByte(strReceivedData.Substring(i * 2, 2), 16);
|
}
|
|
if (!CheckCommand(bytesReceivedFormatData[3], Enum.GetValues(typeof(ReadCommand))))
|
{
|
//SicLogger.WritePiLaserLog($"Command is not exist.");
|
return null;
|
}
|
|
if (!CheckChecksum(bytesReceivedFormatData))
|
{
|
//SicLogger.WritePiLaserLog($"Checksum is fail");
|
return null;
|
}
|
|
var bytesData = new byte[bytesReceivedFormatData[1]];
|
|
for (int i = 0; i < bytesReceivedFormatData[1]; i++)
|
{
|
bytesData[i] = bytesReceivedFormatData[4 + i];
|
}
|
|
return bytesData;
|
}
|
catch(Exception e)
|
{
|
EquipmentLogManager.Instance.WriteExceptionLog(e.StackTrace);
|
return null;
|
}
|
finally
|
{
|
checkDate = DateTime.Now;
|
_isLock = false;
|
|
Monitor.Pulse(_lockObject);
|
}
|
}
|
}
|
|
/// <summary>
|
/// Laser에 Write 명령어를 보낼 때 사용.
|
/// </summary>
|
/// <param name="command"></param>
|
/// <param name="bytesData"></param>
|
/// <param name="addressCode"></param>
|
/// <returns></returns>
|
|
DateTime checkDate = DateTime.Now;
|
private bool WriteData(WriteCommand command, byte[] bytesData = null, int addressCode = -1)
|
{
|
if (!IsOpen)
|
{
|
//SicLogger.WritePiLaserLog($"================ Pi laser ({PortName}) is not opened. ===============");
|
return false;
|
}
|
|
lock (_lockObject)
|
{
|
try
|
{
|
while (_isLock)
|
{
|
Monitor.Wait(_lockObject);
|
}
|
|
_isLock = true;
|
|
while ((DateTime.Now - checkDate).TotalSeconds < 0.1)
|
{
|
|
}
|
|
string write_data;
|
|
if (bytesData == null)
|
{
|
if (addressCode == -1)
|
write_data = $"000000{(int)command:X2}";
|
else
|
write_data = $"0000{addressCode:X2}{(int)command:X2}";
|
}
|
else
|
{
|
if (addressCode == -1)
|
write_data = $"00{bytesData.Length:X2}00{(int)command:X2}";
|
else
|
write_data = $"00{bytesData.Length:X2}{addressCode:X2}{(int)command:X2}";
|
|
foreach (byte data in bytesData)
|
{
|
write_data += $"{data:X2}";
|
}
|
}
|
|
write_data = AddChecksum(write_data) + "\r";
|
|
//SicLogger.WritePiLaserLog($"================ Write Data ===============");
|
//SicLogger.WritePiLaserLog($"[Send] >>> {write_data.Replace("\r", "")}");
|
Write(write_data);
|
return true;
|
}
|
catch (Exception e)
|
{
|
EquipmentLogManager.Instance.WriteExceptionLog(e.StackTrace);
|
return false;
|
}
|
finally
|
{
|
checkDate = DateTime.Now;
|
_isLock = false;
|
Monitor.Pulse(_lockObject);
|
}
|
}
|
}
|
|
/// <summary>
|
/// Pi laser read method 순차적으로 불러우는 함수.
|
/// </summary>
|
/// <returns></returns>
|
public IEnumerator PiLaserReads()
|
{
|
yield return ReadStatus();
|
yield return ReadBoardFaults();
|
yield return ReadSoftFaults();
|
yield return ReadEnableShutter();
|
yield return ReadEnableLdd();
|
yield return ReadSetCurrent();
|
yield return ReadActualCurrent();
|
yield return ReadDiodeVoltage();
|
yield return ReadMaxCurrent();
|
yield return ReadLddHours();
|
yield return ReadPrf();
|
yield return ReadPRFSource();
|
yield return ReadGateSource();
|
yield return ReadPecSource();
|
yield return ReadFPKEnable();
|
yield return ReadFpkRampTime();
|
yield return ReadFpkRampRate();
|
yield return ReadLpkEnable();
|
yield return ReadLpkRampTime();
|
yield return ReadLpkRampRate();
|
yield return ReadTemperatureSetPoint(TemperaturePointType.SHG);
|
yield return ReadTemperatureSetPoint(TemperaturePointType.THG);
|
yield return ReadTemperatureSetPoint(TemperaturePointType.LD1);
|
yield return ReadActualTemperature(TemperaturePointType.SHG);
|
yield return ReadActualTemperature(TemperaturePointType.THG);
|
yield return ReadActualTemperature(TemperaturePointType.LD1);
|
yield return ReadDutyControl();
|
yield return ReadDutyControlWidth();
|
yield return ReadPecLevel();
|
yield return ReadBurstStatus();
|
yield return ReadBurstCount();
|
yield return ReadBurstRate();
|
yield return ReadBurstFiringMode();
|
yield return ReadBurstTriggerSource();
|
yield return ReadDutyControlMode();
|
yield return ReadPowerMonitorReading();
|
yield return ReadFlowReading();
|
yield return ReadHumidityReading();
|
//yield return _piLaser.ReadNetworkAddress();
|
}
|
#endregion
|
}
|
|
/// <summary>
|
/// Pi laser status.
|
/// </summary>
|
public class PiLaserStatus
|
{
|
#region Define
|
public struct SoftFaults
|
{
|
#region Property
|
public bool HfSync
|
{
|
get
|
{
|
return _hfSync;
|
}
|
|
set
|
{
|
_hfSync = value;
|
}
|
}
|
|
public bool LddInterlock
|
{
|
get
|
{
|
return _lddInterlock;
|
}
|
|
set
|
{
|
_lddInterlock = value;
|
}
|
}
|
|
public bool ShutterInterlock
|
{
|
get
|
{
|
return _shutterInterlock;
|
}
|
|
set
|
{
|
_shutterInterlock = value;
|
}
|
}
|
|
public bool LowExtFrequency
|
{
|
get
|
{
|
return _lowExtFrequency;
|
}
|
|
set
|
{
|
_lowExtFrequency = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _hfSync;
|
private bool _lddInterlock;
|
private bool _shutterInterlock;
|
private bool _lowExtFrequency;
|
#endregion
|
}
|
|
public struct BoardFaults
|
{
|
#region Property
|
public bool Main
|
{
|
get
|
{
|
return _main;
|
}
|
|
set
|
{
|
_main = value;
|
}
|
}
|
|
public bool Common
|
{
|
get
|
{
|
return _common;
|
}
|
|
set
|
{
|
_common = value;
|
}
|
}
|
|
public bool Temperature
|
{
|
get
|
{
|
return _temperature;
|
}
|
|
set
|
{
|
_temperature = value;
|
}
|
}
|
|
public bool Sensor
|
{
|
get
|
{
|
return _sensor;
|
}
|
|
set
|
{
|
_sensor = value;
|
}
|
}
|
|
public bool PowerMonitor
|
{
|
get
|
{
|
return _powerMonitor;
|
}
|
|
set
|
{
|
_powerMonitor = value;
|
}
|
}
|
|
public bool Pulse
|
{
|
get
|
{
|
return _pulse;
|
}
|
|
set
|
{
|
_pulse = value;
|
}
|
}
|
|
public bool Ldd
|
{
|
get
|
{
|
return _ldd;
|
}
|
|
set
|
{
|
_ldd = value;
|
}
|
}
|
|
public bool Motor
|
{
|
get
|
{
|
return _motor;
|
}
|
|
set
|
{
|
_motor = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _main;
|
private bool _common;
|
private bool _temperature;
|
private bool _sensor;
|
private bool _powerMonitor;
|
private bool _pulse;
|
private bool _ldd;
|
private bool _motor;
|
#endregion
|
}
|
|
public struct SystemStatus
|
{
|
#region Property
|
/// <summary>
|
/// Power On
|
/// </summary>
|
public bool PowerOn
|
{
|
get
|
{
|
return _powerOn;
|
}
|
|
set
|
{
|
_powerOn = value;
|
}
|
}
|
|
/// <summary>
|
/// Shutter Enabled
|
/// </summary>
|
public bool ShutterEnabled
|
{
|
get
|
{
|
return _shutterEnabled;
|
}
|
|
set
|
{
|
_shutterEnabled = value;
|
}
|
}
|
|
/// <summary>
|
/// Key Switch
|
/// </summary>
|
public bool KeySwitch
|
{
|
get
|
{
|
return _keySwitch;
|
}
|
|
set
|
{
|
_keySwitch = value;
|
}
|
}
|
|
/// <summary>
|
/// Laser Diode Drive On
|
/// </summary>
|
public bool LddOn
|
{
|
get
|
{
|
return _lddOn;
|
}
|
|
set
|
{
|
_lddOn = value;
|
}
|
}
|
|
/// <summary>
|
/// Q Switch On
|
/// </summary>
|
public bool QswOn
|
{
|
get
|
{
|
return _qswOn;
|
}
|
|
set
|
{
|
_qswOn = value;
|
}
|
}
|
|
/// <summary>
|
/// Shutter Interlock
|
/// </summary>
|
public bool ShutterInterlock
|
{
|
get
|
{
|
return _shutterInterlock;
|
}
|
|
set
|
{
|
_shutterInterlock = value;
|
}
|
}
|
|
/// <summary>
|
/// Laser Diode Drive Interlock
|
/// </summary>
|
public bool LddInterlock
|
{
|
get
|
{
|
return _lddInterlock;
|
}
|
|
set
|
{
|
_lddInterlock = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _powerOn;
|
private bool _shutterEnabled;
|
private bool _keySwitch;
|
private bool _lddOn;
|
private bool _qswOn;
|
private bool _shutterInterlock;
|
private bool _lddInterlock;
|
#endregion
|
}
|
|
public struct SystemFaults
|
{
|
#region Property
|
public bool Memory
|
{
|
get
|
{
|
return _memory;
|
}
|
|
set
|
{
|
_memory = value;
|
}
|
}
|
|
public bool SdCard
|
{
|
get
|
{
|
return _sdCard;
|
}
|
|
set
|
{
|
_sdCard = value;
|
}
|
}
|
|
public bool BoardCommunication
|
{
|
get
|
{
|
return _boardCommunication;
|
}
|
|
set
|
{
|
_boardCommunication = value;
|
}
|
}
|
|
public bool BoardState
|
{
|
get
|
{
|
return _boardState;
|
}
|
|
set
|
{
|
_boardState = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _memory;
|
private bool _sdCard;
|
private bool _boardCommunication;
|
private bool _boardState;
|
#endregion
|
}
|
|
public struct GeneralAlarms
|
{
|
#region Property
|
public bool Ldd1
|
{
|
get
|
{
|
return _ldd1;
|
}
|
|
set
|
{
|
_ldd1 = value;
|
}
|
}
|
|
public bool Ldd2
|
{
|
get
|
{
|
return _ldd2;
|
}
|
|
set
|
{
|
_ldd2 = value;
|
}
|
}
|
|
public bool Qsw
|
{
|
get
|
{
|
return _qsw;
|
}
|
|
set
|
{
|
_qsw = value;
|
}
|
}
|
|
public bool Flow
|
{
|
get
|
{
|
return _flow;
|
}
|
|
set
|
{
|
_flow = value;
|
}
|
}
|
|
public bool Wet
|
{
|
get
|
{
|
return _wet;
|
}
|
|
set
|
{
|
_wet = value;
|
}
|
}
|
|
public bool Humidity
|
{
|
get
|
{
|
return _humidity;
|
}
|
|
set
|
{
|
_humidity = value;
|
}
|
}
|
|
public bool HfSync
|
{
|
get
|
{
|
return _hfSync;
|
}
|
|
set
|
{
|
_hfSync = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _ldd1;
|
private bool _ldd2;
|
private bool _qsw;
|
private bool _flow;
|
private bool _wet;
|
private bool _humidity;
|
private bool _hfSync;
|
#endregion
|
}
|
|
public struct TemperatureControlFaults
|
{
|
#region Property
|
public bool TemperatureControlFault0
|
{
|
get
|
{
|
return _temperatureControlFault0;
|
}
|
|
set
|
{
|
_temperatureControlFault0 = value;
|
}
|
}
|
|
public bool TemperatureControlFault1
|
{
|
get
|
{
|
return _temperatureControlFault1;
|
}
|
|
set
|
{
|
_temperatureControlFault1 = value;
|
}
|
}
|
|
public bool TemperatureControlFault2
|
{
|
get
|
{
|
return _temperatureControlFault2;
|
}
|
|
set
|
{
|
_temperatureControlFault2 = value;
|
}
|
}
|
|
public bool TemperatureControlFault3
|
{
|
get
|
{
|
return _temperatureControlFault3;
|
}
|
|
set
|
{
|
_temperatureControlFault3 = value;
|
}
|
}
|
|
public bool TemperatureControlFault4
|
{
|
get
|
{
|
return _temperatureControlFault4;
|
}
|
|
set
|
{
|
_temperatureControlFault4 = value;
|
}
|
}
|
|
public bool TemperatureControlFault5
|
{
|
get
|
{
|
return _temperatureControlFault5;
|
}
|
|
set
|
{
|
_temperatureControlFault5 = value;
|
}
|
}
|
|
public bool TemperatureControlFault6
|
{
|
get
|
{
|
return _temperatureControlFault6;
|
}
|
|
set
|
{
|
_temperatureControlFault6 = value;
|
}
|
}
|
|
public bool TemperatureControlFault7
|
{
|
get
|
{
|
return _temperatureControlFault7;
|
}
|
|
set
|
{
|
_temperatureControlFault7 = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _temperatureControlFault0;
|
private bool _temperatureControlFault1;
|
private bool _temperatureControlFault2;
|
private bool _temperatureControlFault3;
|
private bool _temperatureControlFault4;
|
private bool _temperatureControlFault5;
|
private bool _temperatureControlFault6;
|
private bool _temperatureControlFault7;
|
#endregion
|
}
|
|
public struct SystemState
|
{
|
#region Property
|
public bool SystemInitialization
|
{
|
get
|
{
|
return _systemInitialization;
|
}
|
|
set
|
{
|
_systemInitialization = value;
|
}
|
}
|
|
public bool Setup
|
{
|
get
|
{
|
return _setup;
|
}
|
|
set
|
{
|
_setup = value;
|
}
|
}
|
|
public bool Running
|
{
|
get
|
{
|
return _running;
|
}
|
|
set
|
{
|
_running = value;
|
}
|
}
|
|
public bool Standby
|
{
|
get
|
{
|
return _standby;
|
}
|
|
set
|
{
|
_standby = value;
|
}
|
}
|
|
public bool SoftFault
|
{
|
get
|
{
|
return _softFault;
|
}
|
|
set
|
{
|
_softFault = value;
|
}
|
}
|
|
public bool HardFault
|
{
|
get
|
{
|
return _hardFault;
|
}
|
|
set
|
{
|
_hardFault = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private bool _systemInitialization;
|
private bool _setup;
|
private bool _running;
|
private bool _standby;
|
private bool _softFault;
|
private bool _hardFault;
|
#endregion
|
}
|
#endregion
|
|
#region Property
|
/// <summary>
|
/// Current soft faults.
|
/// </summary>
|
public SoftFaults CurrentSoftFaults
|
{
|
get
|
{
|
return _currentSoftFaults;
|
}
|
|
private set
|
{
|
_currentSoftFaults = value;
|
}
|
}
|
|
/// <summary>
|
/// Current board faults.
|
/// </summary>
|
public BoardFaults CurrentBoardFaults
|
{
|
get
|
{
|
return _currentBoardFaults;
|
}
|
|
private set
|
{
|
_currentBoardFaults = value;
|
}
|
}
|
|
/// <summary>
|
/// current system status.
|
/// </summary>
|
public SystemStatus CurrentSystemStatus
|
{
|
get
|
{
|
return _currentSystemStatus;
|
}
|
|
private set
|
{
|
_currentSystemStatus = value;
|
}
|
}
|
|
/// <summary>
|
/// curerent system faults.
|
/// </summary>
|
public SystemFaults CurrentSystemFaults
|
{
|
get
|
{
|
return _currentSystemFaults;
|
}
|
|
private set
|
{
|
_currentSystemFaults = value;
|
}
|
}
|
|
/// <summary>
|
/// Current general alarms.
|
/// </summary>
|
public GeneralAlarms CurrentGeneralAlarms
|
{
|
get
|
{
|
return _currentGeneralAlarms;
|
}
|
|
private set
|
{
|
_currentGeneralAlarms = value;
|
}
|
}
|
|
/// <summary>
|
/// Current temperature control faults.
|
/// </summary>
|
public TemperatureControlFaults CurrentTemperatureControlFaults
|
{
|
get
|
{
|
return _currentTemperatureControlFaults;
|
}
|
|
private set
|
{
|
_currentTemperatureControlFaults = value;
|
}
|
}
|
|
/// <summary>
|
/// Current systems state.
|
/// </summary>
|
public SystemState CurrentSystemState
|
{
|
get
|
{
|
return _currentSystemState;
|
}
|
|
private set
|
{
|
_currentSystemState = value;
|
}
|
}
|
|
/// <summary>
|
/// Enable shutter (true : Enable, false : Disable).
|
/// </summary>
|
public bool EnableShutter
|
{
|
get
|
{
|
return _enableShutter;
|
}
|
|
set
|
{
|
_enableShutter = value;
|
}
|
}
|
|
/// <summary>
|
/// Enable Laser diode driver (true : Enable, false : Disable).
|
/// </summary>
|
public bool EnableLdd
|
{
|
get
|
{
|
return _enableLdd;
|
}
|
|
set
|
{
|
_enableLdd = value;
|
}
|
}
|
|
/// <summary>
|
/// Set current (A).
|
/// </summary>
|
public float SetCurrent
|
{
|
get
|
{
|
return _setCurrent;
|
}
|
|
set
|
{
|
_setCurrent = value;
|
}
|
}
|
|
/// <summary>
|
/// Actual current (A).
|
/// </summary>
|
public float ActualCurrent
|
{
|
get
|
{
|
return _actualCurrent;
|
}
|
|
set
|
{
|
_actualCurrent = value;
|
}
|
}
|
|
/// <summary>
|
/// Diode voltage (V).
|
/// </summary>
|
public float DiodeVoltage
|
{
|
get
|
{
|
return _diodeVoltage;
|
}
|
|
set
|
{
|
_diodeVoltage = value;
|
}
|
}
|
|
/// <summary>
|
/// Max current (A).
|
/// </summary>
|
public float MaxCurrent
|
{
|
get
|
{
|
return _maxCurrent;
|
}
|
|
set
|
{
|
_maxCurrent = value;
|
}
|
}
|
|
/// <summary>
|
/// Laser diode driver hours (Hour).
|
/// </summary>
|
public float LddHours
|
{
|
get
|
{
|
return _lddHours;
|
}
|
|
set
|
{
|
_lddHours = value;
|
}
|
}
|
|
/// <summary>
|
/// Pulse Repetition Frequency (Hz).
|
/// </summary>
|
public int Prf
|
{
|
get
|
{
|
return _prf;
|
}
|
|
set
|
{
|
_prf = value;
|
}
|
}
|
|
/// <summary>
|
/// Pulse repetition frequency source.
|
/// </summary>
|
public SourcesType PrfSource
|
{
|
get
|
{
|
return _prfSource;
|
}
|
|
set
|
{
|
_prfSource = value;
|
}
|
}
|
|
/// <summary>
|
/// Gate source.
|
/// </summary>
|
public SourcesType GateSource
|
{
|
get
|
{
|
return _gateSource;
|
}
|
|
set
|
{
|
_gateSource = value;
|
}
|
}
|
|
/// <summary>
|
/// Pulse energy control source.
|
/// </summary>
|
public SourcesType PecSource
|
{
|
get
|
{
|
return _pecSource;
|
}
|
|
set
|
{
|
_pecSource = value;
|
}
|
}
|
|
/// <summary>
|
/// First pulse kill enable (true : Enable, false : Disable).
|
/// </summary>
|
public bool FpkEnable
|
{
|
get
|
{
|
return _fpkEnable;
|
}
|
|
set
|
{
|
_fpkEnable = value;
|
}
|
}
|
|
/// <summary>
|
/// First pulse kill Time (ns).
|
/// </summary>
|
public int FpkRampTime
|
{
|
get
|
{
|
return _fpkRampTime;
|
}
|
|
set
|
{
|
_fpkRampTime = value;
|
}
|
}
|
|
/// <summary>
|
/// First pulse kill Ramp Rate (ns)
|
/// </summary>
|
public int FpkRampRate
|
{
|
get
|
{
|
return _fpkRampRate;
|
}
|
|
set
|
{
|
_fpkRampRate = value;
|
}
|
}
|
|
/// <summary>
|
/// Lpk Enable (true : Enable, false : Disable).
|
/// </summary>
|
public bool LpkEnable
|
{
|
get
|
{
|
return _lpkEnable;
|
}
|
|
set
|
{
|
_lpkEnable = value;
|
}
|
}
|
|
/// <summary>
|
/// LPK Ramp Time (ns).
|
/// </summary>
|
public int LpkRampTime
|
{
|
get
|
{
|
return _lpkRampTime;
|
}
|
|
set
|
{
|
_lpkRampTime = value;
|
}
|
}
|
|
/// <summary>
|
/// LPK Ramp Rate (ns).
|
/// </summary>
|
public int LpkRampRate
|
{
|
get
|
{
|
return _lpkRampRate;
|
}
|
|
set
|
{
|
_lpkRampRate = value;
|
}
|
}
|
|
/// <summary>
|
/// Shg temperature set point (℃).
|
/// </summary>
|
public float ShgTemperatureSetPoint
|
{
|
get
|
{
|
return _shgTemperatureSetPoint;
|
}
|
|
set
|
{
|
_shgTemperatureSetPoint = value;
|
}
|
}
|
|
/// <summary>
|
/// Thg temperature set point (℃).
|
/// </summary>
|
public float ThgTemperatureSetPoint
|
{
|
get
|
{
|
return _thgTemperatureSetPoint;
|
}
|
|
set
|
{
|
_thgTemperatureSetPoint = value;
|
}
|
}
|
|
/// <summary>
|
/// Ld temperature set point (℃).
|
/// </summary>
|
public float LdTemperatureSetPoint
|
{
|
get
|
{
|
return _ldTemperatureSetPoint;
|
}
|
|
set
|
{
|
_ldTemperatureSetPoint = value;
|
}
|
}
|
|
|
/// <summary>
|
/// Shg actual temperature (℃).
|
/// </summary>
|
public float ShgActualTemperature
|
{
|
get
|
{
|
return _shgActualTemperature;
|
}
|
|
set
|
{
|
_shgActualTemperature = value;
|
}
|
}
|
|
/// <summary>
|
/// Thg actual temperature (℃).
|
/// </summary>
|
public float ThgActualTemperature
|
{
|
get
|
{
|
return _thgActualTemperature;
|
}
|
|
set
|
{
|
_thgActualTemperature = value;
|
}
|
}
|
|
/// <summary>
|
/// Laser diode actual temperature (℃).
|
/// </summary>
|
public float LdActualTemperature
|
{
|
get
|
{
|
return _ldActualTemperature;
|
}
|
|
set
|
{
|
_ldActualTemperature = value;
|
}
|
}
|
|
/// <summary>
|
/// Duty control (true : Enable, false : Disable).
|
/// </summary>
|
public bool DutyControl
|
{
|
get
|
{
|
return _dutyControl;
|
}
|
|
set
|
{
|
_dutyControl = value;
|
}
|
}
|
|
/// <summary>
|
/// Duty control width (us).
|
/// </summary>
|
public float DutyControlWidth
|
{
|
get
|
{
|
return _dutyControlWidth;
|
}
|
|
set
|
{
|
_dutyControlWidth = value;
|
}
|
}
|
|
/// <summary>
|
/// Pulse energy control level (%).
|
/// </summary>
|
public float PecLevel
|
{
|
get
|
{
|
return _pecLevel;
|
}
|
|
set
|
{
|
_pecLevel = value;
|
}
|
}
|
|
/// <summary>
|
/// Burst status (true : Enable, false : Disable).
|
/// </summary>
|
public bool BurstStatus
|
{
|
get
|
{
|
return _burstStatus;
|
}
|
|
set
|
{
|
_burstStatus = value;
|
}
|
}
|
|
/// <summary>
|
/// Burst count.
|
/// </summary>
|
public ushort BurstCount
|
{
|
get
|
{
|
return _burstCount;
|
}
|
|
set
|
{
|
_burstCount = value;
|
}
|
}
|
|
/// <summary>
|
/// Burst rate.
|
/// </summary>
|
public ushort BurstRate
|
{
|
get
|
{
|
return _burstRate;
|
}
|
|
set
|
{
|
_burstRate = value;
|
}
|
}
|
|
/// <summary>
|
/// Burst cycles.
|
/// </summary>
|
public ushort BurstCycles
|
{
|
get
|
{
|
return _burstCycles;
|
}
|
|
set
|
{
|
_burstCycles = value;
|
}
|
}
|
|
/// <summary>
|
/// Burst firing mode.
|
/// </summary>
|
public BurstFiringModeType BurstFiringMode
|
{
|
get
|
{
|
return _burstFiringMode;
|
}
|
|
set
|
{
|
_burstFiringMode = value;
|
}
|
}
|
|
/// <summary>
|
/// Burst trigger source.
|
/// </summary>
|
public BurstTriggerSourceType BurstTriggerSource
|
{
|
get
|
{
|
return _burstTriggerSource;
|
}
|
|
set
|
{
|
_burstTriggerSource = value;
|
}
|
}
|
|
/// <summary>
|
/// Duty control mode.
|
/// </summary>
|
public DutyControlModeType DutyControlMode
|
{
|
get
|
{
|
return _dutyControlMode;
|
}
|
|
set
|
{
|
_dutyControlMode = value;
|
}
|
}
|
|
/// <summary>
|
/// Power monitor reading (W).
|
/// </summary>
|
public float PowerMonitorReading
|
{
|
get
|
{
|
return _powerMonitorReading;
|
}
|
|
set
|
{
|
_powerMonitorReading = value;
|
}
|
}
|
|
/// <summary>
|
/// Flow reading (L/min).
|
/// </summary>
|
public float FlowReading
|
{
|
get
|
{
|
return _flowReading;
|
}
|
|
set
|
{
|
_flowReading = value;
|
}
|
}
|
|
/// <summary>
|
/// Humidity reading (%).
|
/// </summary>
|
public ushort HumidityReading
|
{
|
get
|
{
|
return _humidityReading;
|
}
|
|
set
|
{
|
_humidityReading = value;
|
}
|
}
|
|
/// <summary>
|
/// Ip address.
|
/// </summary>
|
public string IpAddress
|
{
|
get
|
{
|
return _ipAddress;
|
}
|
|
set
|
{
|
_ipAddress = value;
|
}
|
}
|
|
/// <summary>
|
/// Subnet mask.
|
/// </summary>
|
public string SubnetMask
|
{
|
get
|
{
|
return _subnetMask;
|
}
|
|
set
|
{
|
_subnetMask = value;
|
}
|
}
|
|
/// <summary>
|
/// Gateway.
|
/// </summary>
|
public string Gateway
|
{
|
get
|
{
|
return _gateway;
|
}
|
|
set
|
{
|
_gateway = value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private SoftFaults _currentSoftFaults;
|
private BoardFaults _currentBoardFaults;
|
private SystemStatus _currentSystemStatus;
|
private SystemFaults _currentSystemFaults;
|
private GeneralAlarms _currentGeneralAlarms;
|
private TemperatureControlFaults _currentTemperatureControlFaults;
|
private SystemState _currentSystemState;
|
|
private bool _enableShutter;
|
private bool _enableLdd;
|
private float _setCurrent;
|
private float _actualCurrent;
|
private float _diodeVoltage;
|
private float _maxCurrent;
|
private float _lddHours;
|
private int _prf;
|
private SourcesType _prfSource;
|
private SourcesType _gateSource;
|
private SourcesType _pecSource;
|
private bool _fpkEnable;
|
private int _fpkRampTime;
|
private int _fpkRampRate;
|
private bool _lpkEnable;
|
private int _lpkRampTime;
|
private int _lpkRampRate;
|
private float _shgTemperatureSetPoint;
|
private float _thgTemperatureSetPoint;
|
private float _ldTemperatureSetPoint;
|
private float _shgActualTemperature;
|
private float _thgActualTemperature;
|
private float _ldActualTemperature;
|
private bool _dutyControl;
|
private float _dutyControlWidth;
|
private float _pecLevel;
|
private bool _burstStatus;
|
private ushort _burstCount;
|
private ushort _burstRate;
|
private ushort _burstCycles;
|
private BurstFiringModeType _burstFiringMode;
|
private BurstTriggerSourceType _burstTriggerSource;
|
private DutyControlModeType _dutyControlMode;
|
private float _powerMonitorReading;
|
private float _flowReading;
|
private ushort _humidityReading;
|
private string _ipAddress;
|
private string _subnetMask;
|
private string _gateway;
|
#endregion
|
|
#region Construct
|
public PiLaserStatus()
|
{
|
_currentSoftFaults = new SoftFaults();
|
_currentBoardFaults = new BoardFaults();
|
_currentSystemStatus = new SystemStatus();
|
_currentSystemFaults = new SystemFaults();
|
_currentGeneralAlarms = new GeneralAlarms();
|
_currentTemperatureControlFaults = new TemperatureControlFaults();
|
_currentSystemState = new SystemState();
|
|
IpAddress = "000.000.000.000";
|
SubnetMask = "000.000.000.000";
|
Gateway = "000.000.000.000";
|
}
|
#endregion
|
|
#region Function
|
/// <summary>
|
/// Change soft fauls
|
/// </summary>
|
/// <param name="softFaults">Soft faults</param>
|
public void ChangeSoftFaults(byte softFaults)
|
{
|
var bit = new BitArray(new byte[] { softFaults });
|
|
_currentSoftFaults.HfSync = bit[0];
|
_currentSoftFaults.LddInterlock = bit[1];
|
_currentSoftFaults.ShutterInterlock = bit[2];
|
_currentSoftFaults.LowExtFrequency = bit[3];
|
}
|
|
/// <summary>
|
/// Change board faults
|
/// </summary>
|
/// <param name="boardFaults">Board faulse</param>
|
public void ChangeBoardFaults(byte boardFaults)
|
{
|
var bit = new BitArray(new byte[] { boardFaults });
|
|
_currentBoardFaults.Main = bit[0];
|
_currentBoardFaults.Common = bit[1];
|
_currentBoardFaults.Temperature = bit[2];
|
_currentBoardFaults.Sensor = bit[3];
|
_currentBoardFaults.PowerMonitor = bit[4];
|
_currentBoardFaults.Pulse = bit[5];
|
_currentBoardFaults.Ldd = bit[6];
|
_currentBoardFaults.Motor = bit[7];
|
}
|
|
/// <summary>
|
/// Change system status.
|
/// </summary>
|
/// <param name="systemStatus">System status</param>
|
public void ChangeSystemStatus(byte systemStatus)
|
{
|
var bit = new BitArray(new byte[] { systemStatus });
|
|
_currentSystemStatus.PowerOn = bit[0];
|
_currentSystemStatus.ShutterEnabled= bit[1];
|
_currentSystemStatus.KeySwitch = bit[2];
|
_currentSystemStatus.LddOn = bit[3];
|
_currentSystemStatus.QswOn = bit[4];
|
_currentSystemStatus.ShutterInterlock = bit[5];
|
_currentSystemStatus.LddInterlock = bit[6];
|
}
|
|
/// <summary>
|
/// Change system faults
|
/// </summary>
|
/// <param name="systemFaults">System faults</param>
|
public void ChangeSystemFaults(byte systemFaults)
|
{
|
var bit = new BitArray(new byte[] { systemFaults });
|
|
_currentSystemFaults.Memory = bit[0];
|
_currentSystemFaults.SdCard = bit[1];
|
_currentSystemFaults.BoardCommunication = bit[2];
|
_currentSystemFaults.BoardState = bit[3];
|
}
|
|
/// <summary>
|
/// Change general alrams
|
/// </summary>
|
/// <param name="generalAlarms">General alarms</param>
|
public void ChangeGeneralAlarms(byte generalAlarms)
|
{
|
var bit = new BitArray(new byte[] { generalAlarms });
|
|
_currentGeneralAlarms.Ldd1 = bit[0];
|
_currentGeneralAlarms.Ldd2 = bit[1];
|
_currentGeneralAlarms.Qsw = bit[2];
|
_currentGeneralAlarms.Flow = bit[3];
|
_currentGeneralAlarms.Wet = bit[4];
|
_currentGeneralAlarms.Humidity = bit[5];
|
_currentGeneralAlarms.HfSync = bit[6];
|
}
|
|
/// <summary>
|
/// Change temperature control faults
|
/// </summary>
|
/// <param name="temperatureControlFaults">Temperature control faults</param>
|
public void ChangeTemperatureControlFaults(byte temperatureControlFaults)
|
{
|
var bit = new BitArray(new byte[] { temperatureControlFaults });
|
|
_currentTemperatureControlFaults.TemperatureControlFault0 = bit[0];
|
_currentTemperatureControlFaults.TemperatureControlFault1 = bit[1];
|
_currentTemperatureControlFaults.TemperatureControlFault2 = bit[2];
|
_currentTemperatureControlFaults.TemperatureControlFault3 = bit[3];
|
_currentTemperatureControlFaults.TemperatureControlFault4 = bit[4];
|
_currentTemperatureControlFaults.TemperatureControlFault5 = bit[5];
|
_currentTemperatureControlFaults.TemperatureControlFault6 = bit[6];
|
_currentTemperatureControlFaults.TemperatureControlFault7 = bit[7];
|
}
|
|
/// <summary>
|
/// Change system state
|
/// </summary>
|
/// <param name="systemState">System state</param>
|
public void ChangeSystemState(byte systemState)
|
{
|
var bit = new BitArray(new byte[] { systemState });
|
|
_currentSystemState.SystemInitialization = bit[0];
|
_currentSystemState.Setup = bit[1];
|
_currentSystemState.Running = bit[2];
|
_currentSystemState.Standby = bit[3];
|
_currentSystemState.SoftFault = bit[4];
|
_currentSystemState.HardFault = bit[5];
|
}
|
#endregion
|
}
|
}
|