refactor: 将Framework库和RT、UI放在同一个解决方案中。
This commit is contained in:
+327
@@ -0,0 +1,327 @@
|
||||
using Aitex.Core.RT.DataCenter;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.RT.OperationCenter;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.CommonData.DeviceData;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Device.Bases;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers.BaecChiller
|
||||
{
|
||||
public class BaecChiller : ChillerBase, IConnection
|
||||
{
|
||||
public string Address => Connection.Address;
|
||||
public override bool IsConnected => Connection.IsConnected && !_connection.IsCommunicationError;
|
||||
public bool Connect()
|
||||
{
|
||||
return _connection.Connect();
|
||||
}
|
||||
|
||||
public bool Disconnect()
|
||||
{
|
||||
return _connection.Disconnect();
|
||||
}
|
||||
|
||||
public byte SlaveAddress { get; private set; } = 0x01;
|
||||
|
||||
public string PortStatus { get; set; } = "Closed";
|
||||
|
||||
private BaecChillerConnection _connection;
|
||||
public BaecChillerConnection Connection
|
||||
{
|
||||
get { return _connection; }
|
||||
}
|
||||
|
||||
public override AITChillerData1 DeviceData
|
||||
{
|
||||
get
|
||||
{
|
||||
return new AITChillerData1()
|
||||
{
|
||||
Module = Module,
|
||||
DeviceName = Name,
|
||||
DisplayName = Name,
|
||||
IsCH1On = IsCH1On,
|
||||
IsCH2On = IsCH2On,
|
||||
IsCH1Alarm = IsCH1Alarm,
|
||||
IsCH2Alarm = IsCH2Alarm,
|
||||
CH1Temperature = CH1TemperatureFeedback,
|
||||
CH2Temperature = CH2TemperatureFeedback,
|
||||
CH1TemperatureSetPoint = CH1TemperatureSetpoint,
|
||||
CH2TemperatureSetPoint = CH2TemperatureSetpoint,
|
||||
CH1WaterFlow = CH1WaterFlow,
|
||||
CH2WaterFlow = CH2WaterFlow,
|
||||
FormatString = "f1",
|
||||
TemperatureHighLimit = TemperatureHighLimit,
|
||||
TemperatureLowLimit = TemperatureLowLimit,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override float TemperatureHighLimit => (float)_scTemperatureMaxValue.DoubleValue;
|
||||
public override float TemperatureLowLimit => (float)_scTemperatureMinValue.DoubleValue;
|
||||
private R_TRIG _trigError = new R_TRIG();
|
||||
|
||||
private R_TRIG _trigCommunicationError = new R_TRIG();
|
||||
private R_TRIG _trigRetryConnect = new R_TRIG();
|
||||
|
||||
private PeriodicJob _thread;
|
||||
|
||||
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
|
||||
private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
|
||||
private DeviceTimer _QueryTimer = new DeviceTimer();
|
||||
private readonly int _QueryInterval = 2000;
|
||||
|
||||
private object _locker = new object();
|
||||
private bool _enableLog;
|
||||
private string _address;
|
||||
private string _scRoot;
|
||||
private SCConfigItem _scTemperatureMaxValue;
|
||||
private SCConfigItem _scTemperatureMinValue;
|
||||
public BaecChiller(string module, string name, string scRoot) : base()
|
||||
{
|
||||
_scRoot = scRoot;
|
||||
base.Module = module;
|
||||
base.Name = name;
|
||||
}
|
||||
|
||||
public override bool Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_scTemperatureMaxValue = SC.GetConfigItem($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.TemperatureMaxValue");
|
||||
_scTemperatureMinValue = SC.GetConfigItem($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.TemperatureMinValue");
|
||||
_address = SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address");
|
||||
_enableLog = SC.GetValue<bool>($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.EnableLogMessage");
|
||||
_connection = new BaecChillerConnection(_address);
|
||||
_connection.EnableLog(_enableLog);
|
||||
|
||||
if (_connection.Connect())
|
||||
{
|
||||
PortStatus = "Open";
|
||||
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
|
||||
}
|
||||
|
||||
//_lstMonitorHandler.AddLast(new CommetRFMatchGetActualCapHandler(this));
|
||||
_thread = new PeriodicJob(2000, OnTimer, $"{Module}.{Name} MonitorHandler", true);
|
||||
_QueryTimer.Start(_QueryInterval);
|
||||
_lstMonitorHandler.AddLast(new BaecChillerGetStatusHandler(this));
|
||||
|
||||
DATA.Subscribe($"{Module}.{Name}.IsConnected", () => IsConnected);
|
||||
DATA.Subscribe($"{Module}.{Name}.Address", () => Address);
|
||||
OP.Subscribe($"{Module}.{Name}.Reconnect", (string cmd, object[] args) =>
|
||||
{
|
||||
Disconnect();
|
||||
Connect();
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool OnTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
//_connection.MonitorTimeout();
|
||||
|
||||
if (!_connection.IsConnected || _connection.IsCommunicationError)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.Clear();
|
||||
}
|
||||
|
||||
_trigRetryConnect.CLK = !_connection.IsConnected;
|
||||
if (_trigRetryConnect.Q)
|
||||
{
|
||||
_connection.SetPortAddress(SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address"));
|
||||
if (!_connection.Connect())
|
||||
{
|
||||
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//_lstHandler.AddLast(new RisshiChillerQueryPinHandler(this, _deviceAddress));
|
||||
//_lstHandler.AddLast(new RisshiChillerSetCommModeHandler(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();
|
||||
}
|
||||
|
||||
|
||||
#region Command Functions
|
||||
public void SetTemperature(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
//_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
|
||||
}
|
||||
}
|
||||
public void SetTempHighWarning(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
//_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
|
||||
}
|
||||
}
|
||||
public void SetTempLowWarning(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
//_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
|
||||
}
|
||||
}
|
||||
public void SetRemoteMode(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
//_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWS", angle));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRunMode(string waferSize)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
// _lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWS", waferSize));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetChillerCH1OnOff(bool isOn)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new BaecChillerSetOnOffHandler(this, true, isOn));
|
||||
}
|
||||
}
|
||||
public override void SetChillerCH2OnOff(bool isOn)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new BaecChillerSetOnOffHandler(this, false, isOn));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetChillerCH1Temperature(float temp)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new BaecChillerSetTemperatureHandler(this, true, temp));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetChillerCH2Temperature(float temp)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new BaecChillerSetTemperatureHandler(this, false, temp));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public string Error { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Note Functions
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
|
||||
public void NoteError(string reason)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(reason))
|
||||
{
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
}
|
||||
Error = reason;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers.BaecChiller
|
||||
{
|
||||
public class RisshiChillerMessage : BinaryMessage
|
||||
{
|
||||
public string Command { get; set; }
|
||||
public string ErrorCode { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
|
||||
//Modbus RTU
|
||||
public class BaecChillerConnection : SerialPortConnectionBase
|
||||
{
|
||||
private List<byte> _msgBuffer = new List<byte>();
|
||||
|
||||
public BaecChillerConnection(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)
|
||||
{
|
||||
RisshiChillerMessage msg = new RisshiChillerMessage();
|
||||
if (rawMessage == null || rawMessage.Length < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_msgBuffer.AddRange(rawMessage);
|
||||
if (_msgBuffer.Count < 5)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
if (_msgBuffer[1] == 0x03)
|
||||
{
|
||||
var dataLength = _msgBuffer[2];
|
||||
if (_msgBuffer.Count < 3 + dataLength + 2)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.RawMessage = _msgBuffer.Take(3 + dataLength + 2).ToArray();
|
||||
msg.Data = _msgBuffer.Skip(3).Take(dataLength).ToArray();
|
||||
_msgBuffer.RemoveRange(0, msg.RawMessage.Length);
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
else if (_msgBuffer[1] == 0x10 || _msgBuffer[1] == 0x06)
|
||||
{
|
||||
//SlaveAddress,FunctionCode,StartingAddressHigh,StartingAddressLow,NumberAddressHigh,NumberAddressLow,CRC,CRC
|
||||
if (_msgBuffer.Count < 8)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.RawMessage = _msgBuffer.Take(8).ToArray();
|
||||
_msgBuffer.RemoveRange(0, msg.RawMessage.Length);
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.IsFormatError = true;
|
||||
LOG.Error($"invalid response");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers.BaecChiller
|
||||
{
|
||||
//Modbus RTU
|
||||
public abstract class BaecChillerHandler : HandlerBase
|
||||
{
|
||||
public BaecChiller Device { get; }
|
||||
|
||||
public string _command;
|
||||
protected string _parameter;
|
||||
|
||||
protected BaecChillerHandler(BaecChiller device, string command)
|
||||
: base(BuildMessage(ToByteArray(command)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
|
||||
protected BaecChillerHandler(BaecChiller device, string command, string parameter1, short parameter2)
|
||||
: base(BuildMessage(ToByteArray(command), ToByteArray(parameter1), ShortToByteArray(parameter2)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = $"{parameter1},{parameter2}";
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
protected BaecChillerHandler(BaecChiller device, string command, string parameter1, short parameter2, short parameter3)
|
||||
: base(BuildMessage(ToByteArray(command), ToByteArray(parameter1), ShortToByteArray(parameter2), ShortToByteArray(parameter3)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = $"{parameter1},{parameter2},{parameter3}";
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
protected BaecChillerHandler(BaecChiller device, string command, string parameter)
|
||||
: base(BuildMessage(ToByteArray(command), ToByteArray(parameter)))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter;
|
||||
_address = device.SlaveAddress;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
protected BaecChillerHandler(BaecChiller device, string command, byte[] parameter)
|
||||
: base(BuildMessage(ToByteArray(command), parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
//_parameter = parameter;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
private static byte _address = 0x01;
|
||||
|
||||
protected static byte[] BuildMessage(byte[] commandArray, byte[] argumentArray1 = null, byte[] argumentArray2 = null, byte[] argumentArray3 = null)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
|
||||
buffer.Add(_address);
|
||||
|
||||
if (commandArray != null && commandArray.Length > 0)
|
||||
{
|
||||
buffer.AddRange(commandArray);
|
||||
}
|
||||
if (argumentArray1 != null && argumentArray1.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray1);
|
||||
}
|
||||
if (argumentArray2 != null && argumentArray2.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray2.Reverse());
|
||||
}
|
||||
if (argumentArray3 != null && argumentArray3.Length > 0)
|
||||
{
|
||||
buffer.AddRange(argumentArray3.Reverse());
|
||||
}
|
||||
var checkSum = Crc16.CRC16_ModbusRTU(buffer.ToArray());
|
||||
var ret = BitConverter.GetBytes(checkSum);
|
||||
buffer.AddRange(ret);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
protected bool HandleMessage(MessageBase msg)
|
||||
{
|
||||
RisshiChillerMessage response = msg as RisshiChillerMessage;
|
||||
if (!response.IsComplete)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static string Ushort2String(ushort num)
|
||||
{
|
||||
var bytes = UshortToByteArray(num);
|
||||
return string.Join(",", bytes, 0);
|
||||
}
|
||||
|
||||
protected static byte[] ToByteArray(string parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
return new byte[] { };
|
||||
|
||||
return parameter.Split(',').Select(para => Convert.ToByte(para, 16)).ToArray();
|
||||
}
|
||||
protected static byte[] IntToByteArray(int num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected static byte[] UshortToByteArray(ushort num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected static byte[] ShortToByteArray(short num)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(num);
|
||||
return bytes;
|
||||
}
|
||||
protected int ByteArrayToInt(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 4)
|
||||
{
|
||||
int temp = BitConverter.ToInt32(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
protected short ByteArrayToShort(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 2)
|
||||
{
|
||||
short temp = BitConverter.ToInt16(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected ushort ByteArrayToUshort(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 2)
|
||||
{
|
||||
ushort temp = BitConverter.ToUInt16(bytes, 0);
|
||||
return temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class BaecChillerSetOnOffHandler : BaecChillerHandler
|
||||
{
|
||||
public BaecChillerSetOnOffHandler(BaecChiller device, bool isCH1, bool isOn)
|
||||
: base(device, "06", $"{(isCH1 ? "00,00" : "00,01")},{(isOn ? "00,01" : "00,00")}")
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class BaecChillerSetTemperatureHandler : BaecChillerHandler
|
||||
{
|
||||
public BaecChillerSetTemperatureHandler(BaecChiller device, bool isCH1, float temp)
|
||||
: base(device, "06", $"{(isCH1 ? "00,03" : "00,04")}", (short)(temp * 10))
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class BaecChillerSetTemperatureWarningRangeHandler : BaecChillerHandler
|
||||
{
|
||||
public BaecChillerSetTemperatureWarningRangeHandler(BaecChiller device, bool isCH1, float tempHighLimit, float tempLowLimit)
|
||||
: base(device, "10", $"{(isCH1 ? "00,06" : "00,08")}", (short)(tempHighLimit * 10), (short)(tempLowLimit * 10))
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class BaecChillerGetStatusHandler : BaecChillerHandler
|
||||
{
|
||||
public BaecChillerGetStatusHandler(BaecChiller device)
|
||||
: base(device, "03", "00,0C,00,0E")
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
if (HandleMessage(msg))
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
var datas = result.Data.ToList();
|
||||
if (datas.Count == 28)
|
||||
{
|
||||
var reason = string.Empty;
|
||||
var tempCH1 = datas.Skip(0).Take(2).Reverse().ToArray();
|
||||
var tempCH2 = datas.Skip(2).Take(2).Reverse().ToArray();
|
||||
var flowCH1 = datas.Skip(6).Take(2).Reverse().ToArray();
|
||||
var flowCH2 = datas.Skip(8).Take(2).Reverse().ToArray();
|
||||
var warningCH1 = datas.Skip(12).Take(2).Reverse().ToArray();
|
||||
var warningCH2 = datas.Skip(14).Take(2).Reverse().ToArray();
|
||||
var alarmCH1 = datas.Skip(18).Take(2).Reverse().ToArray();
|
||||
var alarmCH2 = datas.Skip(20).Take(2).Reverse().ToArray();
|
||||
var stateCH1 = datas.Skip(24).Take(2).Reverse().ToArray();
|
||||
var stateCH2 = datas.Skip(26).Take(2).Reverse().ToArray();
|
||||
|
||||
Device.CH1TemperatureFeedback = BitConverter.ToInt16(tempCH1, 0) / 10.0f;
|
||||
Device.CH2TemperatureFeedback = BitConverter.ToInt16(tempCH2, 0) / 10.0f;
|
||||
Device.CH1WaterFlow = BitConverter.ToUInt16(flowCH1, 0) / 10.0f;
|
||||
Device.CH2WaterFlow = BitConverter.ToUInt16(flowCH2, 0) / 10.0f;
|
||||
|
||||
var warningCH1Status = BitConverter.ToInt16(warningCH1, 0);
|
||||
var warningCH2Status = BitConverter.ToInt16(warningCH2, 0);
|
||||
Device.IsCH1Warning = (warningCH1Status & 0b_0000_0001) > 0;
|
||||
Device.IsCH2Warning = (warningCH2Status & 0b_0000_0001) > 0;
|
||||
if (Device.IsCH1Warning)
|
||||
{
|
||||
reason += (warningCH1Status & 0b_0000_0010) > 0 ? "CH1 water level low warning," : "";
|
||||
reason += (warningCH1Status & 0b_0000_0100) > 0 ? "CH1 water temperature high warning," : "";
|
||||
reason += (warningCH1Status & 0b_0000_1000) > 0 ? "CH1 water temperature low warning," : "";
|
||||
}
|
||||
if (Device.IsCH2Warning)
|
||||
{
|
||||
reason += (warningCH2Status & 0b_0000_0010) > 0 ? "CH2 water level low warning," : "";
|
||||
reason += (warningCH2Status & 0b_0000_0100) > 0 ? "CH2 water temperature high warning," : "";
|
||||
reason += (warningCH2Status & 0b_0000_1000) > 0 ? "CH2 water temperature low warning," : "";
|
||||
}
|
||||
|
||||
var alarmCH1Status = BitConverter.ToInt16(alarmCH1, 0);
|
||||
var alarmCH2Status = BitConverter.ToInt16(alarmCH2, 0);
|
||||
Device.IsCH1Alarm = (alarmCH1Status & 0b_0000_0001) > 0;
|
||||
Device.IsCH2Alarm = (alarmCH2Status & 0b_0000_0001) > 0;
|
||||
if (Device.IsCH1Alarm)
|
||||
{
|
||||
reason += (alarmCH1Status & 0b_0000_0010) > 0 ? "CH1 water level low alarm," : "";
|
||||
reason += (alarmCH1Status & 0b_0000_0100) > 0 ? "CH1 water temperature high alarm," : "";
|
||||
reason += (alarmCH1Status & 0b_0000_1000) > 0 ? "CH1 water temperature low alarm," : "";
|
||||
reason += (alarmCH1Status & 0b_0001_0000) > 0 ? "CH1 water flow low alarm," : "";
|
||||
}
|
||||
if (Device.IsCH2Alarm)
|
||||
{
|
||||
reason += (alarmCH2Status & 0b_0000_0010) > 0 ? "CH2 water level low alarm," : "";
|
||||
reason += (alarmCH2Status & 0b_0000_0100) > 0 ? "CH2 water temperature high alarm," : "";
|
||||
reason += (alarmCH2Status & 0b_0000_1000) > 0 ? "CH2 water temperature low alarm," : "";
|
||||
reason += (alarmCH2Status & 0b_0001_0000) > 0 ? "CH2 water flow low alarm," : "";
|
||||
}
|
||||
|
||||
Device.IsCH1On = (BitConverter.ToInt16(stateCH1, 0) & 0b_0000_0001) > 0;
|
||||
Device.IsCH2On = (BitConverter.ToInt16(stateCH2, 0) & 0b_0000_0001) > 0;
|
||||
|
||||
Device.NoteError(reason);
|
||||
}
|
||||
|
||||
handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers
|
||||
{
|
||||
public interface IChiller
|
||||
{
|
||||
bool IsRunning { get; }
|
||||
|
||||
bool SetMainPowerOnOff(bool isOn, out string reason);
|
||||
}
|
||||
}
|
||||
+602
@@ -0,0 +1,602 @@
|
||||
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.Chillers.RisshiChiller
|
||||
{
|
||||
public class RisshiChiller : 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 RisshiChillerConnection _connection;
|
||||
public RisshiChillerConnection 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 RisshiChiller(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 RisshiChillerConnection(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 RisshiChillerConnection(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 RisshiChillerQueryPinHandler(this, _deviceAddress));
|
||||
//_lstHandler.AddLast(new RisshiChillerSetCommModeHandler(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 RisshiChillerRawCommandHandler(this, command, comandArgument));
|
||||
}
|
||||
}
|
||||
|
||||
public void PerformRawCommand(string command)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new RisshiChillerRawCommandHandler(this, command));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetTemperature(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
|
||||
}
|
||||
}
|
||||
public void SetTempHighWarning(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
|
||||
}
|
||||
}
|
||||
public void SetTempLowWarning(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
|
||||
}
|
||||
}
|
||||
public void SetRemoteMode(string angle)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWS", angle));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRunMode(string waferSize)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWS", waferSize));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal void NoteActionCompleted(string command)
|
||||
{
|
||||
if(command == "ALIGN")
|
||||
{
|
||||
AlignCompleted = true;
|
||||
}
|
||||
else if(command == "ROTATE")
|
||||
{
|
||||
RotatedCompleted = true;
|
||||
}
|
||||
else if(command == "XFER")
|
||||
{
|
||||
XferCompleted = true;
|
||||
}
|
||||
else if(command == "ALIGNER HOME/SCAN/ALGN")
|
||||
{
|
||||
HomeCompleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteQueryResult(string command, string parameter, string queryResult)
|
||||
{
|
||||
if (command == "HELLO")
|
||||
{
|
||||
if(queryResult == "AG")
|
||||
{
|
||||
CommunicationIsOK = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunicationIsOK = false;
|
||||
}
|
||||
}
|
||||
else if (command == "RWAA")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if(resultArray.Count() == 1)
|
||||
{
|
||||
AlignedAngle = double.Parse(queryResult);
|
||||
}
|
||||
}
|
||||
else if (command == "RWS")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 1)
|
||||
{
|
||||
WaferSize = double.Parse(queryResult);
|
||||
}
|
||||
}
|
||||
else if (command == "RBIASXY")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 2)
|
||||
{
|
||||
BaisX = double.Parse(queryResult.Split(',')[0]);
|
||||
BaisY = double.Parse(queryResult.Split(',')[1]);
|
||||
}
|
||||
}
|
||||
else if (command == "RBIASRT")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 2)
|
||||
{
|
||||
BaisR = double.Parse(queryResult.Split(',')[0]);
|
||||
BaisT = double.Parse(queryResult.Split(',')[1]);
|
||||
}
|
||||
}
|
||||
else if (command == "RNOTCH")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 1)
|
||||
{
|
||||
Notch = double.Parse(queryResult);
|
||||
}
|
||||
}
|
||||
else if (command == "REER")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 1)
|
||||
{
|
||||
Error = "_ERR " + queryResult;
|
||||
}
|
||||
}
|
||||
else if (command == "RWK")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 1)
|
||||
{
|
||||
WafeOnOff = queryResult == "1";
|
||||
}
|
||||
}
|
||||
else if (command == "RAR")
|
||||
{
|
||||
var resultArray = queryResult.Split(',');
|
||||
if (resultArray.Count() == 1)
|
||||
{
|
||||
IsReady = queryResult == "1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(RisshiChillerRawCommandHandler) && ((RisshiChillerHandler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new RisshiChillerRawCommandHandler(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(RisshiChillerRawCommandHandler) && ((RisshiChillerHandler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new RisshiChillerRawCommandHandler(this, command));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RequestTemprature(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "RWAA");
|
||||
}
|
||||
public void RequestCoolFlowRate(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "RWS");
|
||||
}
|
||||
public void RequestResistivity(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "RBIASXY");
|
||||
}
|
||||
public void RequestOperationStatus(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "RBIASRT");
|
||||
}
|
||||
|
||||
public void RequestAlarmStatus(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "RNOTCH");
|
||||
}
|
||||
public void RequestWarningStatus(bool isSelected)
|
||||
{
|
||||
SimpleRequest(isSelected, "REER");
|
||||
}
|
||||
|
||||
|
||||
private void SimpleRequest(bool isSelected, string command)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(RisshiChillerSimpleQueryHandler) && ((RisshiChillerSimpleQueryHandler)handler)._command == command);
|
||||
if (isSelected)
|
||||
{
|
||||
if (!existHandlers.Any())
|
||||
_lstMonitorHandler.AddFirst(new RisshiChillerSimpleQueryHandler(this, command));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existHandlers.Any())
|
||||
{
|
||||
_lstMonitorHandler.Remove(existHandlers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public string Error { get; private set; }
|
||||
public bool SevoOnOff { get; private set; }
|
||||
public bool AlignCompleted { get; private set; }
|
||||
public bool RotatedCompleted { get; private set; }
|
||||
public double AlignAngleSet { get; private set; }
|
||||
public double WaferSizeSet { get; private set; }
|
||||
public double WaferSize { get; private set; }
|
||||
public bool XferCompleted { get; private set; }
|
||||
public bool HomeCompleted { get; private set; }
|
||||
public bool CommunicationIsOK { get; private set; }
|
||||
public double AlignedAngle { get; private set; }
|
||||
public double BaisX { get; private set; }
|
||||
public double BaisY { get; private set; }
|
||||
public double BaisR { get; private set; }
|
||||
public double BaisT { get; private set; }
|
||||
public double Notch { get; private set; }
|
||||
public bool WafeOnOff { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
public string LastPickInfo { get; private set; }
|
||||
public string LastPlaceInfo { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Note Functions
|
||||
private R_TRIG _trigWarningMessage = new R_TRIG();
|
||||
|
||||
|
||||
|
||||
public void NoteError(string reason)
|
||||
{
|
||||
CommunicationIsOK = false;
|
||||
if (reason != null)
|
||||
{
|
||||
_trigWarningMessage.CLK = true;
|
||||
if (_trigWarningMessage.Q)
|
||||
{
|
||||
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
|
||||
}
|
||||
Error = reason;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = null;
|
||||
}
|
||||
}
|
||||
|
||||
internal void NoteLastPickInfo(string sendText)
|
||||
{
|
||||
LastPickInfo = sendText;
|
||||
}
|
||||
internal void NoteLastPlaceInfo(string sendText)
|
||||
{
|
||||
LastPlaceInfo = sendText;
|
||||
}
|
||||
internal void NoteSevoOnOff(bool isOn)
|
||||
{
|
||||
SevoOnOff = isOn;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
public class XferArgument
|
||||
{
|
||||
public string Arm { get; set; }
|
||||
public int FromStation { get; set; }
|
||||
public int FromSlot { get; set; }
|
||||
public int ToStation { get; set; }
|
||||
public int ToSlot { get; set; }
|
||||
public string AlignCommand { get; set; }
|
||||
}
|
||||
public class PickPlaceArgument
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Station { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Slot { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Arm { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Step { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Offset { get; set; }
|
||||
|
||||
public string AlignCommand { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers.RisshiChiller
|
||||
{
|
||||
public class RisshiChillerMessage : AsciiMessage
|
||||
{
|
||||
public string Data { get; set; }
|
||||
public string ErrorText { get; set; }
|
||||
}
|
||||
|
||||
public class RisshiChillerConnection : SerialPortConnectionBase
|
||||
{
|
||||
private static char _endLine = (char)3;
|
||||
//private bool _isAckMode = false;//should read from config file
|
||||
|
||||
private string _cachedBuffer = string.Empty;
|
||||
|
||||
public RisshiChillerConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
|
||||
: base(portName, baudRate, dataBits, parity, stopBits, _endLine.ToString(), true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool SendMessage(byte[] message)
|
||||
{
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
|
||||
protected override MessageBase ParseResponse(string rawText)
|
||||
{
|
||||
RisshiChillerMessage msg = new RisshiChillerMessage();
|
||||
msg.RawMessage = rawText;
|
||||
|
||||
if (rawText.Length <= 0)
|
||||
{
|
||||
LOG.Error($"empty response,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
if (rawText.Length <= 4)
|
||||
{
|
||||
LOG.Error($"too short response,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
rawText = rawText.Substring(1, rawText.Length - 2);//remove start char and end char
|
||||
|
||||
if(!CheckSum(rawText))
|
||||
{
|
||||
LOG.Error($"check sum failed,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
|
||||
rawText = rawText.Substring(2, rawText.Length - 4);// remove length and sum
|
||||
if (rawText.Contains("_ERR"))
|
||||
{
|
||||
msg.IsError = true;
|
||||
|
||||
var rewTextArray = rawText.Split(' ');
|
||||
msg.Data = rewTextArray[1];
|
||||
}
|
||||
else if (rawText == "_RDY")
|
||||
{
|
||||
msg.Data = rawText;
|
||||
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Data = rawText;
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
private bool CheckSum(string responseContent)
|
||||
{
|
||||
string responseSum = responseContent.Substring(responseContent.Length - 2);
|
||||
string checkContent = responseContent.Substring(0, responseContent.Length - 2);
|
||||
var charArray = checkContent.ToArray();
|
||||
int sum = charArray.Sum(chr => (int)chr);
|
||||
string sSum = sum.ToString("X");
|
||||
|
||||
if (sSum.Length < 2)
|
||||
sSum = "0" + sSum;
|
||||
else
|
||||
sSum = sSum.Substring(sSum.Length - 2);
|
||||
|
||||
return responseSum == sSum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+351
@@ -0,0 +1,351 @@
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers.RisshiChiller
|
||||
{
|
||||
public abstract class RisshiChillerHandler : HandlerBase
|
||||
{
|
||||
public RisshiChiller Device { get; }
|
||||
|
||||
public string _command;
|
||||
protected string _parameter;
|
||||
|
||||
|
||||
protected RisshiChillerHandler(RisshiChiller device, string command, string parameter = null)
|
||||
: base(BuildMessage(command, parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter;
|
||||
Name = command;
|
||||
}
|
||||
|
||||
private static char _startLine = (char)1;
|
||||
private static char _endLine = (char)3;
|
||||
private static string BuildMessage( string command, string parameter)
|
||||
{
|
||||
command = "ALIG " + command;
|
||||
string commandContent = parameter == null ? $"{command}" : $"{command} {parameter}";
|
||||
|
||||
string sLength = commandContent.Length.ToString("D2");
|
||||
var charArray = (sLength + commandContent).ToArray();
|
||||
int sum = charArray.Sum(chr => (int)chr);
|
||||
string sSum = sum.ToString("X");
|
||||
|
||||
if (sSum.Length < 2)
|
||||
return _startLine + sLength + commandContent + "0" + sSum + _endLine.ToString();
|
||||
else
|
||||
return _startLine + sLength + commandContent + sSum.Substring(sSum.Length - 2) + _endLine.ToString();
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
RisshiChillerMessage response = msg as RisshiChillerMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
SetState(EnumHandlerState.Acked);
|
||||
}
|
||||
|
||||
|
||||
if (response.IsResponse)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RisshiChillerRawCommandHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerRawCommandHandler(RisshiChiller device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
Device.NoteRawCommandInfo(_command, result.RawMessage);
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class RisshiChillerXferHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerXferHandler(RisshiChiller device, string jsonParameter)
|
||||
: base(device, "XFER", BuildCommandParameter(jsonParameter))
|
||||
{
|
||||
|
||||
}
|
||||
static string BuildCommandParameter(string jsonParameter)
|
||||
{
|
||||
JObject jsonObject = JObject.Parse(jsonParameter);
|
||||
StringBuilder paraBuilder = new StringBuilder();
|
||||
foreach (var item in jsonObject)
|
||||
{
|
||||
if (item.Key.Contains("Slot") || item.Key == "Arm")
|
||||
paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
|
||||
else if(item.Value!=null && item.Value.ToString().Length > 0)
|
||||
paraBuilder.Append(" " + item.Value);
|
||||
}
|
||||
|
||||
return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
|
||||
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteActionCompleted(_command);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
public class RisshiChillerPickHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerPickHandler(RisshiChiller device, string jsonParameter)
|
||||
: base(device, "PICK", BuildCommandParameter(jsonParameter))
|
||||
{
|
||||
}
|
||||
|
||||
//N 2 R EX Z DOWN SLOT 1 ARM A
|
||||
static string BuildCommandParameter(string jsonParameter)
|
||||
{
|
||||
JObject jsonObject = JObject.Parse(jsonParameter);
|
||||
StringBuilder paraBuilder = new StringBuilder();
|
||||
foreach (var item in jsonObject)
|
||||
{
|
||||
if (paraBuilder.Length == 0)
|
||||
{
|
||||
paraBuilder.Append(item.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(item.Key == "Slot" || item.Key == "Arm")
|
||||
paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
|
||||
else
|
||||
paraBuilder.Append(" " + item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
|
||||
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteLastPickInfo(SendText);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RisshiChillerPlaceHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerPlaceHandler(RisshiChiller device, string jsonParameter)
|
||||
: base(device, "PLACE", BuildCommandParameter(jsonParameter))
|
||||
{
|
||||
}
|
||||
|
||||
static string BuildCommandParameter(string jsonParameter)
|
||||
{
|
||||
JObject jsonObject = JObject.Parse(jsonParameter);
|
||||
StringBuilder paraBuilder = new StringBuilder();
|
||||
foreach (var item in jsonObject)
|
||||
{
|
||||
if (paraBuilder.Length == 0)
|
||||
{
|
||||
paraBuilder.Append(item.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Key == "Slot" || item.Key == "Arm")
|
||||
paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
|
||||
else
|
||||
paraBuilder.Append(" " + item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
|
||||
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteLastPlaceInfo(SendText);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class RisshiChillerSimpleActionHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerSimpleActionHandler(RisshiChiller device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteActionCompleted(_command);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public class RisshiChillerSimpleSetHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerSimpleSetHandler(RisshiChiller device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteSetCompleted(_command,_parameter);
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class RisshiChillerSevoOnOffHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerSevoOnOffHandler(RisshiChiller device, bool isOn)
|
||||
: base(device, isOn ? "SVON" : "SVOFF")
|
||||
{
|
||||
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteSevoOnOff(_command == "SVON");
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class RisshiChillerSimpleQueryHandler : RisshiChillerHandler
|
||||
{
|
||||
public RisshiChillerSimpleQueryHandler(RisshiChiller device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool handled)
|
||||
{
|
||||
var result = msg as RisshiChillerMessage;
|
||||
|
||||
if (result.IsError)
|
||||
{
|
||||
Device.NoteError(result.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
var resultArray = result.Data.Split(' ');
|
||||
if(resultArray.Count() >= 2 && resultArray[0] == _command)
|
||||
{
|
||||
Device.NoteError(null);
|
||||
Device.NoteQueryResult(_command, _parameter, string.Join(",", resultArray, 1, resultArray.Count()-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.NoteError($"Invalid Response '{result.Data}' for command: {_command}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ResponseMessage = msg;
|
||||
handled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user