using Aurora.Api; using Aurora.Api.Devices; using AuroraLaser.Amplitude.Satsuma; using AuroraLaser.IPG; using AuroraLaser.IPG.YLS; using Hermes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AuroraLaser.Trumpf.TruDisk { public class LaserDeviceTruDisk : Device, ILaserDeviceTrumpf { protected Logger Log = new Logger("LaserDeviceYLS"); public LaserTruDiskConfig Config { get; set; } private LaserTruDiskSocketConn _laserTruDiskSocketConn; public LaserDeviceTruDisk(string deviceId) { CommType = CommunicationType.Socket; DeviceId = deviceId; } protected override int DoActivate(IDeviceConfig config) { Config = config as LaserTruDiskConfig; return ActivateDevice(); //Config = config as LaserTruDiskConfig; //if (IsActivated) { // return E1.OK; //} //if (Config.IsSimul) { // return E1.OK; //} //_laserTruDiskSocketConn = new LaserTruDiskSocketConn(DeviceId, IsSimul, SocketProtocol.TCP); //if (_laserTruDiskSocketConn == null) { // Log.E(string.Format("LaserObj is Null")); // return E1.ARGUMENT; //} //return _laserTruDiskSocketConn.Open(Config.ConnConfig as SocketConnConfig); } protected override int DoDeactivate() { return DeactivateDevice(); //if (IsSimul) { // return E1.OK; //} //if (_laserTruDiskSocketConn != null) { // _laserTruDiskSocketConn.DisConnect(); //} //return E1.OK; } public int ActivateDevice() { if (IsActivated) { return E1.OK; } if (IsSimul) { return E1.OK; } _laserTruDiskSocketConn = new LaserTruDiskSocketConn(DeviceId, IsSimul, SocketProtocol.TCP); if (_laserTruDiskSocketConn == null) { Log.E(string.Format("LaserObj is Null")); return E1.ARGUMENT; } return _laserTruDiskSocketConn.Open(Config.ConnConfig as SocketConnConfig); } public int DeactivateDevice() { if (IsSimul) { return E1.OK; } if (_laserTruDiskSocketConn != null) { _laserTruDiskSocketConn.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 (_laserTruDiskSocketConn == null) { return false; } return true; } public int LaserOn() { if (IsSimul) { return E1.OK; } if (CanCallLaserFunction() == false) { return E1.GENERIC; } int result = _laserTruDiskSocketConn.SetLaserOn(true); if (result != 1) { return E1.GENERIC; } return E1.OK; } public int LaserOff() { if (IsSimul) { return E1.OK; } if (CanCallLaserFunction() == false) { return E1.GENERIC; } int result = _laserTruDiskSocketConn.SetLaserOn(false); if (result != 1) { return E1.GENERIC; } return E1.OK; } public int PilotLaserOn() { if (IsSimul) { return E1.OK; } if (CanCallLaserFunction() == false) { return E1.GENERIC; } int result = _laserTruDiskSocketConn.SetData(csWriteNodeNo.PILOT_LASER_ON, 1); if (result != 1) { return E1.GENERIC; } return E1.OK; } public int PilotLaserOff() { if (IsSimul) { return E1.OK; } if (CanCallLaserFunction() == false) { return E1.GENERIC; } int result = _laserTruDiskSocketConn.SetData(csWriteNodeNo.PILOT_LASER_ON, 0); if (result != 1) { return E1.GENERIC; } return E1.OK; } // MAINS_STATUS, ERROR_STATUS 는 위에 있음 public bool GetPilotLaserStatus() { if (IsSimul) { return true; } if (CanCallLaserFunction() == false) { return false; } // 업데이트 예정 return false; } public bool GetLaserReady() { if (IsSimul) { return true; } if (CanCallLaserFunction() == false) { return false; } return _laserTruDiskSocketConn.GetLaserReady(); } public bool GetPilotLaserSetBitStatus() { if (IsSimul) { return true; } if (CanCallLaserFunction() == false) { return false; } // Pilot Laser On 명령. // 업데이트 예정 return false; } public bool GetConnected() { if (IsSimul) { return true; } if (CanCallLaserFunction() == false) { return false; } return _laserTruDiskSocketConn.GetConnected(); } public int SetData(int nTarget, int value) { if (IsSimul) { return 1; } if (CanCallLaserFunction() == false) { return 0; } return _laserTruDiskSocketConn.SetData(nTarget, value); } public int ResetLaser() { if (IsSimul) { return E1.OK; } if (CanCallLaserFunction() == false) { return E1.GENERIC; } // 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(); } } }