369 lines
10 KiB
C#
369 lines
10 KiB
C#
using Aurora.Api.Devices;
|
|
using Hermes;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace AuroraLaser
|
|
{
|
|
class LaserRapid : SocketConn, ILaser
|
|
{
|
|
internal bool _IsCommError = false;
|
|
private bool _IsSimul;
|
|
|
|
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 LaserRapid(string deviceid, bool isSimul, SocketProtocol type) : base(deviceid, isSimul, type)
|
|
{
|
|
// Legacy 가 구현이 다 안되있는듯..
|
|
|
|
_IsSimul = isSimul;
|
|
|
|
CloseEvent += new EventHandler<string>(OnForcedCloseEvent);
|
|
ErrorEvent += new EventHandler<Exception>(OnExceptionEvent);
|
|
|
|
}
|
|
public int Open(LaserConfig Config)
|
|
{
|
|
if (_IsSimul)
|
|
return E1.OK;
|
|
var config = Config.ConnConfig as SocketConnConfig;
|
|
return Connect(config);
|
|
}
|
|
public void DisConnect()
|
|
{
|
|
if (_IsSimul)
|
|
return;
|
|
if ((bool)IsConnected()) {
|
|
Close();
|
|
}
|
|
_IsCommError = false;
|
|
return;
|
|
}
|
|
public bool GetConnected()
|
|
{
|
|
if (_IsSimul)
|
|
return false;
|
|
|
|
return IsConnected();
|
|
}
|
|
public int SetData(int nTarget, int value)
|
|
{
|
|
// nTarget 에 따라서 아래의 set 함수들을 연동시키자
|
|
// data type 이 다른것들 처리가 필요하다. 이 함수는 추상함수라서 구현만해두고 실제로는 직접 함수를 연결해서 쓰는게 많을것 같다.
|
|
if (_IsSimul)
|
|
return 0;
|
|
|
|
return value;
|
|
}
|
|
public string GetData(int nTarget)
|
|
{
|
|
if (_IsSimul)
|
|
return null;
|
|
|
|
if (_IsCommError) {
|
|
return null;
|
|
}
|
|
|
|
if (Recieve(out byte[] recieveData, 2000) == E1.OK) {
|
|
return Encoding.Default.GetString(recieveData);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public int LaserOn()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public int LaserOff()
|
|
{
|
|
return 1;
|
|
}
|
|
public int PilotLaserOn()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public int PilotLaserOff()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public bool GetInitCommunication()
|
|
{
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetEmissionStatus()
|
|
{
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetLaserReady()
|
|
{
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetLaserError()
|
|
{
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetWariningStatus()
|
|
{
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
// MAINS_STATUS, ERROR_STATUS 는 위에 있음
|
|
public bool GetPilotLaserStatus()
|
|
{
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public string GetControlMode()
|
|
{
|
|
// 업데이트 예정
|
|
return "";
|
|
}
|
|
public string GetPowerCenter()
|
|
{
|
|
// 업데이트 예정
|
|
return "";
|
|
}
|
|
public string GetPowerRing()
|
|
{
|
|
// 업데이트 예정
|
|
return "";
|
|
}
|
|
#region Set 명령 나간 bit 를 모니터링
|
|
public bool GetStartLaserSetBitStatus()
|
|
{
|
|
|
|
// Laser Start 명령
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetLaserStartSetBitStatus()
|
|
{
|
|
// Laser On 명령. Laser Emission Ready 를 위한 bit
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetPilotLaserSetBitStatus()
|
|
{
|
|
// Pilot Laser On 명령.
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetLaserResetSetBitStatus()
|
|
{
|
|
// Laser Reset 명령.
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
public bool GetControlModeSetStatus()
|
|
{
|
|
// Control mode Local(false) Remote(true)
|
|
// 업데이트 예정
|
|
return false;
|
|
}
|
|
#endregion
|
|
|
|
protected override void OnClose(object sender, AsyncSocketConnectionEventArgs e)
|
|
{
|
|
}
|
|
protected override void OnError(object sender, AsyncSocketErrorEventArgs e)
|
|
{
|
|
}
|
|
|
|
public int SetAlarmReset()
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("FACK=1", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
private void OnExceptionEvent(object sender, Exception e)
|
|
{
|
|
_IsCommError = true;
|
|
}
|
|
|
|
private void OnForcedCloseEvent(object sender, string e)
|
|
{
|
|
_IsCommError = true;
|
|
}
|
|
|
|
public string GetStatus()
|
|
{
|
|
if (_IsCommError) {
|
|
return null;
|
|
}
|
|
|
|
if (SendAndRecieve("?ALL\r\n", out byte[] recieveData, 2000) == E1.OK) {
|
|
return Encoding.Default.GetString(recieveData);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public int SetEmission(bool bEmission)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve(bEmission ? "START" : "STOP", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
public int SetPower(double dPower)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("RL={0:0.0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
public int SetTrigger(int iTrigger)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("PM={0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
public int SetBurst(int iBurst)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("BURST={0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
public int SetRepRate(int iRepRate)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("RRAMPSET={0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
public void UpdateStatus()
|
|
{
|
|
if (_IsSimul)
|
|
return;
|
|
|
|
if (!_IsCommError) {
|
|
return;
|
|
}
|
|
|
|
var status = 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;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|