2026-01-26 18:56:53 +09:00

409 lines
10 KiB
C#

using Aurora.Api;
using Aurora.Api.Devices;
using AuroraLaser.Amplitude.Satsuma;
using AuroraLaser.Coherent.HyperRapid;
using Hermes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AuroraLaser.Coherent.RapidLX
{
// IR
public class LaserDeviceRapidLX : Device, ILaserDeviceCoherent
{
LaserRapidLXSocketConn _LaserRapidLXSocketConn;
public int Trigger { get; private set; }
public bool State { get; private set; }
public int Burst { get; private set; }
public int RepRate { get; private set; }
public double Power { get; private set; }
public double MonitorPower { get; private set; }
public double MonitorSeed { get; private set; }
public string Fault { get; private set; }
public string Serial { get; private set; }
public string FirmVer { get; private set; }
public string Model { get; private set; }
public string Status { get; private set; }
public string Warning { get; private set; }
public double Flow { get; private set; }
public double Temp { get; private set; }
public double SeederTime { get; private set; }
public double HeadTime { get; private set; }
public LaserRapidLXConfig Config { get; set; }
public LaserDeviceRapidLX(string deviceId)
{
DeviceId = deviceId;
_LaserRapidLXSocketConn = new LaserRapidLXSocketConn(deviceId);
}
protected override int DoActivate(IDeviceConfig config)
{
Config = config as LaserRapidLXConfig;
return ActivateDevice();
//if (IsSimul) {
// return E1.OK;
//}
//return _LaserRapidLXSocketConn.OnInit(config.ConnConfig as SocketConnConfig);
}
protected override int DoDeactivate()
{
return DeactivateDevice();
//return _LaserRapidLXSocketConn.OnClose();
}
public int ActivateDevice()
{
if (IsSimul) {
return E1.OK;
}
return _LaserRapidLXSocketConn.OnInit(Config.ConnConfig as SocketConnConfig);
}
public int DeactivateDevice()
{
return _LaserRapidLXSocketConn.OnClose();
}
public bool IsConnected()
{
if (!IsActivated) {
return false;
}
IsCommError = _LaserRapidLXSocketConn._IsCommError;
if (IsCommError) {
return false;
}
return true;
}
public int SetAlarmReset()
{
if (!IsActivated) {
return E2.NOT_CONNECTED;
}
if (IsSimul) {
return E1.OK;
}
return _LaserRapidLXSocketConn.SetAlarmReset();
}
public int SetEmission(bool bEmission)
{
if (!IsActivated) {
return E2.NOT_CONNECTED;
}
if (IsSimul) {
State = bEmission;
return E1.OK;
}
return _LaserRapidLXSocketConn.SetEmission(bEmission);
}
public int SetPower(double dPower)
{
if (!IsActivated) {
return E2.NOT_CONNECTED;
}
if (IsSimul) {
Power = dPower;
return E1.OK;
}
return _LaserRapidLXSocketConn.SetPower(dPower);
}
public int SetRepRate(int iRepRate)
{
if (!IsActivated) {
return E2.NOT_CONNECTED;
}
if (IsSimul) {
RepRate = iRepRate;
return E1.OK;
}
return _LaserRapidLXSocketConn.SetRepRate(iRepRate);
}
public int SetBurst(int iBurst)
{
if (!IsActivated) {
return E2.NOT_CONNECTED;
}
if (IsSimul) {
Burst = iBurst;
return E1.OK;
}
return _LaserRapidLXSocketConn.SetBurst(iBurst);
}
public int SetTrigger(int iTrigger)
{
if (!IsActivated) {
return E2.NOT_CONNECTED;
}
if (IsSimul) {
Trigger = iTrigger;
return E1.OK;
}
return _LaserRapidLXSocketConn.SetTrigger(iTrigger);
}
public void UpdateStatus()
{
if (!IsActivated) {
return;
}
var status = _LaserRapidLXSocketConn.GetStatus();
if (status == null) {
return;
}
int iValue;
double dValue;
var strList = status.Split('r');
for (int i = 0; i < strList.Count(); i++) {
var splited = strList[i].Split('=');
if (splited.Count() < 2) {
continue;
}
var command = splited[0];
var strValue = splited[1];
if (strValue.Length > 20) {
return;
}
switch (command) {
case "\nBURST":
if (int.TryParse(strValue, out iValue)) {
Burst = iValue;
}
break;
case "\nF":
Fault = strValue;
break;
case "\nW":
Warning = strValue;
break;
case "\nWF":
if (double.TryParse(strValue, out dValue)) {
Temp = dValue;
}
break;
case "\nSH":
if (double.TryParse(strValue, out dValue)) {
SeederTime = dValue;
}
break;
case "\nHH":
if (double.TryParse(strValue, out dValue)) {
HeadTime = dValue;
}
break;
case "\nRL":
if (double.TryParse(strValue, out dValue)) {
Power = dValue;
}
break;
case "\nPD4P":
if (double.TryParse(strValue, out dValue)) {
MonitorSeed = dValue;
}
break;
case "\nPOUT":
if (double.TryParse(strValue, out dValue)) {
MonitorPower = dValue;
}
break;
case "\nRRAMPSET":
if (int.TryParse(strValue, out iValue)) {
RepRate = iValue;
}
break;
case "\nPM":
if (int.TryParse(strValue, out iValue)) {
Trigger = iValue;
}
break;
case "\nSTATE":
if (int.TryParse(strValue, out iValue)) {
State = iValue == 1;
}
break;
}
}
}
///////////////////////////////////////////////////////////
// Laser Interface 추가
// All LaserDevice 에서 선택하여 Device 가 생성될 때 사용되며, All LaserDevice 가 Activated 일 때만 true 가 됨.
public bool IsActivated_InAllLaserDevice = false;
private bool CanCallLaserFunction()
{
if (IsActivated_InAllLaserDevice == false && IsActivated == false) {
return false;
}
return true;
}
public int LaserOn()
{
// TODO: 구현 필요
return 1;
}
public int LaserOff()
{
// TODO: 구현 필요
return 1;
}
public int PilotLaserOn()
{
// TODO: 구현 필요
return 1;
}
public int PilotLaserOff()
{
// TODO: 구현 필요
return 1;
}
public bool GetPilotLaserStatus()
{
// TODO: 구현 필요
return true;
}
public bool GetLaserReady()
{
// TODO: 구현 필요
return true;
}
public bool GetPilotLaserSetBitStatus()
{
// TODO: 구현 필요
return true;
}
public bool GetConnected()
{
// TODO: 구현 필요
return true;
}
public int SetData(int nTarget, int value)
{
// TODO: 구현 필요
return 1;
}
public int ResetLaser()
{
// TODO: 구현 필요
return E1.OK;
}
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();
}
}
}