首次上传
This commit is contained in:
+371
@@ -0,0 +1,371 @@
|
||||
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;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.KITZ
|
||||
{
|
||||
public class KITZThrottleValve : ThrottleValveBase
|
||||
{
|
||||
#region properties
|
||||
|
||||
|
||||
public int TVAlarm
|
||||
{
|
||||
get
|
||||
{
|
||||
//return _aiThrottleValveAlarm.Value;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override AITThrottleValveData DeviceData
|
||||
{
|
||||
get
|
||||
{
|
||||
AITThrottleValveData data = new AITThrottleValveData()
|
||||
{
|
||||
DeviceName = Name,
|
||||
DeviceSchematicId = DeviceID,
|
||||
DisplayName = Display,
|
||||
UnitPressure = "Torr",
|
||||
UnitPosition = "%",
|
||||
Module = Module,
|
||||
|
||||
PositionFeedback = PositionFeedback,
|
||||
PressureFeedback = PressureFeedback,
|
||||
PressureSetPoint = PressureSetPoint,
|
||||
PositionSetPoint = PositionSetPoint,
|
||||
MaxValuePressure = PressureRange,
|
||||
MaxValuePosition = 100,
|
||||
Mode = (int)Mode,
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public double PressureRange
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_scPressureRange == null)
|
||||
return 0;
|
||||
return _scPressureRange.DoubleValue;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsError
|
||||
{
|
||||
get { return _errorCode != 0; }
|
||||
}
|
||||
|
||||
public int DBNumber { get; private set; } = 6;
|
||||
#endregion
|
||||
private KITZConnection _connection;
|
||||
|
||||
|
||||
private const int VlaveClose = 1;
|
||||
private const int VlaveOpen = 2;
|
||||
private const int VlavePositionControl = 3;
|
||||
private const int VlavePressureControl = 4;
|
||||
|
||||
private int _errorCode;
|
||||
|
||||
private RD_TRIG _trigPumpOnOff = new RD_TRIG();
|
||||
private R_TRIG _trigError = new R_TRIG();
|
||||
private R_TRIG _trigOverTemp = new R_TRIG();
|
||||
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
private string _lastError = string.Empty;
|
||||
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 bool _isFirstTime = true;
|
||||
|
||||
private SCConfigItem _scPressureRange;
|
||||
|
||||
public KITZThrottleValve(string module, string name) : base(module, name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_scPressureRange = SC.GetConfigItem($"{Module}.{Name}.PressureRange");
|
||||
|
||||
//for recipe
|
||||
OP.Subscribe($"{Module}.{Name}.SetPressure", (out string reason, int time, object[] param) =>
|
||||
{
|
||||
reason = string.Empty;
|
||||
SetPressure(Convert.ToSingle(param[0]));
|
||||
return true;
|
||||
});
|
||||
|
||||
string portName = SC.GetStringValue($"{Module}.{Name}.Address");
|
||||
_enableLog = SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
|
||||
|
||||
_connection = new KITZConnection(portName);
|
||||
_connection.EnableLog(_enableLog);
|
||||
|
||||
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($"{Module}.{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)
|
||||
{
|
||||
if(_isFirstTime)
|
||||
{
|
||||
_lstHandler.AddFirst(new RemoteHandler(this));
|
||||
_lstHandler.AddLast(new CalibrationHandler(this));
|
||||
Mode = PressureCtrlMode.TVCalib;
|
||||
_isFirstTime = false;
|
||||
}
|
||||
_lstHandler.AddLast(new QueryStateHandler(this));
|
||||
|
||||
if(Mode != PressureCtrlMode.TVCalib)
|
||||
{
|
||||
_lstHandler.AddLast(new QueryPressureHandler(this));
|
||||
|
||||
_lstHandler.AddLast(new QueryPositionHandler(this));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
_trigError.CLK = IsError;
|
||||
if (_trigError.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} is error, error code {_errorCode:D3}");
|
||||
}
|
||||
|
||||
_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()
|
||||
{
|
||||
_tolerancePressureAlarmChecker.Reset(PressureAlarmTime);
|
||||
_tolerancePressureWarningChecker.Reset(PressureWarningTime);
|
||||
_tolerancePositionAlarmChecker.Reset(PositionAlarmTime);
|
||||
_tolerancePositionWarningChecker.Reset(PositionWarningTime);
|
||||
|
||||
if (_trigError.M || _trigWarningMessage.M)
|
||||
_isFirstTime = true;
|
||||
|
||||
_trigError.RST = true;
|
||||
_trigOverTemp.RST = true;
|
||||
_trigWarningMessage.RST = true;
|
||||
|
||||
_connection.SetCommunicationError(false, "");
|
||||
_trigCommunicationError.RST = true;
|
||||
|
||||
_enableLog = SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
|
||||
|
||||
_trigRetryConnect.RST = true;
|
||||
|
||||
|
||||
base.Reset();
|
||||
}
|
||||
|
||||
|
||||
public void SetErrorCode(int errorCode)
|
||||
{
|
||||
_errorCode = errorCode;
|
||||
}
|
||||
|
||||
public void SetError(string reason)
|
||||
{
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetControlMode(PressureCtrlMode mode)
|
||||
{
|
||||
if(Mode == PressureCtrlMode.TVCalib)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"Throttle valve is in calibration mode, pls wait");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == PressureCtrlMode.TVClose)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new CloseHandler(this));
|
||||
}
|
||||
}
|
||||
else if (mode == PressureCtrlMode.TVOpen)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new OpenHandler(this));
|
||||
}
|
||||
}
|
||||
else if (mode == PressureCtrlMode.TVPositionCtrl)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new SetPositionHandler(this, 0));
|
||||
}
|
||||
}
|
||||
else if (mode == PressureCtrlMode.TVPressureCtrl)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new SetPressureHandler(this, 0, DBNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetPressure(float pressure)
|
||||
{
|
||||
if (Mode == PressureCtrlMode.TVCalib)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Name} is in calibration mode, pls wait");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressure < 0 || pressure > PressureRange)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Name} invalid pressure {pressure}, not in the scope (0, {PressureRange})");
|
||||
return;
|
||||
}
|
||||
PressureSetPoint = pressure;
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new SetPressureHandler(this, pressure, DBNumber));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPressure(float pressure, int dbNo)
|
||||
{
|
||||
if (Mode == PressureCtrlMode.TVCalib)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Name} is in calibration mode, pls wait");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressure < 0 || pressure > PressureRange)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Name} invalid pressure {pressure}, not in the scope (0, {PressureRange})");
|
||||
return;
|
||||
}
|
||||
PressureSetPoint = pressure;
|
||||
DBNumber = dbNo;
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new SetPressureHandler(this, pressure, dbNo));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetPosition(float position)
|
||||
{
|
||||
if (Mode == PressureCtrlMode.TVCalib)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Name} is in calibration mode, pls wait");
|
||||
return;
|
||||
}
|
||||
|
||||
if (position < 0 || position > 100)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Name} invalid position {position}, not in the scope (0, 100)");
|
||||
return;
|
||||
}
|
||||
PositionSetPoint = position;
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new SetPositionHandler(this, position));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System.IO.Ports;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.KITZ
|
||||
{
|
||||
public class KITZMessage : AsciiMessage
|
||||
{
|
||||
public string Command { get; set; }
|
||||
public string Parameter { get; set; }
|
||||
}
|
||||
|
||||
public class KITZConnection : SerialPortConnectionBase
|
||||
{
|
||||
public KITZConnection(string portName) : base(portName,115200, 8, Parity.None, StopBits.One, "\r")
|
||||
{
|
||||
|
||||
}
|
||||
protected override MessageBase ParseResponse(string rawText)
|
||||
{
|
||||
KITZMessage msg = new KITZMessage();
|
||||
msg.IsResponse = false;
|
||||
msg.IsAck = false;
|
||||
msg.IsComplete = false;
|
||||
msg.RawMessage = rawText.Replace("\r", "").Replace("\n", "");
|
||||
|
||||
if(string.IsNullOrEmpty(msg.RawMessage) || !msg.RawMessage.Contains(":"))
|
||||
{
|
||||
LOG.Error($"text length check failed, " + rawText);
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
string[] words = Regex.Split(msg.RawMessage, ":");
|
||||
msg.Command = words[0];
|
||||
|
||||
if(words.Length > 1)
|
||||
msg.Parameter = words[1];
|
||||
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+363
@@ -0,0 +1,363 @@
|
||||
using Aitex.Core.Common.DeviceData;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.KITZ
|
||||
{
|
||||
//PCH-C6
|
||||
public abstract class KITZHandler : HandlerBase
|
||||
{
|
||||
public KITZThrottleValve ThrottleValveDevice { get; }
|
||||
|
||||
protected KITZHandler(KITZThrottleValve throttleValve, bool isQuery, string parameter, string data = "")
|
||||
: base(BuildMessage(isQuery, parameter, data))
|
||||
{
|
||||
ThrottleValveDevice = throttleValve;
|
||||
}
|
||||
|
||||
private static string BuildMessage(bool isQuery, string parameter, string data)
|
||||
{
|
||||
string msg = string.Empty;
|
||||
if (isQuery)
|
||||
msg = parameter.ToLower() + ":";
|
||||
else
|
||||
msg = parameter.ToUpper() + ":" + data;
|
||||
|
||||
return $"{msg}\r\n";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//remote switch
|
||||
public class RemoteHandler : KITZHandler
|
||||
{
|
||||
public RemoteHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, false, "REMOTE")
|
||||
{
|
||||
Name = "Remote";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Calibration
|
||||
public class CalibrationHandler : KITZHandler
|
||||
{
|
||||
public CalibrationHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, false, "CAL")
|
||||
{
|
||||
Name = "Cal";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Close
|
||||
public class CloseHandler : KITZHandler
|
||||
{
|
||||
public CloseHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, false, "C")
|
||||
{
|
||||
Name = "C";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Open
|
||||
public class OpenHandler : KITZHandler
|
||||
{
|
||||
public OpenHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, false, "O")
|
||||
{
|
||||
Name = "O";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Position control
|
||||
public class SetPositionHandler : KITZHandler
|
||||
{
|
||||
public SetPositionHandler(KITZThrottleValve throttleValve, float position)
|
||||
: base(throttleValve, false, "POS", position.ToString("f1"))
|
||||
{
|
||||
Name = "POS";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Pressure control
|
||||
public class SetPressureHandler : KITZHandler
|
||||
{
|
||||
//PRS: (a), (b), (c), (d), (e)
|
||||
//a:Map No.
|
||||
//b:Table No.
|
||||
//c:DB No.
|
||||
//d:RAMP Mode No.
|
||||
//e:Target pressure
|
||||
public SetPressureHandler(KITZThrottleValve throttleValve, float pressure, int dbNo = 1)
|
||||
: base(throttleValve, false, "PRS", $"1,1,{dbNo},1," + pressure.ToString("f3"))
|
||||
{
|
||||
Name = "PRS";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//State
|
||||
public class QueryStateHandler : KITZHandler
|
||||
{
|
||||
public QueryStateHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, true, "sts")
|
||||
{
|
||||
Name = "sts";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper() || string.IsNullOrEmpty(result.Parameter))
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
string[] parameters = Regex.Split(result.Parameter, ",");
|
||||
if (parameters.Length < 4)
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
var accessMode = parameters[0];
|
||||
var controlMode = parameters[1];
|
||||
var warningInfo = parameters[2];
|
||||
var cycleCounter = parameters[3];
|
||||
|
||||
if (controlMode.ToUpper() == "CLOSE")
|
||||
{
|
||||
ThrottleValveDevice.Mode = PressureCtrlMode.TVClose;
|
||||
}
|
||||
else if (controlMode.ToUpper() == "OPEN")
|
||||
{
|
||||
ThrottleValveDevice.Mode = PressureCtrlMode.TVOpen;
|
||||
}
|
||||
else if (controlMode.ToUpper() == "PRESS")
|
||||
{
|
||||
ThrottleValveDevice.Mode = PressureCtrlMode.TVPressureCtrl;
|
||||
}
|
||||
else if (controlMode.ToUpper() == "POS")
|
||||
{
|
||||
ThrottleValveDevice.Mode = PressureCtrlMode.TVPositionCtrl;
|
||||
}
|
||||
else if (controlMode.ToUpper() == "CALIB")
|
||||
{
|
||||
ThrottleValveDevice.Mode = PressureCtrlMode.TVCalib;
|
||||
}
|
||||
|
||||
if (warningInfo.Contains("1") && ThrottleValveDevice.Mode != PressureCtrlMode.TVCalib)
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class QueryPressureHandler : KITZHandler
|
||||
{
|
||||
public QueryPressureHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, true, "prs")
|
||||
{
|
||||
Name = "prs";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper() || string.IsNullOrEmpty(result.Parameter))
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
if (!float.TryParse(result.Parameter, out float pressure))
|
||||
{
|
||||
//ThrottleValveDevice.SetErrorCode(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrottleValveDevice.PressureFeedback = pressure;
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class QueryPositionHandler : KITZHandler
|
||||
{
|
||||
public QueryPositionHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, true, "pos")
|
||||
{
|
||||
Name = "pos";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper() || string.IsNullOrEmpty(result.Parameter))
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
if (!float.TryParse(result.Parameter, out float position))
|
||||
{
|
||||
//ThrottleValveDevice.SetErrorCode(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrottleValveDevice.PositionFeedback = position;
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class CalbrationHandler : KITZHandler
|
||||
{
|
||||
public CalbrationHandler(KITZThrottleValve throttleValve)
|
||||
: base(throttleValve, false, "CAL")
|
||||
{
|
||||
Name = "CAL";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as KITZMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak || result.Command.ToUpper() != Name.ToUpper())
|
||||
{
|
||||
ThrottleValveDevice.SetError(result.RawMessage);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+664
@@ -0,0 +1,664 @@
|
||||
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.ThrottleValves.VAT
|
||||
{
|
||||
public class VATS651 : SerialPortDevice, IConnection
|
||||
{
|
||||
public string Address { get; }
|
||||
public bool IsConnected { get; }
|
||||
public bool Connect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Disconnect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public string PortStatus { get; set; } = "Closed";
|
||||
|
||||
private VATS651Connection _connection;
|
||||
public VATS651Connection 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 _scRoot;
|
||||
public VATS651(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;
|
||||
|
||||
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
|
||||
_connection = new VATS651Connection(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 VATS651Connection(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 VATS651QueryPinHandler(this, _deviceAddress));
|
||||
//_lstHandler.AddLast(new VATS651SetCommModeHandler(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 comandArgument)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651RawCommandHandler(this, command, comandArgument));
|
||||
}
|
||||
}
|
||||
|
||||
public void PerformRawCommand(string command)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651RawCommandHandler(this, command));
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseValve()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "C:"));
|
||||
}
|
||||
}
|
||||
public void OpenValve()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "O:"));
|
||||
}
|
||||
}
|
||||
public void Hold()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "H:"));
|
||||
}
|
||||
}
|
||||
public void SetPosition(string position)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "R:", position));
|
||||
}
|
||||
}
|
||||
public void SetPressure(string pressure)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "S:", pressure));
|
||||
}
|
||||
}
|
||||
public void SetAcessMode(string mode)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "c:01", mode));
|
||||
}
|
||||
}
|
||||
public void SetValveConfig(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:04", setVal));
|
||||
}
|
||||
}
|
||||
public void SetSensorConfig(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:01", setVal));
|
||||
}
|
||||
}
|
||||
public void SetSensorScale(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:05", setVal));
|
||||
}
|
||||
}
|
||||
public void SetSensor1Linearization(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:17", setVal));
|
||||
}
|
||||
}
|
||||
public void SetSensor2Linearization(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:18", setVal));
|
||||
}
|
||||
}
|
||||
public void SetSensorAverage(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:19", setVal));
|
||||
}
|
||||
}
|
||||
public void SetCommRangeConfig(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:21", setVal));
|
||||
}
|
||||
}
|
||||
public void SetInterfaceConfig(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:20", setVal));
|
||||
}
|
||||
}
|
||||
public void SetValveSpeed(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "V:", setVal));
|
||||
}
|
||||
}
|
||||
public void SetPressureControllerMode(string setVal)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:02Z00", setVal));
|
||||
}
|
||||
}
|
||||
public void SetPressureControllerConfig(string pressureController, string parameterNumber, string parameterValue)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:02", pressureController+ parameterNumber+ parameterValue));
|
||||
}
|
||||
}
|
||||
public void ResetError(string reset)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new VATS651SimpleActionHandler(this, "c:82", reset));
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteActionCompleted(string command)
|
||||
{
|
||||
if (command == "C:")
|
||||
{
|
||||
CloseValveCompleted = true;
|
||||
}
|
||||
else if (command == "O:")
|
||||
{
|
||||
OpenValveCompleted = true;
|
||||
}
|
||||
else if (command == "R:")
|
||||
{
|
||||
SetPositonCompleted = true;
|
||||
}
|
||||
else if (command == "S:")
|
||||
{
|
||||
SetPressureCompleted = true;
|
||||
}
|
||||
else if (command == "c:01")
|
||||
{
|
||||
SetAcessModeCompleted = true;
|
||||
}
|
||||
else if (command == "s:04")
|
||||
{
|
||||
SetValveConfigCompleted = true;
|
||||
}
|
||||
else if (command == "s:01")
|
||||
{
|
||||
SetSensorConfigCompleted = true;
|
||||
}
|
||||
else if (command == "s:05")
|
||||
{
|
||||
SetSensorScaleCompleted = true;
|
||||
}
|
||||
else if (command == "s:17")
|
||||
{
|
||||
SetSensor1LinearizationCompleted = true;
|
||||
}
|
||||
else if (command == "s:18")
|
||||
{
|
||||
SetSensor2LinearizationCompleted = true;
|
||||
}
|
||||
else if (command == "s:19")
|
||||
{
|
||||
SetSensorAverageCompleted = true;
|
||||
}
|
||||
else if (command == "s:21")
|
||||
{
|
||||
SetCommRangeConfigCompleted = true;
|
||||
}
|
||||
else if (command == "s:20")
|
||||
{
|
||||
SetInterfaceConfigCompleted = true;
|
||||
}
|
||||
else if (command == "V:")
|
||||
{
|
||||
SetValveSpeedCompleted = true;
|
||||
}
|
||||
else if (command == "c:82")
|
||||
{
|
||||
ResetErrorCompleted = true;
|
||||
}
|
||||
else if (command == "s:02Z00")
|
||||
{
|
||||
SetPressureControllerModeCompleted = true;
|
||||
}
|
||||
else if (command == "s:02")
|
||||
{
|
||||
SetPressureControllerConfigCompleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void NoteQueryResult(string command, string queryResult)
|
||||
{
|
||||
if (command == "A:")
|
||||
{
|
||||
Position = queryResult;
|
||||
}
|
||||
else if (command == "P:")
|
||||
{
|
||||
Pressure = queryResult;
|
||||
}
|
||||
else if (command == "i:60")
|
||||
{
|
||||
Sensor1Offset = queryResult;
|
||||
}
|
||||
else if (command == "i:61")
|
||||
{
|
||||
Sensor2Offset = queryResult;
|
||||
}
|
||||
else if (command == "i:64")
|
||||
{
|
||||
Sensor1Reading = queryResult;
|
||||
}
|
||||
else if (command == "i:65")
|
||||
{
|
||||
Sensor2Reading = queryResult;
|
||||
}
|
||||
else if (command == "i:30")
|
||||
{
|
||||
DeviceStatus = queryResult;
|
||||
}
|
||||
else if (command == "i:50")
|
||||
{
|
||||
VATError = queryResult;
|
||||
}
|
||||
else if (command == "i:51")
|
||||
{
|
||||
VATWarning = queryResult;
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteSetCompleted(string command, string parameter)
|
||||
{
|
||||
//if(command == "SWAA")
|
||||
//{
|
||||
// AlignAngleSet = double.Parse(parameter);
|
||||
//}
|
||||
//else if(command == "SWS")
|
||||
//{
|
||||
// WaferSizeSet = double.Parse(parameter);
|
||||
//}
|
||||
}
|
||||
|
||||
public void MonitorRawCommand(bool isSelected, string command, string comandArgument)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(VATS651RawCommandHandler) && ((VATS651Handler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new VATS651RawCommandHandler(this, command, comandArgument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void MonitorRawCommand(bool isSelected, string command)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(VATS651RawCommandHandler) && ((VATS651Handler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new VATS651RawCommandHandler(this, command));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RequestPositoin(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "A:");
|
||||
}
|
||||
public void RequestPressure(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "P:");
|
||||
}
|
||||
public void RequestSensor1Offset(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:60");
|
||||
}
|
||||
public void RequestSensor2Offset(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:61");
|
||||
}
|
||||
|
||||
public void RequestSensor1Reading(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:64");
|
||||
}
|
||||
public void RequestSensor2Reading(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:65");
|
||||
}
|
||||
public void RequestDeviceStatus(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:30");
|
||||
}
|
||||
|
||||
public void RequestError(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:50");
|
||||
}
|
||||
public void RequestWarnings(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "i:51");
|
||||
}
|
||||
|
||||
private void SimpleRequest(bool isSelected, string command)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(VATS651SimpleQueryHandler) && ((VATS651SimpleQueryHandler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new VATS651SimpleQueryHandler(this, command));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public string Error { get; private set; }
|
||||
public bool SetPositonCompleted { get; private set; }
|
||||
public bool SetPressureCompleted { get; private set; }
|
||||
public bool SetAcessModeCompleted { get; private set; }
|
||||
public bool ResetErrorCompleted { get; private set; }
|
||||
public string Position { get; private set; }
|
||||
public bool CloseValveCompleted { get; private set; }
|
||||
public bool OpenValveCompleted { get; private set; }
|
||||
public string Pressure { get; private set; }
|
||||
public string Sensor1Offset { get; private set; }
|
||||
public string Sensor2Offset { get; private set; }
|
||||
public string Sensor1Reading { get; private set; }
|
||||
public string Sensor2Reading { get; private set; }
|
||||
public string DeviceStatus { get; private set; }
|
||||
public string VATError { get; private set; }
|
||||
public string VATWarning { get; private set; }
|
||||
public bool SetValveConfigCompleted { get; private set; }
|
||||
public bool SetSensorConfigCompleted { get; private set; }
|
||||
public bool SetPressureControllerModeCompleted { get; private set; }
|
||||
public bool SetPressureControllerConfigCompleted { get; private set; }
|
||||
public bool SetSensorScaleCompleted { get; private set; }
|
||||
public bool SetSensor1LinearizationCompleted { get; private set; }
|
||||
public bool SetSensor2LinearizationCompleted { get; private set; }
|
||||
public bool SetSensorAverageCompleted { get; private set; }
|
||||
public bool SetCommRangeConfigCompleted { get; private set; }
|
||||
public bool SetInterfaceConfigCompleted { get; private set; }
|
||||
public bool SetValveSpeedCompleted { 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 });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using System.IO.Ports;
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.VAT
|
||||
{
|
||||
public class VATS651Message : AsciiMessage
|
||||
{
|
||||
public string Data { get; set; }
|
||||
public string ErrorText { get; set; }
|
||||
}
|
||||
|
||||
public class VATS651Connection : SerialPortConnectionBase
|
||||
{
|
||||
private static string _endLine = "\r\n";
|
||||
|
||||
private string _cachedBuffer = string.Empty;
|
||||
|
||||
public VATS651Connection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
|
||||
: base(portName, baudRate, dataBits, parity, stopBits, _endLine, true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override MessageBase ParseResponse(string rawText)
|
||||
{
|
||||
VATS651Message msg = new VATS651Message();
|
||||
msg.RawMessage = rawText;
|
||||
|
||||
if (rawText.Length <= 0)
|
||||
{
|
||||
LOG.Error($"empty response,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
if (rawText.Length <= 1)
|
||||
{
|
||||
LOG.Error($"too short response,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
rawText = rawText.Substring(0, rawText.Length - 2);//remove end char
|
||||
|
||||
if (rawText.Contains("E:"))
|
||||
{
|
||||
msg.IsError = true;
|
||||
msg.Data = rawText.Substring(2, rawText.Length - 2); ;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Data = rawText;
|
||||
msg.IsAck = true;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.VAT
|
||||
{
|
||||
public abstract class VATS651Handler : HandlerBase
|
||||
{
|
||||
public VATS651 Device { get; }
|
||||
|
||||
public string _command;
|
||||
protected string _parameter;
|
||||
|
||||
|
||||
protected VATS651Handler(VATS651 device, string command, string parameter = null)
|
||||
: base(BuildMessage(command, parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
private static string _endLine = "\r\n";
|
||||
private static string BuildMessage( string command, string parameter)
|
||||
{
|
||||
string commandContent = parameter == null ? $"{command}" : $"{command}{parameter}";
|
||||
return commandContent + _endLine.ToString();
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
VATS651Message response = msg as VATS651Message;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsError)
|
||||
{
|
||||
Device.NoteError(response.Data);
|
||||
transactionComplete = true;
|
||||
return false;
|
||||
}
|
||||
Device.NoteError(null);
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
SetState(EnumHandlerState.Acked);
|
||||
if(response.Data.IndexOf(_command)==0)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class VATS651RawCommandHandler : VATS651Handler
|
||||
{
|
||||
public VATS651RawCommandHandler(VATS651 device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if(base.HandleMessage(msg, out handled))
|
||||
{
|
||||
var result = msg as VATS651Message;
|
||||
Device.NoteRawCommandInfo(_command, result.RawMessage);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class VATS651SimpleActionHandler : VATS651Handler
|
||||
{
|
||||
public VATS651SimpleActionHandler(VATS651 device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
Device.NoteActionCompleted(_command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public class VATS651SimpleSetHandler : VATS651Handler
|
||||
{
|
||||
public VATS651SimpleSetHandler(VATS651 device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
Device.NoteSetCompleted(_command, _parameter);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public class VATS651SimpleQueryHandler : VATS651Handler
|
||||
{
|
||||
public VATS651SimpleQueryHandler(VATS651 device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
var vatMsg = msg as VATS651Message;
|
||||
string result = vatMsg.Data.Substring(_command.Length);
|
||||
Device.NoteQueryResult(_command, result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user