首次上传
This commit is contained in:
@@ -0,0 +1,515 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using Aitex.Core.Common.DeviceData;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.RT.OperationCenter;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Device.Bases;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.AE
|
||||
{
|
||||
public class AeRfMatch : RfMatchBase
|
||||
{
|
||||
|
||||
public override EnumRfMatchTuneMode TuneMode1
|
||||
{
|
||||
get
|
||||
{
|
||||
return _statusData.Status2.Net1AutoMode ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual;
|
||||
}
|
||||
}
|
||||
|
||||
public override EnumRfMatchTuneMode TuneMode2
|
||||
{
|
||||
get
|
||||
{
|
||||
return _statusData.Status2.Net2AutoMode ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual;
|
||||
}
|
||||
}
|
||||
public override float LoadPosition1
|
||||
{
|
||||
get { return _statusData.LoadPosi1; }
|
||||
}
|
||||
|
||||
public override float LoadPosition2
|
||||
{
|
||||
get { return _statusData.LoadPosi2; }
|
||||
}
|
||||
|
||||
public override float TunePosition1
|
||||
{
|
||||
get { return _statusData.TunePosi1; }
|
||||
}
|
||||
|
||||
public override float TunePosition2
|
||||
{
|
||||
get { return _statusData.TunePosi2; }
|
||||
}
|
||||
public override float BiasPeak
|
||||
{
|
||||
get { return _statusData.BiasPeak; }
|
||||
}
|
||||
|
||||
public override float DCBias
|
||||
{
|
||||
get { return _statusData.DCBias; }
|
||||
}
|
||||
public override AITRfMatchData DeviceData
|
||||
{
|
||||
get
|
||||
{
|
||||
AITRfMatchData data = new AITRfMatchData()
|
||||
{
|
||||
DeviceName = Name,
|
||||
DeviceSchematicId = DeviceID,
|
||||
DisplayName = Display,
|
||||
|
||||
LoadPosition1 = LoadPosition1,
|
||||
LoadPosition2 = LoadPosition2,
|
||||
|
||||
TunePosition1 = TunePosition1,
|
||||
TunePosition2 = TunePosition2,
|
||||
|
||||
TuneMode1 = TuneMode1,
|
||||
TuneMode2 = TuneMode2,
|
||||
|
||||
BiasPeak = BiasPeak,
|
||||
DCBias = DCBias,
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public AeRfMatchConnection Connection
|
||||
{
|
||||
get { return _connection; }
|
||||
}
|
||||
|
||||
private AeRfMatchConnection _connection;
|
||||
|
||||
private byte _deviceAddress ;
|
||||
|
||||
private EnumRfMatchTuneMode _tuneMode1;
|
||||
private EnumRfMatchTuneMode _tuneMode2;
|
||||
|
||||
private RD_TRIG _trigRfOnOff = new RD_TRIG();
|
||||
|
||||
private int _presetNumber;
|
||||
|
||||
private R_TRIG _trigError = new R_TRIG();
|
||||
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
|
||||
private R_TRIG _trigCommunicationError = new R_TRIG();
|
||||
private R_TRIG _trigRetryConnect = new R_TRIG();
|
||||
|
||||
private PeriodicJob _thread;
|
||||
|
||||
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
|
||||
private object _locker = new object();
|
||||
|
||||
private bool _enableLog = true;
|
||||
|
||||
private AEStatusData _statusData;
|
||||
|
||||
public AeRfMatch(string module, string name) : base(module, name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
string portName = SC.GetStringValue($"{ScBasePath}.{Name}.Address");
|
||||
int bautRate = SC.GetValue<int>($"{ScBasePath}.{Name}.BaudRate");
|
||||
int dataBits = SC.GetValue<int>($"{ScBasePath}.{Name}.DataBits");
|
||||
Enum.TryParse(SC.GetStringValue($"{ScBasePath}.{Name}.Parity"), out Parity parity);
|
||||
Enum.TryParse(SC.GetStringValue($"{ScBasePath}.{Name}.StopBits"), out StopBits stopBits);
|
||||
|
||||
_deviceAddress = (byte)SC.GetValue<int>($"{ScBasePath}.{Name}.DeviceAddress");
|
||||
_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
|
||||
|
||||
_connection = new AeRfMatchConnection(portName, bautRate, dataBits, parity, stopBits);
|
||||
_connection.EnableLog(_enableLog);
|
||||
|
||||
if (_connection.Connect())
|
||||
{
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.MatchMode1", (out string reason, int time, object[] args) =>
|
||||
{
|
||||
reason = "";
|
||||
|
||||
if (!Enum.TryParse((string)args[0], out EnumRfMatchTuneMode mode))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not mode, {args[0]} is not a valid mode value");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PerformMatchMode1(out reason, time, mode))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not set mode, {reason}");
|
||||
return false;
|
||||
}
|
||||
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} set match mode1 to {mode}");
|
||||
return true;
|
||||
});
|
||||
OP.Subscribe($"{Module}.{Name}.SetMatchLoad1", (out string reason, int time, object[] args) =>
|
||||
{
|
||||
reason = "";
|
||||
float value = Convert.ToSingle((string)args[0]);
|
||||
|
||||
if (!PerformSetMatchLoad1(out reason, time, value))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not set mode, {reason}");
|
||||
return false;
|
||||
}
|
||||
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} set match load1 to {value}");
|
||||
return true;
|
||||
});
|
||||
OP.Subscribe($"{Module}.{Name}.SetMatchTune1", (out string reason, int time, object[] args) =>
|
||||
{
|
||||
reason = "";
|
||||
float value = Convert.ToSingle((string)args[0]);
|
||||
|
||||
if (!PerformSetMatchTune1(out reason, time, value))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not set mode, {reason}");
|
||||
return false;
|
||||
}
|
||||
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} set match tune1 to {value}");
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.MatchMode2", (out string reason, int time, object[] args) =>
|
||||
{
|
||||
reason = "";
|
||||
|
||||
if (!Enum.TryParse((string)args[0], out EnumRfMatchTuneMode mode))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not mode, {args[0]} is not a valid mode value");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PerformMatchMode2(out reason, time, mode))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not set mode, {reason}");
|
||||
return false;
|
||||
}
|
||||
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} set match mode2 to {mode}");
|
||||
return true;
|
||||
});
|
||||
OP.Subscribe($"{Module}.{Name}.SetMatchLoad2", (out string reason, int time, object[] args) =>
|
||||
{
|
||||
reason = "";
|
||||
float value = Convert.ToSingle((string)args[0]);
|
||||
|
||||
if (!PerformSetMatchLoad2(out reason, time, value))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not set mode, {reason}");
|
||||
return false;
|
||||
}
|
||||
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} set match load2 to {value}");
|
||||
return true;
|
||||
});
|
||||
OP.Subscribe($"{Module}.{Name}.SetMatchTune2", (out string reason, int time, object[] args) =>
|
||||
{
|
||||
reason = "";
|
||||
float value = Convert.ToSingle((string)args[0]);
|
||||
|
||||
if (!PerformSetMatchTune2(out reason, time, value))
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} Can not set mode, {reason}");
|
||||
return false;
|
||||
}
|
||||
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} set match tune2 to {value}");
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool PerformSetMatchTune1(out string reason, int time, float value)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool PerformSetMatchLoad1(out string reason, int time, float value)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool PerformMatchMode1(out string reason, int time, EnumRfMatchTuneMode mode)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool PerformMatchMode2(out string reason, int time, EnumRfMatchTuneMode mode)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool PerformSetMatchLoad2(out string reason, int time, float value)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool PerformSetMatchTune2(out string reason, int time, float value)
|
||||
{
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OnTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
_connection.MonitorTimeout();
|
||||
|
||||
if (!_connection.IsConnected || _connection.IsCommunicationError)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.Clear();
|
||||
}
|
||||
|
||||
_trigRetryConnect.CLK = !_connection.IsConnected;
|
||||
if (_trigRetryConnect.Q)
|
||||
{
|
||||
_connection.SetPortAddress(SC.GetStringValue($"{ScBasePath}.{Name}.Address"));
|
||||
if (!_connection.Connect())
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HandlerBase handler = null;
|
||||
if (!_connection.IsBusy)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (_lstHandler.Count == 0)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchQueryStatusHandler(this, _deviceAddress));
|
||||
}
|
||||
|
||||
if (_lstHandler.Count > 0)
|
||||
{
|
||||
handler = _lstHandler.First.Value;
|
||||
|
||||
_lstHandler.RemoveFirst();
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
_connection.Execute(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Monitor()
|
||||
{
|
||||
try
|
||||
{
|
||||
_connection.EnableLog(_enableLog);
|
||||
|
||||
_trigCommunicationError.CLK = _connection.IsCommunicationError;
|
||||
if (_trigCommunicationError.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal void NotePresetNumber(int presetNumber)
|
||||
{
|
||||
_presetNumber = presetNumber;
|
||||
}
|
||||
|
||||
|
||||
internal void NoteStatus(AEStatusData data)
|
||||
{
|
||||
_statusData = data;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_trigError.RST = true;
|
||||
_trigWarningMessage.RST = true;
|
||||
|
||||
_connection.SetCommunicationError(false, "");
|
||||
_trigCommunicationError.RST = true;
|
||||
|
||||
_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
|
||||
|
||||
_trigRetryConnect.RST = true;
|
||||
|
||||
base.Reset();
|
||||
}
|
||||
|
||||
internal void NoteError(string reason)
|
||||
{
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void SetPreSetsAndTrajectories1(Presets presets)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetPresetHandler(this, _deviceAddress, 1, presets));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetPreSetsAndTrajectories2(Presets presets)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetPresetHandler(this, _deviceAddress, 2, presets));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetActivePresetNo1(int presetNumber)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetActivePresetHandler(this, _deviceAddress, 1, presetNumber));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetActivePresetNo2(int presetNumber)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetActivePresetHandler(this, _deviceAddress, 2, presetNumber));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void EnablePreset1(bool enable)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchEnablePresetHandler(this, _deviceAddress, 1, enable));
|
||||
}
|
||||
}
|
||||
|
||||
public override void EnablePreset2(bool enable)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchEnablePresetHandler(this, _deviceAddress, 2, enable));
|
||||
}
|
||||
}
|
||||
|
||||
public override void EnableCapacitorMove1(bool enable)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchEnableCapMoveHandler(this, _deviceAddress, 1, enable));
|
||||
}
|
||||
}
|
||||
|
||||
public override void EnableCapacitorMove2(bool enable)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchEnableCapMoveHandler(this, _deviceAddress, 2, enable));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetTuneMode1(EnumRfMatchTuneMode mode)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetControlModeHandler(this, _deviceAddress, 1, mode));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetTuneMode2(EnumRfMatchTuneMode mode)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetControlModeHandler(this, _deviceAddress, 2, mode));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetLoad1(float position)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetLoadPositionHandler(this, _deviceAddress, 1, position));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetLoad2(float position)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetLoadPositionHandler(this, _deviceAddress, 2, position));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void SetTune1(float position)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetTunePositionHandler(this, _deviceAddress, 1, position));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void SetTune2(float position)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new AeRfMatchSetTunePositionHandler(this, _deviceAddress, 2, position));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.AE
|
||||
{
|
||||
public class AeRfMatchMessage : BinaryMessage
|
||||
{
|
||||
public byte Header { get; set; }
|
||||
public byte CommandNumber { get; set; }
|
||||
public byte OptionLength { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
public byte CheckSum { get; set; }
|
||||
|
||||
public int Address { get; set; }
|
||||
public int DataLength { get; set; }
|
||||
|
||||
public int MessageLength { get; set; }
|
||||
}
|
||||
|
||||
public class AeRfMatchConnection : SerialPortConnectionBase
|
||||
{
|
||||
private List<byte> _lstCacheBuffer = new List<byte>();
|
||||
|
||||
public AeRfMatchConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
|
||||
: base(portName, baudRate, dataBits, parity, stopBits, "\r", false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool SendMessage(byte[] message)
|
||||
{
|
||||
_lstCacheBuffer.Clear();
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
|
||||
protected override MessageBase ParseResponse(byte[] rawBuffer)
|
||||
{
|
||||
_lstCacheBuffer.AddRange(rawBuffer);
|
||||
|
||||
AeRfMatchMessage msg = new AeRfMatchMessage();
|
||||
msg.RawMessage = rawBuffer;
|
||||
|
||||
if (_lstCacheBuffer.Count >= 1 && _lstCacheBuffer[0] == 0x06)
|
||||
{
|
||||
msg.IsAck = true;
|
||||
_lstCacheBuffer.RemoveAt(0);
|
||||
}
|
||||
|
||||
if (_lstCacheBuffer.Count < 4)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
msg.Header = _lstCacheBuffer[0];
|
||||
msg.CommandNumber = _lstCacheBuffer[1];
|
||||
msg.OptionLength = _lstCacheBuffer[2];
|
||||
msg.Address = _lstCacheBuffer[0] >> 3;
|
||||
msg.DataLength = (byte)(0x07 & _lstCacheBuffer[0]);
|
||||
msg.MessageLength = 3 + msg.DataLength ;//3=包头+Cmd+校验
|
||||
if (msg.DataLength >= 7)
|
||||
{
|
||||
msg.DataLength = _lstCacheBuffer[2];
|
||||
msg.MessageLength = 4 + msg.DataLength ;//4=包头+Cmd+length+校验
|
||||
}
|
||||
|
||||
if (_lstCacheBuffer.Count < msg.MessageLength)
|
||||
return msg;
|
||||
|
||||
msg.Data = _lstCacheBuffer.GetRange(msg.DataLength >= 7 ? 3 : 2, msg.DataLength).ToArray();
|
||||
|
||||
byte sum = 0x00;
|
||||
for (var i = 0; i < msg.MessageLength - 1; i++)
|
||||
{
|
||||
sum ^= _lstCacheBuffer[i];
|
||||
}
|
||||
|
||||
if (_lstCacheBuffer[msg.MessageLength - 1] != sum)
|
||||
{
|
||||
LOG.Error($"check sum failed, ");
|
||||
msg.IsFormatError = true;
|
||||
_lstCacheBuffer.Clear();
|
||||
return msg;
|
||||
}
|
||||
|
||||
msg.IsResponse = true;
|
||||
|
||||
_lstCacheBuffer.RemoveRange(0, msg.MessageLength);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+384
@@ -0,0 +1,384 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Aitex.Core.Common.DeviceData;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.AE
|
||||
{
|
||||
public abstract class AeRfMatchHandler : HandlerBase
|
||||
{
|
||||
public AeRfMatch Device { get; }
|
||||
|
||||
private byte _address;
|
||||
private byte _command;
|
||||
|
||||
protected AeRfMatchHandler(AeRfMatch device, byte address, byte command, byte[] data)
|
||||
: base(BuildMessage(address, command, data))
|
||||
{
|
||||
Device = device;
|
||||
_address = address;
|
||||
_command = command;
|
||||
}
|
||||
|
||||
private static byte[] BuildMessage(byte address, byte command, byte[] data)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
|
||||
buffer.Add((byte)((address << 3) + (data == null ? 0 : data.Length)));
|
||||
|
||||
buffer.Add(command);
|
||||
|
||||
if (data != null && data.Length > 0)
|
||||
{
|
||||
buffer.AddRange(data);
|
||||
}
|
||||
|
||||
buffer.Add(CalcSum(buffer, buffer.Count));
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
//host->unit, unit->host(ack), unit->host(csr), host->unit(ack)
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
AeRfMatchMessage response = msg as AeRfMatchMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
SetState(EnumHandlerState.Acked);
|
||||
}
|
||||
|
||||
if (response.Address != _address || response.CommandNumber != _command)
|
||||
{
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.IsResponse)
|
||||
{
|
||||
if (response.DataLength >= 1)
|
||||
{
|
||||
ParseData(response);
|
||||
}
|
||||
|
||||
SendAck();
|
||||
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual void ParseData(AeRfMatchMessage msg)
|
||||
{
|
||||
if (msg.Data[0] != 0)
|
||||
{
|
||||
var reason = TranslateCsrCode(msg.Data[0]);
|
||||
Device.NoteError(reason);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendAck()
|
||||
{
|
||||
Device.Connection.SendMessage(new byte[] { 0x06 });
|
||||
}
|
||||
|
||||
private static byte CalcSum(List<byte> data, int length)
|
||||
{
|
||||
byte ret = 0x00;
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
ret ^= data[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected string TranslateCsrCode(int csrCode)
|
||||
{
|
||||
string ret = csrCode.ToString();
|
||||
switch (csrCode)
|
||||
{
|
||||
case 0:
|
||||
ret = null;//"Command accepted";
|
||||
break;
|
||||
case 1:
|
||||
ret = "Control Code Is Incorrect";
|
||||
break;
|
||||
case 2:
|
||||
ret = "Output Is On(Change Not Allowed)";
|
||||
break;
|
||||
case 4:
|
||||
ret = "Data Is Out Of Range";
|
||||
break;
|
||||
case 7:
|
||||
ret = "Active Fault(s) Exist";
|
||||
break;
|
||||
case 9:
|
||||
ret = "Data Byte Count Is Incorrect";
|
||||
break;
|
||||
case 19:
|
||||
ret = "Recipe Is Active(Change Not Allowed)";
|
||||
break;
|
||||
case 50:
|
||||
ret = "The Frequency Is Out Of Range";
|
||||
break;
|
||||
case 51:
|
||||
ret = "The Duty Cycle Is Out Of Range";
|
||||
break;
|
||||
case 53:
|
||||
ret = "The Device Controlled By The Command Is Not Detected";
|
||||
break;
|
||||
case 99:
|
||||
ret = "Command Not Accepted(There Is No Such Command)";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
//91 set active preset number
|
||||
public class AeRfMatchSetActivePresetHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchSetActivePresetHandler(AeRfMatch device, byte address, byte network, int number)
|
||||
: base(device, address, 91, BuildData(network, number))
|
||||
{
|
||||
Name = "set active preset number";
|
||||
}
|
||||
private static byte[] BuildData(byte network, int number)
|
||||
{
|
||||
return new byte[] { network, 0, (byte)number, 0 };
|
||||
}
|
||||
}
|
||||
|
||||
//92 set preset
|
||||
public class AeRfMatchSetPresetHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchSetPresetHandler(AeRfMatch device, byte address, byte network, Presets data)
|
||||
: base(device, address, 92, BuildData(network, data))
|
||||
{
|
||||
Name = "set active preset number";
|
||||
}
|
||||
private static byte[] BuildData(byte network, Presets data)
|
||||
{
|
||||
List<byte> lstData = new List<byte>();
|
||||
lstData.AddRange(new byte[]{ network, 0, data.PreNo, data.TraSum });
|
||||
|
||||
int tempdata = (int)(data.LoadData * 100);
|
||||
lstData.Add((byte)tempdata);
|
||||
lstData.Add((byte)(tempdata >> 8));
|
||||
|
||||
tempdata = (int)(data.TuneData * 100);
|
||||
lstData.Add((byte)tempdata);
|
||||
lstData.Add((byte)(tempdata >> 8));
|
||||
for (int i = 0; i < data.TraSum; i++)
|
||||
{
|
||||
tempdata = (int)(data.TraData[i, 0] * 100);
|
||||
lstData.Add((byte)tempdata);
|
||||
lstData.Add((byte)(tempdata >> 8));
|
||||
tempdata = (int)(data.TraData[i, 1] * 100);
|
||||
lstData.Add((byte)tempdata);
|
||||
lstData.Add((byte)(tempdata >> 8));
|
||||
}
|
||||
|
||||
return lstData.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
//93 control mode
|
||||
public class AeRfMatchSetControlModeHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchSetControlModeHandler(AeRfMatch device, byte address, byte network, EnumRfMatchTuneMode mode)
|
||||
: base(device, address, 93, BuildData(network, mode))
|
||||
{
|
||||
Name = "Set control mode";
|
||||
}
|
||||
|
||||
private static byte[] BuildData(byte network, EnumRfMatchTuneMode mode)
|
||||
{
|
||||
byte setpoint = 0;
|
||||
switch (mode)
|
||||
{
|
||||
case EnumRfMatchTuneMode.Auto:
|
||||
setpoint = 1;
|
||||
break;
|
||||
case EnumRfMatchTuneMode.Manual:
|
||||
setpoint = 2;
|
||||
break;
|
||||
}
|
||||
return new byte[]{network, 0, setpoint, 0};
|
||||
}
|
||||
}
|
||||
|
||||
//94 enable presets
|
||||
public class AeRfMatchEnablePresetHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchEnablePresetHandler(AeRfMatch device, byte address, byte network, bool enable)
|
||||
: base(device, address, 94, BuildData(network, enable))
|
||||
{
|
||||
Name = "enable preset";
|
||||
}
|
||||
|
||||
private static byte[] BuildData(byte network, bool enable)
|
||||
{
|
||||
return new byte[] { network, 0, enable?(byte)0x1: (byte)0x0, 0 };
|
||||
}
|
||||
}
|
||||
|
||||
//98 enable motor move
|
||||
public class AeRfMatchEnableCapMoveHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchEnableCapMoveHandler(AeRfMatch device, byte address, byte network, bool enable)
|
||||
: base(device, address, 98, BuildData(network, enable))
|
||||
{
|
||||
Name = "enable motor move";
|
||||
}
|
||||
private static byte[] BuildData(byte network, bool enable)
|
||||
{
|
||||
return new byte[] { network, 0, enable ? (byte)0x1 : (byte)0x0, 0 };
|
||||
}
|
||||
}
|
||||
|
||||
//112 set load position
|
||||
public class AeRfMatchSetLoadPositionHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchSetLoadPositionHandler(AeRfMatch device, byte address, byte network, float position)
|
||||
: base(device, address, 112, BuildData(network, position))
|
||||
{
|
||||
Name = "set load position";
|
||||
}
|
||||
private static byte[] BuildData(byte network, float position)
|
||||
{
|
||||
int iposi = (int)(position * 100);
|
||||
return new byte[] { network, 0, (byte)iposi, (byte)(iposi >> 8) };
|
||||
}
|
||||
}
|
||||
|
||||
//122 set tune position
|
||||
public class AeRfMatchSetTunePositionHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchSetTunePositionHandler(AeRfMatch device, byte address, byte network, float position)
|
||||
: base(device, address, 122, BuildData(network, position))
|
||||
{
|
||||
Name = "set tune position";
|
||||
}
|
||||
private static byte[] BuildData(byte network, float position)
|
||||
{
|
||||
int iposi = (int)(position * 100);
|
||||
return new byte[] { network, 0, (byte)iposi, (byte)(iposi >> 8) };
|
||||
}
|
||||
}
|
||||
|
||||
//161 query preset no
|
||||
public class AeRfMatchQueryPresetNumberHandler : AeRfMatchHandler
|
||||
{
|
||||
public AeRfMatchQueryPresetNumberHandler(AeRfMatch device, byte address)
|
||||
: base(device, address, 161, null)
|
||||
{
|
||||
Name = "query preset mode";
|
||||
}
|
||||
protected override void ParseData(AeRfMatchMessage response)
|
||||
{
|
||||
if (response.DataLength != 4)
|
||||
{
|
||||
Device.NoteError($"{Name}, return data length {response.DataLength}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NotePresetNumber(response.Data[2] + (response.Data[3] << 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//219 query status
|
||||
public class AeRfMatchQueryStatusHandler : AeRfMatchHandler
|
||||
{
|
||||
private AEStatusData _statusData;
|
||||
|
||||
public AeRfMatchQueryStatusHandler(AeRfMatch device, byte address)
|
||||
: base(device, address, 219, null)
|
||||
{
|
||||
Name = "query status";
|
||||
}
|
||||
protected override void ParseData(AeRfMatchMessage response)
|
||||
{
|
||||
if (response.DataLength != 88)
|
||||
{
|
||||
Device.NoteError($"{Name}, return data length {response.DataLength}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var retData = response.Data;
|
||||
_statusData = new AEStatusData();
|
||||
|
||||
_statusData.LoadPosi1 = (retData[4] + (retData[5] << 8)) / 100f;
|
||||
_statusData.TunePosi1 = (retData[6] + (retData[7] << 8)) / 100f;
|
||||
_statusData.LoadPosi2 = (retData[12] + (retData[13] << 8)) / 100f;
|
||||
_statusData.TunePosi2 = (retData[14] + (retData[15] << 8)) / 100f;
|
||||
_statusData.BiasPeak = (retData[20] + (retData[21] << 8)) / 100f;
|
||||
_statusData.DCBias = (retData[22] + (retData[23] << 8)) / 100f;
|
||||
_statusData.ZScanII.R1 = BitConverter.ToSingle(retData.ToArray(), 40);
|
||||
_statusData.ZScanII.X1 = BitConverter.ToSingle(retData.ToArray(), 44);
|
||||
_statusData.ZScanII.Voltage1 = BitConverter.ToSingle(retData.ToArray(), 48) * 1.41421f;
|
||||
_statusData.ZScanII.Current1 = BitConverter.ToSingle(retData.ToArray(), 52);
|
||||
_statusData.ZScanII.Phase1 = BitConverter.ToSingle(retData.ToArray(), 56);
|
||||
_statusData.ZScanII.Power1 = BitConverter.ToSingle(retData.ToArray(), 60);
|
||||
_statusData.ZScanII.R2 = BitConverter.ToSingle(retData.ToArray(), 64);
|
||||
_statusData.ZScanII.X2 = BitConverter.ToSingle(retData.ToArray(), 68);
|
||||
_statusData.ZScanII.Voltage2 = BitConverter.ToSingle(retData.ToArray(), 72);
|
||||
_statusData.ZScanII.Current2 = BitConverter.ToSingle(retData.ToArray(), 76);
|
||||
_statusData.ZScanII.Phase2 = BitConverter.ToSingle(retData.ToArray(), 80);
|
||||
_statusData.ZScanII.Power2 = BitConverter.ToSingle(retData.ToArray(), 84);
|
||||
AnalysisAEMatchStatus(retData);
|
||||
|
||||
Device.NoteStatus(_statusData);
|
||||
}
|
||||
}
|
||||
|
||||
private void AnalysisAEMatchStatus(byte[] sts)
|
||||
{
|
||||
_statusData.Status2.Net1OutPutOn = ((sts[0] >> 0) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net1OutPutTuned = ((sts[0] >> 1) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2OutPutOn = ((sts[0] >> 2) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2OutPutTuned = ((sts[0] >> 3) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.Net2OutPutOn = ((sts[0] >> 4) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.Net2OutPutTuned = ((sts[0] >> 5) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net1PresetsActive = ((sts[0] >> 6) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net1ExtPresetsSelected = ((sts[0] >> 7) & 0x01) == 0x01 ? true : false;
|
||||
|
||||
_statusData.Status2.Low24VDetected = ((sts[1] >> 0) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.OverTempDetected = ((sts[1] >> 1) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.InterlockOpen = ((sts[1] >> 2) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.FanFault = ((sts[1] >> 3) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net1AutoMode = ((sts[1] >> 4) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net1HostCtrlMode = ((sts[1] >> 5) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2AutoMode = ((sts[1] >> 6) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2HostCtrlMode = ((sts[1] >> 7) & 0x01) == 0x01 ? true : false;
|
||||
|
||||
_statusData.Status2.AuxCapOutputTuned = ((sts[2] >> 0) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.AuxCapAutoModed = ((sts[2] >> 1) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.AuxCapPresetsActive = ((sts[2] >> 2) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.FanFault = ((sts[1] >> 3) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.Net1AutoMode = ((sts[1] >> 4) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net1UserCtrlMode = ((sts[2] >> 5) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2UserCtrlMode = ((sts[2] >> 6) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.Net2HostCtrlMode = ((sts[2] >> 7) & 0x01) == 0x01 ? true : false;
|
||||
|
||||
_statusData.Status2.Faults = ((sts[3] >> 0) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Warning = ((sts[3] >> 1) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.InitMotorFailed = ((sts[3] >> 2) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2PresetsActive = ((sts[3] >> 3) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.Net2ExtPresetsSelected = ((sts[3] >> 4) & 0x01) == 0x01 ? true : false;
|
||||
_statusData.Status2.VoltageOverLimitFault = ((sts[3] >> 5) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.Net2AutoMode = ((sts[3] >> 6) & 0x01) == 0x01 ? true : false;
|
||||
//RecvData.Status2.Net2HostCtrlMode = ((sts[3] >> 7) & 0x01) == 0x01 ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.AE
|
||||
{
|
||||
public struct AENavigatorMatchSts
|
||||
{
|
||||
public bool Net1OutPutOn;
|
||||
public bool Net1OutPutTuned;
|
||||
public bool Net2OutPutOn;
|
||||
public bool Net2OutPutTuned;
|
||||
public bool Net1PresetsActive;
|
||||
public bool Net1ExtPresetsSelected;
|
||||
|
||||
public bool Low24VDetected;
|
||||
public bool OverTempDetected;
|
||||
public bool InterlockOpen;
|
||||
public bool FanFault;
|
||||
public bool Net1AutoMode;
|
||||
public bool Net1HostCtrlMode;
|
||||
public bool Net2AutoMode;
|
||||
public bool Net2HostCtrlMode;
|
||||
|
||||
public bool AuxCapOutputTuned;
|
||||
public bool AuxCapAutoModed;
|
||||
public bool AuxCapPresetsActive;
|
||||
public bool Net1UserCtrlMode;
|
||||
public bool Net2UserCtrlMode;
|
||||
|
||||
public bool Faults;
|
||||
public bool Warning;
|
||||
public bool InitMotorFailed;
|
||||
public bool Net2PresetsActive;
|
||||
public bool Net2ExtPresetsSelected;
|
||||
public bool VoltageOverLimitFault;
|
||||
}
|
||||
public struct AENavioMatchSts
|
||||
{
|
||||
public bool RF_On;
|
||||
public bool Tuned;
|
||||
public bool AutoMode;
|
||||
public bool SerialMode;
|
||||
public bool AnalogMode;
|
||||
public bool EnPresets;
|
||||
public bool GenFaultSts;
|
||||
public bool PresetAct;
|
||||
public bool EnMotorMove;
|
||||
public bool Low24VFault;
|
||||
public bool NOVRAMFault;
|
||||
public bool OverTFault;
|
||||
public bool TuneVFault;
|
||||
public bool OutputIFault;
|
||||
public bool MotorInitFault;
|
||||
}
|
||||
public struct AEMatchZScanII
|
||||
{
|
||||
public float R1;
|
||||
public float X1;
|
||||
public float Voltage1;
|
||||
public float Current1;
|
||||
public float Phase1;
|
||||
public float Power1;
|
||||
public float R2;
|
||||
public float X2;
|
||||
public float Voltage2;
|
||||
public float Current2;
|
||||
public float Phase2;
|
||||
public float Power2;
|
||||
}
|
||||
public struct AEStatusData
|
||||
{
|
||||
public float BiasPeak; //RF峰值
|
||||
public float DCBias; //偏压值
|
||||
public float LoadPosi1; //Load电容位置
|
||||
public float TunePosi1; //Tune电容位置
|
||||
public float LoadPosi2; //Load电容位置
|
||||
public float TunePosi2; //Tune电容位置
|
||||
public float PreLoad1; //Load电容位置
|
||||
public float PreTune1; //Tune电容位置
|
||||
|
||||
public AENavioMatchSts Status1; //当前状态
|
||||
public AENavigatorMatchSts Status2; //当前状态
|
||||
public AEMatchZScanII ZScanII;
|
||||
public bool Online; //设备在线
|
||||
}
|
||||
}
|
||||
+912
@@ -0,0 +1,912 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Comet
|
||||
{
|
||||
public class CometRFMatch : SerialPortDevice, IConnection
|
||||
{
|
||||
public string Address { get { return _address; } }
|
||||
|
||||
public bool IsConnected { get; }
|
||||
public bool Connect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Disconnect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public string PortStatus { get; set; } = "Closed";
|
||||
|
||||
private CometRFMatchConnection _connection;
|
||||
public CometRFMatchConnection Connection
|
||||
{
|
||||
get { return _connection; }
|
||||
}
|
||||
|
||||
private R_TRIG _trigError = new R_TRIG();
|
||||
|
||||
private R_TRIG _trigCommunicationError = new R_TRIG();
|
||||
private R_TRIG _trigRetryConnect = new R_TRIG();
|
||||
|
||||
private PeriodicJob _thread;
|
||||
|
||||
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
|
||||
private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
|
||||
|
||||
public List<IOResponse> IOResponseList { get; set; } = new List<IOResponse>();
|
||||
|
||||
|
||||
private object _locker = new object();
|
||||
|
||||
private bool _enableLog;
|
||||
private string _address;
|
||||
private string _scRoot;
|
||||
public CometRFMatch(string module, string name, string scRoot, string portName) : base(module, name)
|
||||
{
|
||||
_scRoot = scRoot;
|
||||
PortName = portName;
|
||||
}
|
||||
private void ResetPropertiesAndResponses()
|
||||
{
|
||||
|
||||
foreach (var ioResponse in IOResponseList)
|
||||
{
|
||||
ioResponse.ResonseContent = null;
|
||||
ioResponse.ResonseRecievedTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Initialize(string portName)
|
||||
{
|
||||
base.Initialize(portName);
|
||||
|
||||
ResetPropertiesAndResponses();
|
||||
|
||||
if (_connection != null && _connection.IsConnected && PortName == portName)
|
||||
return true;
|
||||
|
||||
if (_connection != null && _connection.IsConnected)
|
||||
_connection.Disconnect();
|
||||
|
||||
PortName = portName;
|
||||
|
||||
_address = SC.GetStringValue($"{_scRoot}.{Module}.{Name}.DeviceAddress");
|
||||
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
|
||||
_connection = new CometRFMatchConnection(PortName);
|
||||
_connection.EnableLog(_enableLog);
|
||||
|
||||
if (_connection.Connect())
|
||||
{
|
||||
PortStatus = "Open";
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InitConnection(string portName, int bautRate, int dataBits, Parity parity, StopBits stopBits)
|
||||
{
|
||||
|
||||
_connection = new CometRFMatchConnection(portName, bautRate, dataBits, parity, stopBits);
|
||||
|
||||
if (_connection.Connect())
|
||||
{
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OnTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
//_connection.MonitorTimeout();
|
||||
|
||||
if (!_connection.IsConnected || _connection.IsCommunicationError)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.Clear();
|
||||
}
|
||||
|
||||
_trigRetryConnect.CLK = !_connection.IsConnected;
|
||||
if (_trigRetryConnect.Q)
|
||||
{
|
||||
_connection.SetPortAddress(SC.GetStringValue($"{ScBasePath}.{Name}.Address"));
|
||||
if (!_connection.Connect())
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//_lstHandler.AddLast(new CommetRFMatchQueryPinHandler(this, _deviceAddress));
|
||||
//_lstHandler.AddLast(new CommetRFMatchSetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HandlerBase handler = null;
|
||||
if (!_connection.IsBusy)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (_lstHandler.Count == 0)
|
||||
{
|
||||
foreach (var monitorHandler in _lstMonitorHandler)
|
||||
{
|
||||
_lstHandler.AddLast(monitorHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (_lstHandler.Count > 0)
|
||||
{
|
||||
handler = _lstHandler.First.Value;
|
||||
|
||||
_lstHandler.RemoveFirst();
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
_connection.Execute(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void NoteNAK(ResponseNAK nak)
|
||||
{
|
||||
ResponseNAK = nak;
|
||||
}
|
||||
|
||||
|
||||
public override void Monitor()
|
||||
{
|
||||
try
|
||||
{
|
||||
//_connection.EnableLog(_enableLog);
|
||||
|
||||
|
||||
_trigCommunicationError.CLK = _connection.IsCommunicationError;
|
||||
if (_trigCommunicationError.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_trigError.RST = true;
|
||||
|
||||
_connection.SetCommunicationError(false, "");
|
||||
_trigCommunicationError.RST = true;
|
||||
|
||||
//_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
|
||||
|
||||
_trigRetryConnect.RST = true;
|
||||
|
||||
base.Reset();
|
||||
}
|
||||
|
||||
public override bool Home(out string reason)
|
||||
{
|
||||
return base.Home(out reason);
|
||||
}
|
||||
|
||||
|
||||
#region Command Functions
|
||||
|
||||
public void PerformRawCommand(string command, string completeEvent, string comandArgument)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchRawCommandHandler(this, command, completeEvent, comandArgument));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void TriggerFullRefRun()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "10,00", "10,01", "FullRefRunCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerGotoCap()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "20,00", "20,01", "GotoCapCompleted"));
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerGotoFullStepPos()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "21,00", "21,01", "GotoFullStepPosCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerMoveFullSteps()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "22,00", "22,01", "MoveFullStepsCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerGotoCmin()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "23,00", "23,01", "GotoCminCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerGotoCmax()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "24,00", "24,01", "GotoCmaxCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerGotoMicroStepPos()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "25,00", "25,01", "GotoMicroStepPosCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerMoveMicroSteps()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "26,00", "26,01", "MoveMicroStepsCompleted"));
|
||||
}
|
||||
}
|
||||
public void TriggerGotoStoredPos()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchTriggerHandler(this, "27,00", "27,01", "GotoStoredPosCompleted"));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAccelerationSpeedIndex(byte acceleration, byte speed)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "43,00", acceleration.ToString("X2") + "," + speed.ToString("X2")));
|
||||
}
|
||||
}
|
||||
public void SetAccelerationSpeedIndex(string acceleration, string speed)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "43,00", acceleration + "," + speed));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCurrent(byte idleCurrent, byte driveCurrent)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "45,00", idleCurrent.ToString("X2") + "," + driveCurrent.ToString("X2")));
|
||||
}
|
||||
}
|
||||
public void SetCurrent(string idleCurrent, string driveCurrent)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "45,00", idleCurrent + "," + driveCurrent));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLowerCustomerLimit(short lowerLimit)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "72,01", lowerLimit));
|
||||
}
|
||||
}
|
||||
public void SetLowerCustomerLimit(string lowerLimit)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "72,01", short.Parse(lowerLimit)));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetUpperCustomerLimit(short upperLimit)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "72,02", upperLimit));
|
||||
}
|
||||
}
|
||||
public void SetUpperCustomerLimit(string upperLimit)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "72,02", short.Parse(upperLimit)));
|
||||
}
|
||||
}
|
||||
|
||||
public void StoreIndexedPosition(byte index, short positon)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "75,00", index, positon));
|
||||
}
|
||||
}
|
||||
public void StoreIndexedPosition(string index, string positon)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CommetRFMatchSetHandler(this, "75,00", byte.Parse(index), short.Parse(positon)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double ActualCap { get; set; }
|
||||
public void GetActualCap(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ActualCap";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetDoubleValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetDoubleValueHandler(this, "40,01", "41,01", propName, 0.1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short ActualFullStepPos { get; set; }
|
||||
public void GetActualFullStepPos(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ActualFullStepPos";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetShortValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetShortValueHandler(this, "40,02", "41,02", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double MinimumCap { get; set; }
|
||||
public void GetMinimumCap(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "MinimumCap";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetDoubleValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetDoubleValueHandler(this, "40,10", "41,10", propName, 0.1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public double MaximumCap { get; set; }
|
||||
public void GetMaximumCap(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "MaximumCap";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetDoubleValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetDoubleValueHandler(this, "40,11", "41,11", propName, 0.1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short MinimumFullStepPos { get; set; }
|
||||
public void GetMinimumFullStepPos(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "MinimumFullStepPos";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetShortValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetShortValueHandler(this, "40,12", "41,12", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public short MaximumFullStepPos { get; set; }
|
||||
public void GetMaximumFullStepPos(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "MaximumFullStepPos";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetShortValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetShortValueHandler(this, "40,13", "41,13", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//parse
|
||||
public short AccelerationSpeed { get; set; }
|
||||
public void GetAccelerationSpeed(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "AccelerationSpeed";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetShortValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetShortValueHandler(this, "40,21", "41,21", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//parse
|
||||
public int Status { get; set; }
|
||||
public void GetStatus(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "Status";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetDoubleValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetShortValueHandler(this, "40,22", "41,22", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//need special handler ??
|
||||
public short CcurveIndexedFullStepCap { get; set; }
|
||||
public void GetCcurveIndexedFullStepCap(bool isSelected, int tableIndex)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "CcurveIndexedFullStepCap";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetShortValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetShortValueHandler(this, "40,30", "41,30", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public byte ControllerTemp { get; set; }
|
||||
public void GetControllerTemp(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ControllerTemp";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetByteValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetByteValueHandler(this, "40,32", "41,32", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public uint MicroStepPos { get; set; }
|
||||
public void GetMicroStepPos(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "MicroStepPos";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetIntValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetIntValueHandler(this, "40,36", "41,36", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public double CminNom { get; set; }
|
||||
public void GetCminNom(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "CminNom";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetDoubleValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetDoubleValueHandler(this, "40,70", "41,70", propName, 0.1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public double CmaxNom { get; set; }
|
||||
public void GetCmaxNom(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "CmaxNom";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetDoubleValueHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetDoubleValueHandler(this, "40,11", "41,11", propName, 0.1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double LowerCustomerLimit { get; set; }
|
||||
public void GetLowerCustomerLimit(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "LowerCustomerLimit";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetLimitHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetLimitHandler(this, "40,72", "41,72", propName,"01"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public double UpperCustomerLimit { get; set; }
|
||||
public void GetUpperCustomerLimit(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "UpperCustomerLimit";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetLimitHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetLimitHandler(this, "40,72", "41,72", propName, "02"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public double LowerFactoryLimit { get; set; }
|
||||
public void GetLowerFactoryLimit(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "LowerFactoryLimit";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetLimitHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetLimitHandler(this, "40,72", "41,72", propName, "03"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public double UpperFactoryLimit { get; set; }
|
||||
public void GetUpperFactoryLimit(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "UpperFactoryLimit";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetLimitHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetLimitHandler(this, "40,72", "41,72", propName, "04"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double PresetCap { get; set; }
|
||||
public void GetPresetCap(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "PresetCap";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGetLimitHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGetLimitHandler(this, "40,73", "41,73", propName, "00"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short PresetFullStepPos { get; set; }
|
||||
public void GetPresetFullStepPos(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "PresetFullStepPos";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGet3ByteHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGet3ByteHandler(this, "40,73", "41,73", propName, "01"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public short StoredFullStepPos { get; set; }
|
||||
public void GetStoredFullStepPos(bool isSelected, int index)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "PresetFullStepPos";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchGet3ByteHandler) && ((CometRFMatchHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchGet3ByteHandler(this, "40,75", "41,75", propName, index.ToString("X2")));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MonitorRawCommand(bool isSelected, string command, string completeEvent, string comandArgument)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(CommetRFMatchRawCommandHandler) && ((CometRFMatchHandler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new CommetRFMatchRawCommandHandler(this, command, completeEvent, comandArgument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public string Error { get; private set; }
|
||||
|
||||
|
||||
public ResponseNAK ResponseNAK { get; private set; }
|
||||
public bool FullRefRunCompleted { get; private set; }
|
||||
public bool GotoCapCompleted { get; private set; }
|
||||
public bool GotoFullStepPosCompleted { get; private set; }
|
||||
public bool MoveFullStepsCompleted { get; private set; }
|
||||
public bool GotoCminCompleted { get; private set; }
|
||||
public bool GotoCmaxCompleted { get; private set; }
|
||||
public bool GotoMicroStepPosCompleted { get; private set; }
|
||||
public bool MoveMicroStepsCompleted { get; private set; }
|
||||
public bool GotoStoredPosCompleted { get; private set; }
|
||||
|
||||
public byte Acceleration { get; private set; }
|
||||
public byte SpeedIndex { get; private set; }
|
||||
public bool SetCommandCompleted { get; private set; }
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Note Functions
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
|
||||
|
||||
|
||||
public void NoteError(string reason)
|
||||
{
|
||||
if (reason != null)
|
||||
{
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
}
|
||||
Error = reason;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void NoteRawCommandInfo(string command, string data)
|
||||
{
|
||||
var curIOResponse = IOResponseList.Find(res => res.SourceCommandName == command);
|
||||
if (curIOResponse != null)
|
||||
{
|
||||
IOResponseList.Remove(curIOResponse);
|
||||
}
|
||||
IOResponseList.Add(new IOResponse() { SourceCommand = command, ResonseContent = data, ResonseRecievedTime = DateTime.Now });
|
||||
}
|
||||
internal void NoteSetComplted()
|
||||
{
|
||||
SetCommandCompleted = true;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum ResponseNAK
|
||||
{
|
||||
NotNak,
|
||||
CommandNotDefined,
|
||||
CheckSumFailed,
|
||||
PositionOverLimit,
|
||||
IndexOutOfRange
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Comet
|
||||
{
|
||||
|
||||
public class CometRFMatchMessage : BinaryMessage
|
||||
{
|
||||
public string Command { get; set; }
|
||||
public string ErrorCode { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
|
||||
public class CometRFMatchConnection : SerialPortConnectionBase
|
||||
{
|
||||
|
||||
private static byte _start = 0xAA;
|
||||
private static byte _address = 0x21;
|
||||
|
||||
|
||||
|
||||
public CometRFMatchConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
|
||||
: base(portName, baudRate, dataBits, parity, stopBits, "", false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool SendMessage(byte[] message)
|
||||
{
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
protected override MessageBase ParseResponse(byte[] rawMessage)
|
||||
{
|
||||
|
||||
CometRFMatchMessage msg = new CometRFMatchMessage();
|
||||
msg.RawMessage = rawMessage;
|
||||
//msg.Data = rawMessage;
|
||||
|
||||
if (rawMessage.Length < 4)
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid response");
|
||||
return msg;
|
||||
}
|
||||
|
||||
if (rawMessage[0] != _start )
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid start byte");
|
||||
return msg;
|
||||
}
|
||||
if (rawMessage[1] != _address)
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid address byte");
|
||||
return msg;
|
||||
}
|
||||
|
||||
byte checkSum = 0;
|
||||
for (int i = 0; i < rawMessage.Length-1; i++)
|
||||
{
|
||||
checkSum += rawMessage[i];
|
||||
}
|
||||
var recSum = rawMessage[rawMessage.Length - 1];
|
||||
if (recSum != checkSum)
|
||||
{
|
||||
LOG.Error($"check sum failed,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
//command&data
|
||||
msg.Data = rawMessage.Skip(2).Take(rawMessage.Length - 3).ToArray();
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
+618
@@ -0,0 +1,618 @@
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Comet
|
||||
{
|
||||
|
||||
public enum RFMatchResponseResult
|
||||
{
|
||||
InvalidResonse,
|
||||
TriggerAck,
|
||||
TriggerNAK,
|
||||
CheckInProcess,
|
||||
CheckCompleted
|
||||
}
|
||||
public abstract class CometRFMatchHandler : HandlerBase
|
||||
{
|
||||
public CometRFMatch Device { get; }
|
||||
|
||||
public string _command;
|
||||
protected string _parameter;
|
||||
protected string _completeEvent;
|
||||
|
||||
|
||||
|
||||
protected CometRFMatchHandler(CometRFMatch device, string command, string completeEvent, string parameter)
|
||||
: base(BuildMessage(StringToByteArray(command), StringToByteArray(parameter)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_completeEvent = completeEvent;
|
||||
_parameter = parameter;
|
||||
_address = Convert.ToByte(Device.Address, 16);
|
||||
Name = command;
|
||||
}
|
||||
|
||||
protected CometRFMatchHandler(CometRFMatch device, string command)
|
||||
: base(BuildMessage(StringToByteArray(command)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_address = Convert.ToByte(Device.Address, 16);
|
||||
Name = command;
|
||||
}
|
||||
|
||||
|
||||
protected CometRFMatchHandler(CometRFMatch device, string command, string parameter)
|
||||
: base(BuildMessage(StringToByteArray(command), StringToByteArray(parameter)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter;
|
||||
_address = Convert.ToByte(Device.Address, 16);
|
||||
Name = command;
|
||||
}
|
||||
|
||||
protected CometRFMatchHandler(CometRFMatch device, string command, byte[] parameter)
|
||||
: base(BuildMessage(StringToByteArray(command), parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
//_parameter = parameter;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
private static byte _start = 0xAA;
|
||||
private static byte _address = 0x21;
|
||||
|
||||
protected static byte[] BuildMessage(byte[] commandArray, byte[] argumentArray = null)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
|
||||
buffer.Add(_start);
|
||||
buffer.Add(_address);
|
||||
|
||||
if (commandArray != null && commandArray.Length > 0)
|
||||
{
|
||||
buffer.AddRange(commandArray);
|
||||
}
|
||||
if (argumentArray != null && argumentArray.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray);
|
||||
}
|
||||
byte checkSum = 0;
|
||||
for(int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
checkSum += buffer[i];
|
||||
}
|
||||
buffer.Add(checkSum);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
protected static byte[] BuildMessage(string commandStr, byte[] argumentArray = null)
|
||||
{
|
||||
byte[] commandArray = StringToByteArray(commandStr);
|
||||
List<byte> buffer = new List<byte>();
|
||||
|
||||
buffer.Add(_start);
|
||||
buffer.Add(_address);
|
||||
|
||||
if (commandArray != null && commandArray.Length > 0)
|
||||
{
|
||||
buffer.AddRange(commandArray);
|
||||
}
|
||||
if (argumentArray != null && argumentArray.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray);
|
||||
}
|
||||
byte checkSum = 0;
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
checkSum += buffer[i];
|
||||
}
|
||||
buffer.Add(checkSum);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
||||
protected static byte[] BuildByteArray(byte para1, short para2)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
buffer.Add(para1);
|
||||
buffer.AddRange(IntToByteArray(para2));
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
//public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
//{
|
||||
// CometRFMatchMessage response = msg as CometRFMatchMessage;
|
||||
// ResponseMessage = msg;
|
||||
|
||||
// string reponseData = string.Join(",", response.Data.Select(bt => bt.ToString("X2")).ToArray());
|
||||
// if(_completeEvent.Contains("|"))
|
||||
// {
|
||||
// var eventArray = _completeEvent.Split('|');
|
||||
// var subRes = reponseData.Substring(0, eventArray[0].Length);
|
||||
// if(!eventArray.Contains(subRes))
|
||||
// {
|
||||
// Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
// msg.IsFormatError = true;
|
||||
|
||||
// transactionComplete = false;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// else if (reponseData.IndexOf(_completeEvent) == -1)
|
||||
// {
|
||||
// Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
// msg.IsFormatError = true;
|
||||
|
||||
// transactionComplete = false;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
// if (response.IsAck)
|
||||
// {
|
||||
// SetState(EnumHandlerState.Acked);
|
||||
// }
|
||||
// if (this.IsAcked && response.IsComplete)
|
||||
// {
|
||||
// SetState(EnumHandlerState.Completed);
|
||||
// transactionComplete = true;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// transactionComplete = false;
|
||||
// return false;
|
||||
//}
|
||||
|
||||
|
||||
protected ResponseNAK CheckNak(string reponseData)
|
||||
{
|
||||
if (reponseData.IndexOf("90") >= 0)
|
||||
{
|
||||
return ResponseNAK.CommandNotDefined;
|
||||
}
|
||||
if (reponseData.IndexOf("92") >= 0)
|
||||
{
|
||||
return ResponseNAK.CheckSumFailed;
|
||||
}
|
||||
if (reponseData.IndexOf("93") >= 0)
|
||||
{
|
||||
return ResponseNAK.PositionOverLimit;
|
||||
}
|
||||
if (reponseData.IndexOf("93") >= 0)
|
||||
{
|
||||
return ResponseNAK.IndexOutOfRange;
|
||||
}
|
||||
|
||||
return ResponseNAK.NotNak;
|
||||
}
|
||||
bool _startWaitCheckResonse = false;
|
||||
protected RFMatchResponseResult HandleTriggerMessage(MessageBase msg)
|
||||
{
|
||||
CometRFMatchMessage response = msg as CometRFMatchMessage;
|
||||
|
||||
string triggerAck = "50";
|
||||
string[] checkResponseArray = new string[] { "53", "52", "51" };
|
||||
|
||||
string reponseData = string.Join(",", response.Data.Select(bt => bt.ToString("X2")).ToArray());
|
||||
|
||||
if (!_startWaitCheckResonse)
|
||||
{
|
||||
if (reponseData.IndexOf(triggerAck) >= 0)
|
||||
{
|
||||
_startWaitCheckResonse = true;
|
||||
return RFMatchResponseResult.TriggerAck;
|
||||
}
|
||||
else if (CheckNak(reponseData) != ResponseNAK.NotNak)
|
||||
{
|
||||
Device.NoteNAK(CheckNak(reponseData));
|
||||
return RFMatchResponseResult.TriggerNAK;
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
msg.IsFormatError = true;
|
||||
return RFMatchResponseResult.InvalidResonse;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var subRes = reponseData.Substring(0, checkResponseArray[0].Length);
|
||||
if (checkResponseArray.Contains(subRes))
|
||||
{
|
||||
if(subRes == checkResponseArray[2])
|
||||
{
|
||||
return RFMatchResponseResult.CheckCompleted;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RFMatchResponseResult.CheckInProcess;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
msg.IsFormatError = true;
|
||||
return RFMatchResponseResult.InvalidResonse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected bool HandleSetMessage(MessageBase msg)
|
||||
{
|
||||
CometRFMatchMessage response = msg as CometRFMatchMessage;
|
||||
|
||||
string setOK = _command;
|
||||
string[] checkResponseArray = new string[] { "53", "52", "51" };
|
||||
|
||||
string reponseData = string.Join(",", response.Data.Select(bt => bt.ToString("X2")).ToArray());
|
||||
if (reponseData.IndexOf(setOK) >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (CheckNak(reponseData) != ResponseNAK.NotNak)
|
||||
{
|
||||
Device.NoteNAK(CheckNak(reponseData));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
msg.IsFormatError = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool HandleGetMessage(MessageBase msg)
|
||||
{
|
||||
CometRFMatchMessage response = msg as CometRFMatchMessage;
|
||||
|
||||
string setOK = _completeEvent;
|
||||
string reponseData = string.Join(",", response.Data.Select(bt => bt.ToString("X2")).ToArray());
|
||||
if (reponseData.IndexOf(setOK) >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
msg.IsFormatError = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static byte[] StringToByteArray(string parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
return new byte[] { };
|
||||
|
||||
return parameter.Split(',').Select(para => Convert.ToByte(para, 16)).ToArray();
|
||||
}
|
||||
protected static byte[] IntToByteArray(int num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
protected static byte[] ShortToByteArray(short num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
protected uint ByteArrayToUInt(byte[] bytes)
|
||||
{
|
||||
uint temp = BitConverter.ToUInt32(bytes.Reverse().ToArray(), 0);
|
||||
return temp;
|
||||
}
|
||||
protected short ByteArrayToShort(byte[] bytes)
|
||||
{
|
||||
short temp = BitConverter.ToInt16(bytes.Reverse().ToArray(), 0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
protected void SetDevicePropValue<T>(string propName, T value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Type objType = Device.GetType();
|
||||
objType.GetProperty(propName).SetValue(Device, value, null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public string DevicePropName;
|
||||
}
|
||||
|
||||
public class CommetRFMatchRawCommandHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchRawCommandHandler(CometRFMatch device, string command, string completeEvent, string parameter)
|
||||
: base(device, command, completeEvent, parameter)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
CometRFMatchMessage response = msg as CometRFMatchMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
string reponseData = string.Join(",", response.Data.Select(bt => bt.ToString("X2")).ToArray());
|
||||
if (_completeEvent.Contains("|"))
|
||||
{
|
||||
var eventArray = _completeEvent.Split('|');
|
||||
var subRes = reponseData.Substring(0, eventArray[0].Length);
|
||||
if (!eventArray.Contains(subRes))
|
||||
{
|
||||
Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
msg.IsFormatError = true;
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (reponseData.IndexOf(_completeEvent) == -1)
|
||||
{
|
||||
Device.NoteError($"Invalid response, no expected command feedback: {reponseData}");
|
||||
msg.IsFormatError = true;
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
else if (CheckNak(reponseData) != ResponseNAK.NotNak)
|
||||
{
|
||||
Device.NoteNAK(CheckNak(reponseData));
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
SetState(EnumHandlerState.Acked);
|
||||
}
|
||||
if (this.IsAcked && response.IsComplete)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
Device.NoteRawCommandInfo(_command, string.Join(",", response.RawMessage.Select(bt => bt.ToString("X2")).ToArray()));
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommetRFMatchTriggerHandler : CometRFMatchHandler
|
||||
{
|
||||
string _checkCommand;
|
||||
public CommetRFMatchTriggerHandler(CometRFMatch device, string triggerCommand, string checkCommand, string propName)
|
||||
: base(device, triggerCommand)
|
||||
{
|
||||
_checkCommand = checkCommand;
|
||||
DevicePropName = propName;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var resonseResult = HandleTriggerMessage(msg);
|
||||
if (resonseResult == RFMatchResponseResult.TriggerAck || resonseResult == RFMatchResponseResult.CheckInProcess)
|
||||
{
|
||||
Device.Connection.SendMessage(BuildMessage(_checkCommand, null));
|
||||
}
|
||||
else if (resonseResult == RFMatchResponseResult.CheckCompleted)
|
||||
{
|
||||
SetDevicePropValue<bool>(DevicePropName, true);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
else if (resonseResult == RFMatchResponseResult.TriggerNAK || resonseResult == RFMatchResponseResult.InvalidResonse)
|
||||
{
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class CommetRFMatchSetHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchSetHandler(CometRFMatch device,string command, string parameter)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
|
||||
public CommetRFMatchSetHandler(CometRFMatch device, string command, short parameter)
|
||||
: base(device, command, ShortToByteArray(parameter))
|
||||
{
|
||||
}
|
||||
public CommetRFMatchSetHandler(CometRFMatch device, string command, byte para1, short para2)
|
||||
: base(device, command, BuildByteArray(para1, para2))
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleSetMessage(msg))
|
||||
{
|
||||
Device.NoteSetComplted();
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class CommetRFMatchGet3ByteHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchGet3ByteHandler(CometRFMatch device, string command, string completeEvent, string propName, string parameter)
|
||||
: base(device, command, completeEvent, parameter)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleGetMessage(msg))
|
||||
{
|
||||
var result = msg as CometRFMatchMessage;
|
||||
|
||||
if (result.Data[3].ToString("X2") != _parameter)
|
||||
{
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
short oriValue = ByteArrayToShort(result.Data.Skip(3).ToArray());
|
||||
SetDevicePropValue<short>(DevicePropName, oriValue);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class CommetRFMatchGetLimitHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchGetLimitHandler(CometRFMatch device, string command, string completeEvent, string propName, string parameter)
|
||||
: base(device, command, completeEvent, parameter)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleGetMessage(msg))
|
||||
{
|
||||
var result = msg as CometRFMatchMessage;
|
||||
|
||||
if (result.Data[3].ToString("X2") != _parameter)
|
||||
{
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
short oriValue = ByteArrayToShort(result.Data.Skip(3).ToArray());
|
||||
SetDevicePropValue<double>(DevicePropName, oriValue * 0.1);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class CommetRFMatchGetDoubleValueHandler : CometRFMatchHandler
|
||||
{
|
||||
double _factor = 1.0f;
|
||||
public CommetRFMatchGetDoubleValueHandler(CometRFMatch device, string command, string completeEvent, string propName, double factor)
|
||||
: base(device, command, completeEvent, null)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
_factor = factor;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleGetMessage(msg))
|
||||
{
|
||||
var result = msg as CometRFMatchMessage;
|
||||
short oriValue = ByteArrayToShort(result.Data.Skip(2).ToArray());
|
||||
SetDevicePropValue<double>(DevicePropName, oriValue * _factor);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommetRFMatchGetIntValueHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchGetIntValueHandler(CometRFMatch device, string command, string completeEvent, string propName)
|
||||
: base(device, command, completeEvent, null)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleGetMessage(msg))
|
||||
{
|
||||
var result = msg as CometRFMatchMessage;
|
||||
uint oriValue = ByteArrayToUInt(result.Data.Skip(2).ToArray());
|
||||
SetDevicePropValue<uint>(DevicePropName, oriValue);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommetRFMatchGetShortValueHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchGetShortValueHandler(CometRFMatch device, string command, string completeEvent, string propName)
|
||||
: base(device, command, completeEvent, null)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleGetMessage(msg))
|
||||
{
|
||||
var result = msg as CometRFMatchMessage;
|
||||
short oriValue = ByteArrayToShort(result.Data.Skip(2).ToArray());
|
||||
SetDevicePropValue<short>(DevicePropName, oriValue);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommetRFMatchGetByteValueHandler : CometRFMatchHandler
|
||||
{
|
||||
public CommetRFMatchGetByteValueHandler(CometRFMatch device, string command, string completeEvent, string propName)
|
||||
: base(device, command, completeEvent, null)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleGetMessage(msg))
|
||||
{
|
||||
var result = msg as CometRFMatchMessage;
|
||||
SetDevicePropValue<byte>(DevicePropName, result.Data[2]);
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
using Aitex.Core.Common.DeviceData;
|
||||
using Aitex.Core.RT.DataCenter;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.RT.OperationCenter;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Device.Bases;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Kaimei
|
||||
{
|
||||
public class KaimeiRFMatch : RfMatchBase, IConnection
|
||||
{
|
||||
public string Address => Connection.Address;
|
||||
public bool IsConnected => Connection.IsConnected && !_connection.IsCommunicationError;
|
||||
public bool Connect()
|
||||
{
|
||||
return _connection.Connect();
|
||||
}
|
||||
|
||||
public bool Disconnect()
|
||||
{
|
||||
return _connection.Disconnect();
|
||||
}
|
||||
|
||||
public byte SlaveAddress { get; private set; } = 0x01;
|
||||
|
||||
public string PortStatus { get; set; } = "Closed";
|
||||
|
||||
private KaimeiRFMatchConnection _connection;
|
||||
public KaimeiRFMatchConnection Connection
|
||||
{
|
||||
get { return _connection; }
|
||||
}
|
||||
public override AITRfMatchData DeviceData
|
||||
{
|
||||
get
|
||||
{
|
||||
return new AITRfMatchData()
|
||||
{
|
||||
Module = Module,
|
||||
DeviceName = Name,
|
||||
DisplayName = Name,
|
||||
TuneMode1 = TuneMode1,
|
||||
TunePosition1 = TunePosition1,
|
||||
LoadPosition1 = LoadPosition1,
|
||||
LoadPosition1SetPoint = LoadPosition1Setpoint,
|
||||
TunePosition1SetPoint = TunePosition1Setpoint,
|
||||
TuneRange = (float)SC.GetValue<double>($"{Module}.{Name}.TuneRange"),
|
||||
LoadRange = (float)SC.GetValue<double>($"{Module}.{Name}.LoadRange"),
|
||||
IsInterlockOk = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private R_TRIG _trigError = new R_TRIG();
|
||||
|
||||
private R_TRIG _trigCommunicationError = new R_TRIG();
|
||||
private R_TRIG _trigRetryConnect = new R_TRIG();
|
||||
|
||||
private PeriodicJob _thread;
|
||||
|
||||
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
|
||||
private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
|
||||
private DeviceTimer _QueryTimer = new DeviceTimer();
|
||||
private readonly int _QueryInterval = 2000;
|
||||
|
||||
private object _locker = new object();
|
||||
private bool _enableLog;
|
||||
private string _address;
|
||||
private string _scRoot;
|
||||
public KaimeiRFMatch(string module, string name, string scRoot) : base(module, name)
|
||||
{
|
||||
_scRoot = scRoot;
|
||||
|
||||
}
|
||||
|
||||
public override bool Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_address = SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address");
|
||||
_enableLog = SC.GetValue<bool>($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.EnableLogMessage");
|
||||
_connection = new KaimeiRFMatchConnection(_address);
|
||||
_connection.EnableLog(_enableLog);
|
||||
|
||||
if (_connection.Connect())
|
||||
{
|
||||
PortStatus = "Open";
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
//_lstMonitorHandler.AddLast(new CommetRFMatchGetActualCapHandler(this));
|
||||
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
_QueryTimer.Start(_QueryInterval);
|
||||
_lstMonitorHandler.AddLast(new KaimeiRFMatchGetStatusHandler(this));
|
||||
|
||||
DATA.Subscribe($"{Module}.{Name}.IsConnected", () => IsConnected);
|
||||
DATA.Subscribe($"{Module}.{Name}.Address", () => Address);
|
||||
OP.Subscribe($"{Module}.{Name}.Reconnect", (string cmd, object[] args) =>
|
||||
{
|
||||
Disconnect();
|
||||
Connect();
|
||||
return true;
|
||||
});
|
||||
|
||||
//for recipe
|
||||
OP.Subscribe($"{Module}.{Name}.SetLoad1", (out string reason, int time, object[] param) =>
|
||||
{
|
||||
reason = string.Empty;
|
||||
if (TuneMode1Setpoint != EnumRfMatchTuneMode.Auto)
|
||||
SetLoad1(Convert.ToSingle(param[0]));
|
||||
return true;
|
||||
});
|
||||
|
||||
//for recipe
|
||||
OP.Subscribe($"{Module}.{Name}.SetTune1", (out string reason, int time, object[] param) =>
|
||||
{
|
||||
reason = string.Empty;
|
||||
if (TuneMode1Setpoint != EnumRfMatchTuneMode.Auto)
|
||||
SetTune1(Convert.ToSingle(param[0]));
|
||||
return true;
|
||||
});
|
||||
|
||||
//for recipe
|
||||
OP.Subscribe($"{Module}.{Name}.SetTuneMode1", (out string reason, int time, object[] param) =>
|
||||
{
|
||||
reason = string.Empty;
|
||||
SetTuneMode1(param[0].ToString().ToUpper() == "AUTO" ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual);
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.SavePreset", (function, args) =>
|
||||
{
|
||||
SavePreset();
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OnTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
_connection.MonitorTimeout();
|
||||
|
||||
if (!_connection.IsConnected || _connection.IsCommunicationError)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.Clear();
|
||||
}
|
||||
|
||||
_trigRetryConnect.CLK = !_connection.IsConnected;
|
||||
if (_trigRetryConnect.Q)
|
||||
{
|
||||
_connection.SetPortAddress(SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address"));
|
||||
if (!_connection.Connect())
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//_lstHandler.AddLast(new CommetRFMatchQueryPinHandler(this, _deviceAddress));
|
||||
//_lstHandler.AddLast(new CommetRFMatchSetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HandlerBase handler = null;
|
||||
if (!_connection.IsBusy)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (_lstHandler.Count == 0)
|
||||
{
|
||||
if (_QueryTimer.IsTimeout())
|
||||
{
|
||||
foreach (var monitorHandler in _lstMonitorHandler)
|
||||
{
|
||||
_lstHandler.AddLast(monitorHandler);
|
||||
}
|
||||
_QueryTimer.Start(_QueryInterval);
|
||||
}
|
||||
}
|
||||
|
||||
if (_lstHandler.Count > 0)
|
||||
{
|
||||
handler = _lstHandler.First.Value;
|
||||
|
||||
_lstHandler.RemoveFirst();
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
_connection.Execute(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Monitor()
|
||||
{
|
||||
try
|
||||
{
|
||||
//_connection.EnableLog(_enableLog);
|
||||
|
||||
_trigCommunicationError.CLK = _connection.IsCommunicationError;
|
||||
if (_trigCommunicationError.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
|
||||
}
|
||||
|
||||
base.Monitor();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_trigError.RST = true;
|
||||
|
||||
_connection.SetCommunicationError(false, "");
|
||||
_trigCommunicationError.RST = true;
|
||||
|
||||
//_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
|
||||
|
||||
_trigRetryConnect.RST = true;
|
||||
|
||||
base.Reset();
|
||||
}
|
||||
|
||||
#region Command Functions
|
||||
internal void NoteActualCap(float value)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SetTuneMode1(EnumRfMatchTuneMode enumRfMatchTuneMode)
|
||||
{
|
||||
TuneMode1Setpoint = enumRfMatchTuneMode;
|
||||
|
||||
//if (SC.ContainsItem("System.IsSimulatorMode") && SC.GetValue<bool>("System.IsSimulatorMode"))
|
||||
// TuneMode1 = TuneMode1Setpoint;
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new KaimeiRFMatchPresetValveHandler(this, TuneMode1Setpoint, TunePosition1Setpoint, LoadPosition1Setpoint));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetLoad1(float load)
|
||||
{
|
||||
LoadPosition1Setpoint = load;
|
||||
|
||||
//if (SC.ContainsItem("System.IsSimulatorMode") && SC.GetValue<bool>("System.IsSimulatorMode"))
|
||||
// LoadPosition1 = LoadPosition1Setpoint;
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new KaimeiRFMatchPresetValveHandler(this, TuneMode1Setpoint, TunePosition1Setpoint, LoadPosition1Setpoint));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetTune1(float tune)
|
||||
{
|
||||
TunePosition1Setpoint = tune;
|
||||
|
||||
//if (SC.ContainsItem("System.IsSimulatorMode") && SC.GetValue<bool>("System.IsSimulatorMode"))
|
||||
// TunePosition1 = TunePosition1Setpoint;
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new KaimeiRFMatchPresetValveHandler(this, TuneMode1Setpoint, TunePosition1Setpoint, LoadPosition1Setpoint));
|
||||
}
|
||||
}
|
||||
|
||||
public void SavePreset()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new KaimeiRFMatchSetCurrentValveHandler(this));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public string Error { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Note Functions
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
|
||||
public void NoteError(string reason)
|
||||
{
|
||||
if (reason != null)
|
||||
{
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
}
|
||||
Error = reason;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Kaimei
|
||||
{
|
||||
public class KaimeiRFMatchMessage : BinaryMessage
|
||||
{
|
||||
public string Command { get; set; }
|
||||
public string ErrorCode { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
|
||||
public class KaimeiRFMatchConnection : SerialPortConnectionBase
|
||||
{
|
||||
private List<byte> _msgBuffer = new List<byte>();
|
||||
|
||||
public KaimeiRFMatchConnection(string portName, int baudRate = 38400, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
|
||||
: base(portName, baudRate, dataBits, parity, stopBits, "", false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool SendMessage(byte[] message)
|
||||
{
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
protected override MessageBase ParseResponse(byte[] rawMessage)
|
||||
{
|
||||
KaimeiRFMatchMessage msg = new KaimeiRFMatchMessage();
|
||||
if (rawMessage == null || rawMessage.Length < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_msgBuffer.AddRange(rawMessage);
|
||||
if (_msgBuffer.Count < 5)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
if(_msgBuffer[1] == 0x03)
|
||||
{
|
||||
var dataLength = _msgBuffer[2];
|
||||
if(_msgBuffer.Count < 3 + dataLength + 2)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.RawMessage = _msgBuffer.Take(3 + dataLength + 2).ToArray();
|
||||
msg.Data = _msgBuffer.Skip(3).Take(dataLength).ToArray();
|
||||
_msgBuffer.RemoveRange(0, msg.RawMessage.Length);
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
else if(_msgBuffer[1] == 0x10)
|
||||
{
|
||||
//SlaveAddress,FunctionCode,StartingAddressHigh,StartingAddressLow,NumberAddressHigh,NumberAddressLow,CRC,CRC
|
||||
if(_msgBuffer.Count < 8)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.RawMessage = _msgBuffer.Take(8).ToArray();
|
||||
_msgBuffer.RemoveRange(0, msg.RawMessage.Length);
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid response");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
using Aitex.Core.Common.DeviceData;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Kaimei
|
||||
{
|
||||
public abstract class KaimeiRFMatchHandler : HandlerBase
|
||||
{
|
||||
public KaimeiRFMatch Device { get; }
|
||||
|
||||
public string _command;
|
||||
protected string _parameter;
|
||||
|
||||
protected KaimeiRFMatchHandler(KaimeiRFMatch device, string command)
|
||||
: base(BuildMessage(ToByteArray(command)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
|
||||
protected KaimeiRFMatchHandler(KaimeiRFMatch device, string command, ushort parameter)
|
||||
: base(BuildMessage(ToByteArray(command), UshortToByteArray(parameter)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter.ToString();
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
protected KaimeiRFMatchHandler(KaimeiRFMatch device, string command, string parameter1, ushort parameter2, ushort parameter3)
|
||||
: base(BuildMessage(ToByteArray(command), ToByteArray(parameter1), UshortToByteArray(parameter2), UshortToByteArray(parameter3)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = $"{parameter1},{parameter2},{parameter3}";
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
protected KaimeiRFMatchHandler(KaimeiRFMatch device, string command, string parameter)
|
||||
: base(BuildMessage(ToByteArray(command), ToByteArray(parameter)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter;
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
protected KaimeiRFMatchHandler(KaimeiRFMatch device, string command, byte[] parameter)
|
||||
: base(BuildMessage(ToByteArray(command), parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
//_parameter = parameter;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
private static byte _address = 0x01;
|
||||
|
||||
protected static byte[] BuildMessage(byte[] commandArray, byte[] argumentArray1 = null, byte[] argumentArray2 = null, byte[] argumentArray3 = null)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
|
||||
buffer.Add(_address);
|
||||
|
||||
if (commandArray != null && commandArray.Length > 0)
|
||||
{
|
||||
buffer.AddRange(commandArray);
|
||||
}
|
||||
if (argumentArray1 != null && argumentArray1.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray1);
|
||||
}
|
||||
if (argumentArray2 != null && argumentArray2.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray2.Reverse());
|
||||
}
|
||||
if (argumentArray3 != null && argumentArray3.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray3.Reverse());
|
||||
}
|
||||
var checkSum = Crc16.CRC16_ModbusRTU(buffer.ToArray());
|
||||
var ret = BitConverter.GetBytes(checkSum);
|
||||
buffer.AddRange(ret);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
protected bool HandleMessage(MessageBase msg)
|
||||
{
|
||||
KaimeiRFMatchMessage response = msg as KaimeiRFMatchMessage;
|
||||
if (!response.IsComplete)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static string Ushort2String(ushort num)
|
||||
{
|
||||
var bytes = UshortToByteArray(num);
|
||||
return string.Join(",", bytes,0);
|
||||
}
|
||||
|
||||
protected static byte[] ToByteArray(string parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
return new byte[] { };
|
||||
|
||||
return parameter.Split(',').Select(para => Convert.ToByte(para, 16)).ToArray();
|
||||
}
|
||||
protected static byte[] IntToByteArray(int num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected static byte[] UshortToByteArray(ushort num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected static byte[] ShortToByteArray(short num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected int ByteArrayToInt(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 4)
|
||||
{
|
||||
int temp = BitConverter.ToInt32(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
protected short ByteArrayToShort(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 2)
|
||||
{
|
||||
short temp = BitConverter.ToInt16(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected ushort ByteArrayToUshort(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 2)
|
||||
{
|
||||
ushort temp = BitConverter.ToUInt16(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class KaimeiRFMatchSetCurrentValveHandler : KaimeiRFMatchHandler
|
||||
{
|
||||
public KaimeiRFMatchSetCurrentValveHandler(KaimeiRFMatch device)
|
||||
: base(device, "10", $"00,08,00,02,04,FF,FF,FF,FF")
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as KaimeiRFMatchMessage;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class KaimeiRFMatchPresetValveHandler : KaimeiRFMatchHandler
|
||||
{
|
||||
public KaimeiRFMatchPresetValveHandler(KaimeiRFMatch device, EnumRfMatchTuneMode mode, float tune, float load)
|
||||
: base(device, "10", $"00,05,00,03,06,{(mode == EnumRfMatchTuneMode.Auto ? "00,00":"00,01")}", (ushort)((0x1 << 12) + (((int)tune * 10) & 0x0FFF)), (ushort)((0x1 << 12) + (((int)load * 10) & 0x0FFF)))
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as KaimeiRFMatchMessage;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class KaimeiRFMatchGetStatusHandler : KaimeiRFMatchHandler
|
||||
{
|
||||
public KaimeiRFMatchGetStatusHandler(KaimeiRFMatch device)
|
||||
: base(device, "03", "00,00,00,06")
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as KaimeiRFMatchMessage;
|
||||
var datas = result.Data.ToList();
|
||||
if (datas.Count == 12)//ox00 no error
|
||||
{
|
||||
var tuneArray = datas.Skip(6).Take(2).Reverse().ToArray();
|
||||
var loadArray = datas.Skip(8).Take(2).Reverse().ToArray();
|
||||
var modeArray = datas.Skip(10).Take(2).Reverse().ToArray();
|
||||
|
||||
Device.TunePosition1 = BitConverter.ToInt16(tuneArray,0)/10.0f;
|
||||
Device.LoadPosition1 = BitConverter.ToInt16(loadArray, 0)/10.0f;
|
||||
Device.TuneMode1 = modeArray[1] == 0x00 ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual;
|
||||
|
||||
var reason = string.Empty;
|
||||
Device.NoteError(reason);
|
||||
}
|
||||
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user