393 lines
11 KiB
C#
393 lines
11 KiB
C#
using Aurora.Api;
|
|
using Aurora.Util.HislogPlus;
|
|
using AuroraIO;
|
|
using AuroraLaser;
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using static ILSOS_ACW_H52A.Device.IOController_ACW_H52A;
|
|
|
|
namespace ILSOS_ACW_H52A.Device
|
|
{
|
|
class LaserCoherentArm_IO : ILaserDevice
|
|
{
|
|
static readonly Logger Log = new Logger("LaserInterface");
|
|
public bool IsEmissionReady { get; set; }
|
|
public bool HasAlarm { get; set; }
|
|
|
|
private bool _IsSimul;
|
|
private int _Status;
|
|
private double _OperatingPower;
|
|
private double _RepetitionRate = 0.0;
|
|
//internal bool IsCommError => IsConnected();
|
|
|
|
private IODevice _IO;
|
|
|
|
Thread m_threadUpdateLaserStatus = null;
|
|
|
|
private bool bPilotLaserOnCmd;
|
|
private bool bLaserEmissionReadyOnCmd;
|
|
|
|
public LaserCoherentArm_IO(string deviceid, bool isSimul, IODevice IO_Board)
|
|
{
|
|
_IsSimul = isSimul;
|
|
|
|
bPilotLaserOnCmd = false;
|
|
|
|
_IO = IO_Board;
|
|
}
|
|
|
|
public int ActivateDevice()
|
|
{
|
|
if (_IsSimul) {
|
|
return E1.OK;
|
|
}
|
|
int nRet = 0;
|
|
if (!_IO.IsActivated)
|
|
nRet = _IO.Activate();
|
|
|
|
return nRet;
|
|
}
|
|
|
|
public int DeactivateDevice()
|
|
{
|
|
if (_IsSimul) {
|
|
return E1.OK;
|
|
}
|
|
|
|
if (_IO._iOUnit.IsConnected()) {
|
|
// 동작중인것을 정지시키는 코드는 여기에
|
|
_IO._iOUnit.Close();
|
|
}
|
|
|
|
return E1.OK;
|
|
}
|
|
|
|
public int LaserOn()
|
|
{
|
|
int nRet = SetLaserDOCommand(eADOAddress.RemoteStart, true) == true ? E1.OK : E1.NETWORK;
|
|
Log.I($"Laser Remote Start On : {nRet}");
|
|
|
|
if (nRet != 0)
|
|
return nRet;
|
|
|
|
Thread.Sleep(500);
|
|
|
|
nRet = SetLaserDOCommand(eADOAddress.LaserEnableOnOff, true) == true ? E1.OK : E1.NETWORK;
|
|
Log.I($"Laser Enable On : {nRet}");
|
|
|
|
if (nRet != 0)
|
|
return nRet;
|
|
|
|
return nRet;
|
|
}
|
|
|
|
public int LaserOff()
|
|
{
|
|
int nRet = SetLaserDOCommand(eADOAddress.LaserEnableOnOff, false) == true ? E1.OK : E1.NETWORK;
|
|
Log.I($"Laser Enable Off : {nRet}");
|
|
|
|
if (nRet != 0)
|
|
return nRet;
|
|
Thread.Sleep(500);
|
|
|
|
nRet = SetLaserDOCommand(eADOAddress.RemoteStart, false) == true ? E1.OK : E1.NETWORK;
|
|
Log.I($"Laser Remote Start Off : {nRet}");
|
|
|
|
return nRet;
|
|
}
|
|
public int PilotLaserOn()
|
|
{
|
|
int nRet = SetLaserDOCommand(eADOAddress.GuideBeamOnOff, true) == true ? E1.OK : E1.NETWORK;
|
|
return nRet;
|
|
}
|
|
|
|
public int PilotLaserOff()
|
|
{
|
|
int nRet = SetLaserDOCommand(eADOAddress.GuideBeamOnOff, false) == true ? E1.OK : E1.NETWORK;
|
|
return nRet;
|
|
}
|
|
public bool GetConnected()
|
|
{
|
|
return _IO._iOUnit.IsConnected();
|
|
}
|
|
public int SetData(int nTarget, int value)
|
|
{
|
|
// 어떻게 쓸지 고민중
|
|
|
|
return E1.OK;
|
|
}
|
|
public string GetData(int nTarget)
|
|
{
|
|
// 어떻게 쓸지 고민중
|
|
return "";
|
|
}
|
|
|
|
private void UpdateLaserStatus()
|
|
{
|
|
while (GetConnected()) {
|
|
int UpdateTimeInterval = 300; // 300ms
|
|
Thread.Sleep(UpdateTimeInterval);
|
|
GetLaserAllStatus();
|
|
}
|
|
}
|
|
|
|
public bool GetInitCommunication()
|
|
{
|
|
//// IPG 는 해당 함수 없음
|
|
return true;
|
|
}
|
|
public bool GetEmissionStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDIStatus(eADIAddress.EmissionOnOff, out bResult);
|
|
return bResult;
|
|
}
|
|
public bool GetLaserReady()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDIStatus(eADIAddress.EmissionOnOff, out bResult);
|
|
return bResult;
|
|
}
|
|
public bool GetLaserError()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
// [25.09.16] ubs.cmy - Alarm이 뭔지 물어보고 필요없으면 Interlock으로 변경할 것
|
|
bool bResult;
|
|
GetLaserDIStatus(eADIAddress.Alarm, out bResult);
|
|
|
|
//// [25.09.16] ubs.cmy - Laser Interlock 선 연결 대응
|
|
//if(bResult)
|
|
// return bResult;
|
|
|
|
//GetLaserDIStatus(eADIAddress.LaserInterlock, out bResult);
|
|
|
|
return bResult;
|
|
}
|
|
|
|
public bool GetLaserInterlock()
|
|
{
|
|
// [25.09.16] ubs.cmy - Laser Interlock 선 연결 대응
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
GetLaserDIStatus(eADIAddress.LaserInterlock, out bool bResult);
|
|
return bResult;
|
|
}
|
|
// MAINS_STATUS, ERROR_STATUS 는 위에 있음
|
|
public bool GetPilotLaserStatus()
|
|
{
|
|
// pilot 신호는 Pin map 배정이 안되어서 DI로 받아오는게 없다. DO 로 대신하자. 밑에 DO 검색이 있어서 보류.
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDoStatus(eADOAddress.GuideBeamOnOff, out bResult);
|
|
return bResult;
|
|
//return false;
|
|
}
|
|
public string GetControlMode()
|
|
{
|
|
// Control mode 신호는 Pin map 배정이 안되어서 DI로 받아오는게 없다.
|
|
|
|
return "";
|
|
}
|
|
public string GetPowerCenter()
|
|
{
|
|
// IO Board 제어는 파워를 직접 세팅하지 않는다.
|
|
|
|
return "";
|
|
}
|
|
public string GetPowerRing()
|
|
{
|
|
// IO Board 제어는 파워를 직접 세팅하지 않는다.
|
|
|
|
return "";
|
|
}
|
|
#region Set 명령 나간 bit 를 모니터링
|
|
public bool GetStartLaserSetBitStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
// Laser Start 명령. 비슷한 이름이 많은데 기능에 대한 설명이 없으니 유추가 어렵다.
|
|
bool bResult;
|
|
GetLaserDIStatus(eADIAddress.LaserOn, out bResult);
|
|
return bResult;
|
|
}
|
|
public bool GetLaserStartSetBitStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDoStatus(eADOAddress.LaserEnableOnOff, out bResult);
|
|
return bResult;
|
|
}
|
|
public bool GetPilotLaserSetBitStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDoStatus(eADOAddress.GuideBeamOnOff, out bResult);
|
|
return bResult;
|
|
}
|
|
public bool GetLaserResetSetBitStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
|
|
// Reset Alarm I/O가 없음
|
|
// GetLaserDoStatus(eADOAddress.ResetAlarm, out bResult);
|
|
return false;
|
|
}
|
|
public bool GetControlModeSetStatus()
|
|
{
|
|
// Control mode 는 Pin map 에 없다
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region IO Board Functions
|
|
private bool GetLaserDIStatus(eADIAddress addr, out bool bValue)
|
|
{
|
|
if (_IsSimul) {
|
|
bValue = false;
|
|
return true;
|
|
}
|
|
bool[] arrDI = new bool[Convert.ToInt32(_IO._iOUnit.GetDICount())];
|
|
int nRet = _IO._iOUnit.GetDiArray(ref arrDI);
|
|
if (nRet == E1.OK && arrDI.Length != 0) {
|
|
bValue = arrDI[Convert.ToInt32(addr)];
|
|
return true;
|
|
} else {
|
|
bValue = false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private bool GetLaserDoStatus(eADOAddress addr, out bool bValue)
|
|
{
|
|
if (_IsSimul) {
|
|
bValue = false;
|
|
return true;
|
|
}
|
|
bool[] arrDO = new bool[Convert.ToInt32(_IO._iOUnit.GetDOCount())];
|
|
int nRet = _IO._iOUnit.GetDoArray(ref arrDO);
|
|
if (nRet == E1.OK && arrDO.Length != 0) {
|
|
bValue = arrDO[Convert.ToInt32(addr)];
|
|
return true;
|
|
} else {
|
|
bValue = false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private bool GetLaserAllStatus()
|
|
{
|
|
if (_IsSimul) {
|
|
return true;
|
|
}
|
|
bool[] arrDI = new bool[Convert.ToInt32(_IO._iOUnit.GetDICount())];
|
|
int nRet = _IO._iOUnit.GetDoArray(ref arrDI);
|
|
if (nRet == E1.OK && arrDI.Length != 0) {
|
|
// 여기에 arrDI 를 저장하는 변수를 assign 하자.
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
private bool SetLaserDOCommand(eADOAddress addr, bool bSetValue)
|
|
{
|
|
if (_IsSimul) {
|
|
return true;
|
|
}
|
|
int nRet = _IO._iOUnit.WriteDoBit(Convert.ToInt32(addr), bSetValue);
|
|
if (nRet == E1.OK) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public static object GetPropertyValue(object obj, string propertyName)
|
|
{
|
|
if (obj == null)
|
|
throw new ArgumentNullException(nameof(obj));
|
|
if (string.IsNullOrEmpty(propertyName))
|
|
throw new ArgumentNullException(nameof(propertyName));
|
|
|
|
Type type = obj.GetType();
|
|
PropertyInfo propertyInfo = type.GetProperty(propertyName);
|
|
|
|
if (propertyInfo == null)
|
|
throw new ArgumentException($"Property '{propertyName}' not found on type '{type.FullName}'");
|
|
|
|
return propertyInfo.GetValue(obj);
|
|
}
|
|
|
|
public int ResetLaser()
|
|
{
|
|
int nRet = SetLaserDOCommand(eADOAddress.Reset, true) == true ? E1.OK : E1.NETWORK;
|
|
|
|
if (nRet != 0)
|
|
return nRet;
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
nRet = SetLaserDOCommand(eADOAddress.Reset, false) == true ? E1.OK : E1.NETWORK;
|
|
|
|
if (nRet != 0)
|
|
return nRet;
|
|
|
|
return nRet;
|
|
}
|
|
public bool GetWarningStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDIStatus(eADIAddress.Warning, out bResult);
|
|
return bResult;
|
|
}
|
|
public bool GetEStop()
|
|
{
|
|
//Won : 현재 EMO I/O 배선 없음 배선 추가 후 구현 필요
|
|
//CMY : 배선 추가 예정에 따른 구현 준비
|
|
/*
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
bool bResult;
|
|
GetLaserDIStatus(eADIAddress.LaserEMO, out bResult);
|
|
return bResult;
|
|
*/
|
|
return false;
|
|
|
|
}
|
|
}
|
|
}
|