131 lines
3.3 KiB
C#
131 lines
3.3 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Hermes;
|
|
using System;
|
|
using System.Text;
|
|
|
|
namespace AuroraLaser.Coherent
|
|
{
|
|
internal class LaserRapidLXTcp : SocketConn
|
|
{
|
|
internal bool _IsCommError = false;
|
|
internal LaserRapidLXTcp(string deviceId, bool isSimul = false) : base(deviceId, isSimul)
|
|
{
|
|
CloseEvent += new EventHandler<string>(OnForcedCloseEvent);
|
|
ErrorEvent += new EventHandler<Exception>(OnExceptionEvent);
|
|
}
|
|
|
|
private void OnExceptionEvent(object sender, Exception e)
|
|
{
|
|
_IsCommError = true;
|
|
}
|
|
|
|
private void OnForcedCloseEvent(object sender, string e)
|
|
{
|
|
_IsCommError = true;
|
|
}
|
|
|
|
public int OnInit(IConnConfig config)
|
|
{
|
|
_IsCommError = false;
|
|
return Connect(config as SocketConnConfig); // Socket comm
|
|
}
|
|
|
|
public int OnClose()
|
|
{
|
|
if ((bool)IsConnected()) {
|
|
return Close();
|
|
}
|
|
_IsCommError = false;
|
|
return E1.OK;
|
|
}
|
|
|
|
protected override void OnClose(object sender, AsyncSocketConnectionEventArgs e)
|
|
{
|
|
}
|
|
protected override void OnError(object sender, AsyncSocketErrorEventArgs e)
|
|
{
|
|
}
|
|
|
|
internal int SetAlarmReset()
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("FACK=1", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
internal string GetStatus()
|
|
{
|
|
if (_IsCommError) {
|
|
return null;
|
|
}
|
|
|
|
if (SendAndRecieve("?ALL\r\n", out byte[] recieveData, 2000) == E1.OK) {
|
|
return Encoding.Default.GetString(recieveData);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
internal int SetEmission(bool bEmission)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve(bEmission ? "START" : "STOP", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
internal int SetPower(double dPower)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("RL={0:0.0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
internal int SetTrigger(int iTrigger)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("PM={0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
internal int SetBurst(int iBurst)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("BURST={0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
internal int SetRepRate(int iRepRate)
|
|
{
|
|
if (_IsCommError) {
|
|
return E2.NOT_CONNECTED;
|
|
}
|
|
|
|
return SendAndRecieve("RRAMPSET={0}", out byte[] recieveData, 2000);
|
|
}
|
|
|
|
internal string GetData()
|
|
{
|
|
if (_IsCommError) {
|
|
return null;
|
|
}
|
|
|
|
if (Recieve(out byte[] recieveData, 2000) == E1.OK) {
|
|
return Encoding.Default.GetString(recieveData);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|