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

338 lines
8.2 KiB
C#

using Aurora.Api;
using Aurora.Api.Devices;
using AuroraLaser.Amplitude.Satsuma;
using AuroraLaser.IPG.YLPN;
using AuroraLaser.IPG.YLPP;
using Hermes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static AuroraLaser.IPG.YLS.LaserYLSSocketConn;
namespace AuroraLaser.IPG.YLS
{
public class LaserDeviceYLS : Device, ILaserDeviceIPG
{
protected Logger Log = new Logger("LaserDeviceYLS");
public LaserYLSConfig Config { get; set; }
private LaserYLSSocketConn _laserYLSSocketConn;
public LaserDeviceYLS(string deviceId)
{
CommType = CommunicationType.Socket;
DeviceId = deviceId;
}
protected override int DoActivate(IDeviceConfig config)
{
Config = config as LaserYLSConfig;
return ActivateDevice();
//Config = config as LaserYLSConfig;
//if (IsActivated) {
// return E1.OK;
//}
//if (Config.IsSimul) {
// return E1.OK;
//}
//_laserYLSSocketConn = new LaserYLSSocketConn(DeviceId, IsSimul);
//if (_laserYLSSocketConn == null) {
// Log.E(string.Format("LaserObj is Null"));
// return E1.ARGUMENT;
//}
//return _laserYLSSocketConn.Open(Config.ConnConfig as SocketConnConfig);
}
protected override int DoDeactivate()
{
return DeactivateDevice();
//if (IsSimul) {
// return E1.OK;
//}
//if (_laserYLSSocketConn != null) {
// _laserYLSSocketConn.DisConnect();
//}
//return E1.OK;
}
public int ActivateDevice()
{
if (IsActivated || IsActivated_InAllLaserDevice) {
return E1.OK;
}
if (IsSimul) {
return E1.OK;
}
_laserYLSSocketConn = new LaserYLSSocketConn(DeviceId, IsSimul);
if (_laserYLSSocketConn == null) {
Log.E(string.Format("LaserObj is Null"));
return E1.ARGUMENT;
}
return _laserYLSSocketConn.Open(Config.ConnConfig as SocketConnConfig);
}
public int DeactivateDevice()
{
if (IsSimul) {
return E1.OK;
}
if (_laserYLSSocketConn != null) {
_laserYLSSocketConn.DisConnect();
}
return E1.OK;
}
///////////////////////////////////////////////////////////
// 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;
}
if (_laserYLSSocketConn == null) {
return false;
}
return true;
}
public int LaserOn()
{
if (IsSimul) {
return E1.OK;
}
if (CanCallLaserFunction() == false) {
return E1.GENERIC;
}
return _laserYLSSocketConn.LaserOn();
}
public int LaserOff()
{
if (IsSimul) {
return E1.OK;
}
if (CanCallLaserFunction() == false) {
return E1.GENERIC;
}
return _laserYLSSocketConn.LaserOff();
}
public int PilotLaserOn()
{
if (IsSimul) {
return E1.OK;
}
if (CanCallLaserFunction() == false) {
return E1.GENERIC;
}
return _laserYLSSocketConn.PilotLaserOn();
}
public int PilotLaserOff()
{
if (IsSimul) {
return E1.OK;
}
if (CanCallLaserFunction() == false) {
return E1.GENERIC;
}
return _laserYLSSocketConn.PilotLaserOff();
}
public bool GetPilotLaserStatus()
{
if (IsSimul) {
return true;
}
if (CanCallLaserFunction() == false) {
return false;
}
return _laserYLSSocketConn.GetPilotLaserStatus();
}
public bool GetLaserReady()
{
if (IsSimul) {
return true;
}
if (CanCallLaserFunction() == false) {
return false;
}
return _laserYLSSocketConn.GetLaserReady();
}
public bool GetPilotLaserSetBitStatus()
{
if (IsSimul) {
return true;
}
if (CanCallLaserFunction() == false) {
return false;
}
return _laserYLSSocketConn.GetPilotLaserSetBitStatus();
}
public bool GetConnected()
{
if (IsSimul) {
return true;
}
if (CanCallLaserFunction() == false) {
return false;
}
return _laserYLSSocketConn.GetConnected();
}
public int SetData(int nTarget, int value)
{
if (IsSimul) {
return E1.OK;
}
if (CanCallLaserFunction() == false) {
return E1.GENERIC;
}
return _laserYLSSocketConn.SetData(nTarget, value);
}
public int ResetLaser()
{
if (IsSimul) {
return E1.OK;
}
if (CanCallLaserFunction() == false) {
return E1.GENERIC;
}
return _laserYLSSocketConn.ResetLaser();
}
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 GetLaserInterlock()
{
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 List<string> Alarm1String()
{
if (IsSimul) {
return new List<string>();
}
if (CanCallLaserFunction() == false) {
return null;
}
return _laserYLSSocketConn.Alarm1String();
}
public List<string> Alarm2String()
{
if (IsSimul) {
return new List<string>();
}
if (CanCallLaserFunction() == false) {
return null;
}
return _laserYLSSocketConn.Alarm2String();
}
public List<string> StatusString()
{
if (IsSimul) {
return new List<string>();
}
if (CanCallLaserFunction() == false) {
return null;
}
return _laserYLSSocketConn.StatusString();
}
}
}