refactor: 将Framework库和RT、UI放在同一个解决方案中。
This commit is contained in:
+970
@@ -0,0 +1,970 @@
|
||||
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.MFCs.FujikinMFC
|
||||
{
|
||||
public class FujikinMFC : 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 FujikinMFCConnection _connection;
|
||||
public FujikinMFCConnection 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 FujikinMFC(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 FujikinMFCConnection(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 FujikinMFCConnection(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 FujikinMFCQueryPinHandler(this, _deviceAddress));
|
||||
//_lstHandler.AddLast(new FujikinMFCSetCommModeHandler(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 = 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();
|
||||
}
|
||||
|
||||
internal void NoteActionCompleted()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Home(out string reason)
|
||||
{
|
||||
return base.Home(out reason);
|
||||
}
|
||||
|
||||
|
||||
#region Command Functions
|
||||
|
||||
public void PerformRawCommand(string commandType, string command, string comandArgument)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCRawCommandHandler(this, commandType, command, comandArgument));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal void NoteExcetionInfo(byte value)
|
||||
{
|
||||
//parse exception status here
|
||||
ExceptionInfo = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ResetMFC()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCResetHandler(this));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFlowTotalizerAlarmEnable(bool enableValue)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "65,01,B5", enableValue.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFlowTotalizerAlarmEnable(string enableValue)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "65,01,B5", enableValue));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFlowTotalizerAlarmLevel(int value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet32BitValueHandler(this, "65,01,B6", value));
|
||||
}
|
||||
}
|
||||
public void SetFlowTotalizerAlarmLevel(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet32BitValueHandler(this, "65,01,B6", int.Parse(value)));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFlowMeterAlarmEnable(string enableValue)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "65,01,B6", enableValue));
|
||||
}
|
||||
}
|
||||
public void SetFlowMeterAlarmTripPointHigh(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet16BitValueHandler(this, "68,01,11", short.Parse(value)));
|
||||
}
|
||||
}
|
||||
public void SetFlowMeterZeroEnable(string enableValue)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "68,01,A5", enableValue));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFlowMeterRequestedZero(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "68,01,BA", byte.Parse(value)));
|
||||
}
|
||||
}
|
||||
public void SetFlowControllerControlModeSelection(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "69,01,03", byte.Parse(value)));
|
||||
}
|
||||
}
|
||||
public void SetFlowControllerDefaultControlMode(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "69,01,04", byte.Parse(value)));
|
||||
}
|
||||
}
|
||||
public void SetFlowControllerFreezeFollow(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "69,01,05", byte.Parse(value)));
|
||||
}
|
||||
}
|
||||
public void SetFlowControllerSetPoint(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet16BitValueHandler(this, "69,01,A4", short.Parse(value)));
|
||||
}
|
||||
}
|
||||
public void SetValveDriverValveOverride(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "6A,01,01", byte.Parse(value)));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValveDriverRampTime(string value)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new FujikinMFCSet32BitValueHandler(this, "6A,01,A4", int.Parse(value)));
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteAlarmDetail(short value)
|
||||
{
|
||||
//parse
|
||||
AlarmDetail = value;
|
||||
}
|
||||
|
||||
public void ReadExceptionStatus(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadExceptionStatusHandler));
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCReadExceptionStatusHandler(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteWarningDetail(short value)
|
||||
{
|
||||
//parse
|
||||
WarningDetail = value;
|
||||
}
|
||||
|
||||
public void ReadAlarmDetail(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadExceptionStatusHandler));
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCReadAlarmDetailHandler(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ReadWarningDetail(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadExceptionStatusHandler));
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCReadWarningDetailHandler(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FlowTotalizerAlarmEnable { get; set; }
|
||||
public void ReadFlowTotalizerAlarmEnable(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowTotalizerAlarmEnable";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadEnableHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCReadEnableHandler(this, "65,01,B5", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FlowTotalizerAlarmLevel { get; set; }
|
||||
public void ReadFlowTotalizerAlarmLevel(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowTotalizerAlarmLevel";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead32BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead32BitHandler(this, "65,01,B6", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//parse set
|
||||
public short FlowMeterStatus { get; set; }
|
||||
public void ReadFlowMeterStatus(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowMeterStatus";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "68,01,07", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FlowMeterAlarmEnable { get; set; }
|
||||
public void ReadFlowMeterAlarmEnable(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowMeterAlarmEnable";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadEnableHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCReadEnableHandler(this, "68,01,08", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short FlowMeterAlarmTripPointHigh { get; set; }
|
||||
public void ReadFlowMeterAlarmTripPointHigh(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowMeterAlarmTripPointHigh";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "68,01,11", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FlowMeterZeroEnable { get; set; }
|
||||
public void ReadFlowMeterZeroEnable(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowMeterZeroEnable";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadEnableHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCReadEnableHandler(this, "68,01,A5", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short FlowMeterRequestedZero { get; set; }
|
||||
public void ReadFlowMeterRequestedZero(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowMeterRequestedZero";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "68,01,BA", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short FlowControllerControlModeSelection { get; set; }
|
||||
public void ReadFlowControllerControlModeSelection(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowControllerControlModeSelection";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,03", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short FlowControllerFreezeFollow { get; set; }
|
||||
public void ReadFlowControllerFreezeFollow(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowControllerFreezeFollow";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,05", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//parse set
|
||||
public short FlowControllerStatus { get; set; }
|
||||
public void ReadFlowControllerStatus(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowControllerStatus";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,0A", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short FlowControllerDefaultControlMode { get; set; }
|
||||
public void ReadFlowControllerDefaultControlMode(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowControllerDefaultControlMode";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,04", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FlowMeterTotalizerData { get; set; }
|
||||
public void ReadFlowMeterTotalizerData(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowMeterTotalizerData";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead32BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead32BitHandler(this, "68,01,B2", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short FlowControllerSetPoint { get; set; }
|
||||
public void ReadFlowControllerSetPoint(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "FlowControllerSetPoint";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "69,01,A4", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public short ValveDriverValveOverride { get; set; }
|
||||
public void ReadValveDriverValveOverride(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverValveOverride";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "6A,01,01", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//parse set
|
||||
public short ValveDriverStatus { get; set; }
|
||||
public void ReadValveDriverStatus(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverStatus";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "6A,01,07", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short ValveDriverValveType { get; set; }
|
||||
public void ReadValveDriverValveType(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverValveType";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "6A,01,A0", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public short ValveDriverFilteredSetpoint { get; set; }
|
||||
public void ReadValveDriverFilteredSetpoint(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverFilteredSetpoint";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "6A,01,A6", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public short ValveDriverIndicatedFlow { get; set; }
|
||||
public void ReadValveDriverIndicatedFlow(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverIndicatedFlow";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "6A,01,A9", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public short ValveDriverValveVoltage { get; set; }
|
||||
public void ReadValveDriverValveVoltage(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverValveVoltage";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "6A,01,B6", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ValveDriverRampTime { get; set; }
|
||||
public void ReadValveDriverRampTime(bool isSelected)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
string propName = "ValveDriverRampTime";
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead32BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRead32BitHandler(this, "6A,01,A4", propName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteResetCompleted()
|
||||
{
|
||||
ResetCompleted = true;
|
||||
}
|
||||
|
||||
public void MonitorRawCommand(bool isSelected, string commandType, string command, string comandArgument)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRawCommandHandler) && ((FujikinMFCHandler)handler)._commandType == commandType && ((FujikinMFCHandler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new FujikinMFCRawCommandHandler(this, commandType, command, comandArgument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public string Error { get; private set; }
|
||||
|
||||
|
||||
|
||||
public short ExceptionInfo { get; private set; }
|
||||
public bool ResetCompleted { get; private set; }
|
||||
public bool ResponseNAK { get; private set; }
|
||||
public short WarningDetail { get; private set; }
|
||||
public short AlarmDetail { 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 NoteRawCommandInfo(string commandType, string command, string data, bool isAck)
|
||||
{
|
||||
var curIOResponse = IOResponseList.Find(res => res.SourceCommandType == commandType && res.SourceCommand == command);
|
||||
if (curIOResponse != null)
|
||||
{
|
||||
IOResponseList.Remove(curIOResponse);
|
||||
}
|
||||
IOResponseList.Add(new IOResponse() { SourceCommandType = commandType, SourceCommand = command, ResonseContent = data, IsAck = isAck, ResonseRecievedTime = DateTime.Now });
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs.FujikinMFC
|
||||
{
|
||||
|
||||
public class FujikinMFCMessage : BinaryMessage
|
||||
{
|
||||
public string CommandType { get; set; }
|
||||
public string Command { get; set; }
|
||||
public string ErrorCode { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
|
||||
public class FujikinMFCConnection : SerialPortConnectionBase
|
||||
{
|
||||
|
||||
private static byte _start = 0x02;
|
||||
//private static byte _end = 0x00;
|
||||
private static byte _ack = 0x06;
|
||||
private static byte _nak = 0x16;
|
||||
|
||||
private static byte _address = 0x00;
|
||||
|
||||
|
||||
|
||||
public FujikinMFCConnection(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)
|
||||
{
|
||||
FujikinMFCMessage msg = new FujikinMFCMessage();
|
||||
msg.RawMessage = rawMessage;
|
||||
//msg.Data = rawMessage;
|
||||
|
||||
if (rawMessage.Length == 1)
|
||||
{
|
||||
if(rawMessage[0] == _ack)
|
||||
{
|
||||
msg.IsAck = true;
|
||||
}
|
||||
else if(rawMessage[0] == _nak)
|
||||
{
|
||||
msg.IsNak = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid response");
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
if (rawMessage.Length < 7)
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid response");
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
if (rawMessage[0] != _address)
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid address byte");
|
||||
return msg;
|
||||
}
|
||||
if (rawMessage[1] != _start)
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid start byte");
|
||||
return msg;
|
||||
}
|
||||
|
||||
byte checkSum = 0;
|
||||
for (int i = 1; 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;
|
||||
}
|
||||
msg.CommandType = rawMessage[2].ToString("X2");
|
||||
var commandArray = rawMessage.Skip(4).Take(3).ToArray();
|
||||
msg.Command = string.Join(",", commandArray.Select(bt => bt.ToString("X2")).ToArray());
|
||||
msg.Data = rawMessage.Skip(7).Take(rawMessage.Length - 9).ToArray();
|
||||
msg.IsResponse = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
+481
@@ -0,0 +1,481 @@
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs.FujikinMFC
|
||||
{
|
||||
|
||||
public abstract class FujikinMFCHandler : HandlerBase
|
||||
{
|
||||
public FujikinMFC Device { get; }
|
||||
|
||||
public string _command;
|
||||
public string _commandType;
|
||||
|
||||
private static byte _start = 0x02;
|
||||
private static byte _end = 0x00;
|
||||
//private static byte _ack = 0x06;
|
||||
//private static byte _nak = 0x16;
|
||||
|
||||
private static byte _address = 0x21;
|
||||
|
||||
|
||||
public string DevicePropName;
|
||||
|
||||
|
||||
protected FujikinMFCHandler(FujikinMFC device, string commandType, string command, string parameter = null)
|
||||
: base(BuildMessage(commandType,command,parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_commandType = commandType;
|
||||
_address = Convert.ToByte(Device.Address, 16);
|
||||
Name = command;
|
||||
}
|
||||
protected FujikinMFCHandler(FujikinMFC device, string commandType, string command, byte[] parameter)
|
||||
: base(BuildMessage(commandType, command, parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_commandType = commandType;
|
||||
_address = Convert.ToByte(Device.Address, 16);
|
||||
Name = command;
|
||||
}
|
||||
private static byte[] BuildMessage(string commandType, string command, string parameter)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
var parameterArray = parameter!=null? parameter.Split(',').Select(s => Convert.ToByte(s, 16)).ToArray():null;
|
||||
buffer.Add(_address);
|
||||
buffer.Add(_start);
|
||||
buffer.Add(Convert.ToByte(commandType, 16));
|
||||
buffer.Add((byte)(3 + (parameterArray!=null ? parameterArray.Length:0)));
|
||||
buffer.AddRange(command.Split(',').Select(s => Convert.ToByte(s, 16)).ToArray());
|
||||
if(parameterArray != null)
|
||||
buffer.AddRange(parameterArray);
|
||||
buffer.Add(_end);
|
||||
|
||||
byte checkSum = 0;
|
||||
for (int i = 1; i < buffer.Count - 1; i++)
|
||||
{
|
||||
checkSum += buffer[i];
|
||||
}
|
||||
buffer.Add(checkSum);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
protected static byte[] BuildMessage(string commandType, string command, byte[] parameterArray = null)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
buffer.Add(_address);
|
||||
buffer.Add(_start);
|
||||
buffer.Add(Convert.ToByte(commandType, 16));
|
||||
buffer.Add((byte)(3 + (parameterArray != null ? parameterArray.Length : 0)));
|
||||
buffer.AddRange(command.Split(',').Select(s => Convert.ToByte(s, 16)).ToArray());
|
||||
if (parameterArray != null)
|
||||
buffer.AddRange(parameterArray);
|
||||
buffer.Add(_end);
|
||||
|
||||
byte checkSum = 0;
|
||||
for (int i = 1; i < buffer.Count - 1; i++)
|
||||
{
|
||||
checkSum += buffer[i];
|
||||
}
|
||||
buffer.Add(checkSum);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsNak)
|
||||
{
|
||||
Device.NoteNAK();
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
else if (response.IsAck)
|
||||
{
|
||||
if (this.IsAcked)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetState(EnumHandlerState.Acked);
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(response.IsComplete)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
transactionComplete = false;
|
||||
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[] ShortToByteArray(short num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected static byte[] IntToByteArray(int num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected static byte[] FloarToByteArray(float num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected int ByteArrayToInt(byte[] bytes)
|
||||
{
|
||||
int temp = BitConverter.ToInt32(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
protected short ByteArrayToShort(byte[] bytes)
|
||||
{
|
||||
short temp = BitConverter.ToInt16(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
protected float ByteArrayToFloat(byte[] bytes)
|
||||
{
|
||||
if(bytes.Length != 4)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
float temp = BitConverter.ToSingle(bytes, 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 class FujikinMFCRawCommandHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCRawCommandHandler(FujikinMFC device, string commandType, string command, string parameter)
|
||||
: base(device, commandType, command, parameter)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
if(base.HandleMessage(msg, out transactionComplete))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
Device.NoteRawCommandInfo(_commandType, _command, string.Join(",", response.RawMessage.Select(bt => bt.ToString("X2")).ToArray()), msg.IsAck);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FujikinMFCResetHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCResetHandler(FujikinMFC device)
|
||||
: base(device, "81","01,01,C7")
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
Device.NoteResetCompleted();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FujikinMFCSetEnableHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCSetEnableHandler(FujikinMFC device, string command, string enableValue)
|
||||
: base(device, "81", command, BoolToByte(enableValue))
|
||||
{
|
||||
}
|
||||
private static string BoolToByte(string boolStr)
|
||||
{
|
||||
return boolStr == "true" ? "01" : "00";
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
Device.NoteActionCompleted();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FujikinMFCSet8BitValueHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCSet8BitValueHandler(FujikinMFC device, string command, byte value)
|
||||
: base(device, "81", command, new byte[] { value })
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
Device.NoteActionCompleted();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class FujikinMFCSet16BitValueHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCSet16BitValueHandler(FujikinMFC device, string command, short value)
|
||||
: base(device, "81", command, ShortToByteArray(value))
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
Device.NoteActionCompleted();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class FujikinMFCSet32BitValueHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCSet32BitValueHandler(FujikinMFC device, string command, int value)
|
||||
: base(device, "81", command, IntToByteArray(value))
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
Device.NoteActionCompleted();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class FujikinMFCReadExceptionStatusHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCReadExceptionStatusHandler(FujikinMFC device)
|
||||
: base(device, "80", "65,01,A0")
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if(response.Data.Length != 1)
|
||||
{
|
||||
Device.NoteError("invalid ExceptionStatus");
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteExcetionInfo(response.Data[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class FujikinMFCReadAlarmDetailHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCReadAlarmDetailHandler(FujikinMFC device)
|
||||
: base(device, "80", "65,01,A1")
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if (response.Data.Length != 2)
|
||||
{
|
||||
Device.NoteError("invalid AlarmDetai");
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteAlarmDetail(ByteArrayToShort(response.Data));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class FujikinMFCReadWarningDetailHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCReadWarningDetailHandler(FujikinMFC device)
|
||||
: base(device, "80", "65,01,A2")
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if (response.Data.Length != 1)
|
||||
{
|
||||
Device.NoteError("invalid WarningDetail");
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteWarningDetail(ByteArrayToShort(response.Data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FujikinMFCReadEnableHandler : FujikinMFCHandler
|
||||
{
|
||||
|
||||
public FujikinMFCReadEnableHandler(FujikinMFC device, string command, string propName)
|
||||
: base(device, "80", command)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if (response.Data.Length != 1)
|
||||
{
|
||||
Device.NoteError("invalid Enable response");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDevicePropValue<bool>(DevicePropName, response.Data[0] == 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FujikinMFCRead8BitHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCRead8BitHandler(FujikinMFC device, string command, string propName)
|
||||
: base(device, "80", command)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if (response.Data.Length != 1)
|
||||
{
|
||||
Device.NoteError("invalid 8Bit response");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDevicePropValue<short>(DevicePropName, (short)response.Data[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FujikinMFCRead16BitHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCRead16BitHandler(FujikinMFC device, string command, string propName)
|
||||
: base(device, "80", command)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if (response.Data.Length != 2)
|
||||
{
|
||||
Device.NoteError("invalid 16Bit response");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDevicePropValue<short>(DevicePropName, ByteArrayToShort(response.Data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FujikinMFCRead32BitHandler : FujikinMFCHandler
|
||||
{
|
||||
public FujikinMFCRead32BitHandler(FujikinMFC device, string command, string propName)
|
||||
: base(device, "80", command)
|
||||
{
|
||||
DevicePropName = propName;
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (base.HandleMessage(msg, out handled))
|
||||
{
|
||||
FujikinMFCMessage response = msg as FujikinMFCMessage;
|
||||
if (response.Data.Length != 4)
|
||||
{
|
||||
Device.NoteError("invalid 32Bit response");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDevicePropValue<int>(DevicePropName, ByteArrayToInt(response.Data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+329
@@ -0,0 +1,329 @@
|
||||
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.Common.Device.Bases;
|
||||
using MECF.Framework.Common.Equipment;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Threading;
|
||||
|
||||
namespace LsOneRT.Devices.HoribaMFC
|
||||
{
|
||||
public class HoribaMessage : BinaryMessage
|
||||
{
|
||||
public string DeviceAddress { get; set; }
|
||||
public string Action { get; set; }
|
||||
public string Parameter { get; set; }
|
||||
public int DataLength { get; set; }
|
||||
public string ErrorText { get; set; }
|
||||
public byte[] Datas { get; set; }
|
||||
}
|
||||
|
||||
public class HoribaConnection: Singleton<HoribaConnection>
|
||||
{
|
||||
public HoribaConnectionBase Horiba { get; private set; }
|
||||
public HoribaConnection()
|
||||
{
|
||||
Horiba = new HoribaConnectionBase();
|
||||
}
|
||||
}
|
||||
|
||||
public class HoribaConnectionBase : SerialPortConnectionBase
|
||||
{
|
||||
private const int STX = 0x02;
|
||||
private const int ETX = 0x03;
|
||||
private const int NAK = 0x15;
|
||||
private List<byte> _lstCacheBuffer = new List<byte>();
|
||||
private PeriodicJob _thread;
|
||||
|
||||
private bool _activeMonitorStatus;
|
||||
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
private R_TRIG _trigCommunicationError = new R_TRIG();
|
||||
private R_TRIG _trigRetryConnect = new R_TRIG();
|
||||
|
||||
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
|
||||
private object _locker = new object();
|
||||
|
||||
private bool _enableLog = true;
|
||||
private bool _isFirstTime = true;
|
||||
private int _reconnectCount = 0;
|
||||
|
||||
private DeviceTimer _QueryScaleTimer = new DeviceTimer();
|
||||
private readonly int _QueryScaleInterval = 3000;
|
||||
|
||||
private List<MfcBase> MFCList = new List<MfcBase>();
|
||||
|
||||
public HoribaConnectionBase():base(SC.GetStringValue($"{ModuleName.PM}.MFCSerialPortName"), 38400, 7, Parity.Odd, StopBits.One, "\r", false)
|
||||
{
|
||||
_activeMonitorStatus = true;
|
||||
Module = ModuleName.PM.ToString();
|
||||
Name = "HoribaConnection";
|
||||
|
||||
_enableLog = SC.GetValue<bool>($"{Module}.MFCEnableLogMessage");
|
||||
EnableLog(_enableLog);
|
||||
|
||||
if (Connect())
|
||||
{
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
Thread.Sleep(2000);
|
||||
if (SC.ContainsItem("System.IsSimulatorMode") && SC.GetValue<bool>("System.IsSimulatorMode"))
|
||||
_thread = new PeriodicJob(200, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
else
|
||||
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
}
|
||||
|
||||
public HoribaConnectionBase(string module) : base(SC.GetStringValue($"{module}.MFCSerialPortName"), 38400, 7, Parity.Odd, StopBits.One, "\r", false)
|
||||
{
|
||||
_activeMonitorStatus = true;
|
||||
Module = module;
|
||||
Name = "HoribaConnection";
|
||||
|
||||
_enableLog = SC.GetValue<bool>($"{Module}.MFCEnableLogMessage");
|
||||
EnableLog(_enableLog);
|
||||
|
||||
if (Connect())
|
||||
{
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
Thread.Sleep(2000);
|
||||
_QueryScaleTimer.Start(_QueryScaleInterval);
|
||||
if (SC.ContainsItem("System.IsSimulatorMode") && SC.GetValue<bool>("System.IsSimulatorMode"))
|
||||
_thread = new PeriodicJob(200, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
else
|
||||
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
}
|
||||
|
||||
public string Module { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
private bool OnTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
MonitorTimeout();
|
||||
if (!IsConnected || IsCommunicationError)
|
||||
{
|
||||
_trigRetryConnect.CLK = !IsConnected;
|
||||
if (_trigRetryConnect.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"Disconnect with {Module}.{Name} {SC.GetStringValue($"{ModuleName.PM}.MFCSerialPortName")}");
|
||||
|
||||
_reconnectCount = 0;
|
||||
}
|
||||
|
||||
if (_reconnectCount <= SC.GetValue<int>($"{Module}.MFCReconnectCount"))
|
||||
{
|
||||
//SetPortAddress(SC.GetStringValue($"{Module}.MFCSerialPortName"));
|
||||
Connect();
|
||||
Thread.Sleep(2000);
|
||||
if (IsConnected)
|
||||
{
|
||||
Reset();
|
||||
EV.PostInfoLog(Module, $"Reconnect with {Module}.{Name} {SC.GetStringValue($"{ModuleName.PM}.MFCSerialPortName")} successed");
|
||||
}
|
||||
else
|
||||
{
|
||||
EV.PostWarningLog(Module, $"Can not connect with {Module}.{Name} {SC.GetStringValue($"{ModuleName.PM}.MFCSerialPortName")}, retry {_reconnectCount}");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.Clear();
|
||||
_reconnectCount++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HandlerBase handler = null;
|
||||
if (!IsBusy)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
if (_lstHandler.Count == 0 && _activeMonitorStatus)
|
||||
{
|
||||
foreach(var mfc in MFCList)
|
||||
{
|
||||
_lstHandler.AddLast(new HoribaMFCQueryFlow(mfc, mfc.DeviceID));
|
||||
if(_QueryScaleTimer.IsTimeout())
|
||||
_lstHandler.AddLast(new HoribaMFCQueryScale(mfc, mfc.DeviceID));
|
||||
if (_isFirstTime)
|
||||
{
|
||||
_lstHandler.AddLast(new HoribaMFCQueryScale(mfc, mfc.DeviceID));
|
||||
_lstHandler.AddLast(new HoribaMFCSetDigitalMode(mfc, mfc.DeviceID));
|
||||
}
|
||||
}
|
||||
|
||||
if (_QueryScaleTimer.IsTimeout())
|
||||
_QueryScaleTimer.Start(_QueryScaleInterval);
|
||||
_isFirstTime = false;
|
||||
}
|
||||
|
||||
if (_lstHandler.Count > 0)
|
||||
{
|
||||
handler = _lstHandler.First.Value;
|
||||
|
||||
_lstHandler.RemoveFirst();
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
Execute(handler);
|
||||
}
|
||||
}
|
||||
|
||||
EnableLog(_enableLog);
|
||||
|
||||
_trigCommunicationError.CLK = IsCommunicationError;
|
||||
if (_trigCommunicationError.Q)
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddHandler(HandlerBase handler)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMFC(MfcBase mfc)
|
||||
{
|
||||
MFCList.Add(mfc);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_trigWarningMessage.RST = true;
|
||||
|
||||
SetCommunicationError(false, "");
|
||||
_trigCommunicationError.RST = true;
|
||||
|
||||
_enableLog = SC.GetValue<bool>($"{Module}.MFCEnableLogMessage");
|
||||
|
||||
_trigRetryConnect.RST = true;
|
||||
|
||||
_reconnectCount = 0;
|
||||
}
|
||||
|
||||
public override bool SendMessage(byte[] message)
|
||||
{
|
||||
_lstCacheBuffer.Clear();
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetError(byte[] content)
|
||||
{
|
||||
string reason = System.Text.Encoding.ASCII.GetString(content);
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override MessageBase ParseResponse(byte[] rawMessage)
|
||||
{
|
||||
_lstCacheBuffer.AddRange(rawMessage);
|
||||
byte[] temps = _lstCacheBuffer.ToArray();
|
||||
|
||||
HoribaMessage msg = new HoribaMessage();
|
||||
msg.IsResponse = false;
|
||||
msg.IsAck = false;
|
||||
msg.IsComplete = false;
|
||||
msg.RawMessage = _lstCacheBuffer.ToArray();
|
||||
if (_lstCacheBuffer.Count < 4 || _lstCacheBuffer[_lstCacheBuffer.Count - 2] != ETX)
|
||||
return msg;
|
||||
|
||||
if (temps.Length > 0 && (int)temps[0] == NAK)
|
||||
{
|
||||
LOG.Error($"NAK, " + temps);
|
||||
msg.IsNak = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
if (temps.Length < 4)
|
||||
{
|
||||
LOG.Error($"text length check failed");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
if ((int)temps[0] != STX)
|
||||
{
|
||||
LOG.Error($"text check STX failed");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
int etxIndex = 0;
|
||||
foreach (var item in temps)
|
||||
{
|
||||
if ((int)item == ETX)
|
||||
break;
|
||||
|
||||
etxIndex++;
|
||||
}
|
||||
|
||||
if(etxIndex >= temps.Length)
|
||||
{
|
||||
LOG.Error($"text check ETX failed");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
msg.DataLength = etxIndex - 1;
|
||||
msg.Datas = new byte[etxIndex - 1];
|
||||
|
||||
///STX msg ETX BCC
|
||||
Array.Copy(temps, 1, msg.Datas, 0, etxIndex - 1);
|
||||
|
||||
var bcc = (int)temps[etxIndex + 1];
|
||||
|
||||
int checkBCC = 0;
|
||||
foreach (var item in msg.Datas)
|
||||
{
|
||||
checkBCC += (int)item;
|
||||
}
|
||||
checkBCC += ETX;
|
||||
|
||||
if (checkBCC % 128 != bcc)
|
||||
{
|
||||
LOG.Error($"check BCC failed");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Device.Bases;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LsOneRT.Devices.HoribaMFC
|
||||
{
|
||||
public abstract class HoribaHandler : HandlerBase
|
||||
{
|
||||
private const byte Header = 0x40;
|
||||
private const byte STX = 0x02;
|
||||
private const byte ETX = 0x03;
|
||||
|
||||
public MfcBase MFCDevice { get; }
|
||||
|
||||
protected HoribaHandler(MfcBase mfc, string msdLsdAddress, string data)
|
||||
: base(BuildMessage(msdLsdAddress, data))
|
||||
{
|
||||
MFCDevice = mfc;
|
||||
}
|
||||
|
||||
private static byte[] BuildMessage(string msdLsdAddress, string data)
|
||||
{
|
||||
List<byte> message = new List<byte>();
|
||||
message.Add(Header);
|
||||
PacketMessage(msdLsdAddress, message);
|
||||
message.Add(STX);
|
||||
PacketMessage(data, message);
|
||||
message.Add(ETX);
|
||||
message.Add((byte)CalcBBC(data));
|
||||
if(SC.ContainsItem("System.IsSimulatorMode") && SC.GetValue<bool>("System.IsSimulatorMode"))
|
||||
message.Add(0x0D);
|
||||
return message.ToArray();
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int CalcBBC(string value)
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (var item in value)
|
||||
{
|
||||
sum += (int)item;
|
||||
}
|
||||
sum += ETX;
|
||||
|
||||
return sum % 128;
|
||||
}
|
||||
|
||||
private static List<byte> PacketMessage(string msg, List<byte> msgList)
|
||||
{
|
||||
foreach (var item in msg)
|
||||
{
|
||||
msgList.Add((byte)item);
|
||||
}
|
||||
return msgList;
|
||||
}
|
||||
|
||||
private static byte[] String2Ascii(string s)
|
||||
{
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(s);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
public class HoribaMFCSetFlow : HoribaHandler
|
||||
{
|
||||
public HoribaMFCSetFlow(MfcBase mfc, string deviceAddress, float flow)
|
||||
: base(mfc, deviceAddress, $"AFC{flow},B")
|
||||
{
|
||||
Name = "SetFlow";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as HoribaMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.Datas[0] != 0x4f && result.Datas[0] != 0x4b)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class HoribaMFCQueryFlow : HoribaHandler
|
||||
{
|
||||
public HoribaMFCQueryFlow(MfcBase mfc, string deviceAddress)
|
||||
: base(mfc, deviceAddress, $"RFV")
|
||||
{
|
||||
Name = "QueryFlow";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as HoribaMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
float.TryParse(System.Text.Encoding.ASCII.GetString(result.Datas), out float flow);
|
||||
MFCDevice.FeedBack = flow;
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class HoribaMFCQueryScale : HoribaHandler
|
||||
{
|
||||
public HoribaMFCQueryScale(MfcBase mfc, string deviceAddress)
|
||||
: base(mfc, deviceAddress, $"RFS")
|
||||
{
|
||||
Name = "QueryScale";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as HoribaMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dataArray = System.Text.Encoding.ASCII.GetString(result.Datas).Split(',');
|
||||
|
||||
float.TryParse(dataArray[0], out float range);
|
||||
//temporary comment to fix compile issue
|
||||
if(dataArray.Length > 1)
|
||||
{
|
||||
if (MFCDevice.Unit != dataArray[1].ToUpper())
|
||||
EV.PostInfoLog(MFCDevice.Module, $"{MFCDevice.Module} {MFCDevice.Name} change from {MFCDevice.Unit} to {dataArray[1].ToUpper()}");
|
||||
|
||||
MFCDevice.Unit = dataArray[1].ToUpper();
|
||||
}
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class HoribaMFCSetDigitalMode : HoribaHandler
|
||||
{
|
||||
public HoribaMFCSetDigitalMode(MfcBase mfc, string deviceAddress)
|
||||
: base(mfc, deviceAddress, $"'!+REVERSE")
|
||||
{
|
||||
Name = "SetDigitalMode";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as HoribaMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.Datas[0] != 0x4f && result.Datas[0] != 0x4b)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class HoribaMFCSetAnalogMode : HoribaHandler
|
||||
{
|
||||
public HoribaMFCSetAnalogMode(MfcBase mfc, string deviceAddress)
|
||||
: base(mfc, deviceAddress, $"'!+NORMAL")
|
||||
{
|
||||
Name = "SetAnalogMode";
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as HoribaMessage;
|
||||
handled = false;
|
||||
if (!result.IsResponse) return true;
|
||||
|
||||
if (result.IsError || result.IsFormatError || result.IsNak)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.Datas[0] != 0x4f && result.Datas[0] != 0x4b)
|
||||
{
|
||||
Singleton<HoribaConnection>.Instance.Horiba.SetError(result.RawMessage);
|
||||
}
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs
|
||||
{
|
||||
public interface IMfc
|
||||
{
|
||||
bool Ramp(double flowSetPoint, int time, out string reason);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user