首次上传

This commit is contained in:
hanqiangqiang
2026-06-15 10:56:30 +08:00
commit b0213b94d6
4160 changed files with 736101 additions and 0 deletions
@@ -0,0 +1,93 @@
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TurboPumps.PfeifferHipace
{
public class HipaceMessage : AsciiMessage
{
public string DeviceAddress { get; set; }
public string Action { get; set; }
public string Parameter { get; set; }
public int DataLength { get; set; }
public string Data { get; set; }
public string ErrorText { get; set; }
}
public class HipaceConnection : SerialPortConnectionBase
{
public HipaceConnection(string portName) : base(portName)
{
}
protected override MessageBase ParseResponse(string rawText)
{
HipaceMessage msg = new HipaceMessage();
msg.RawMessage = rawText;
if (rawText.Length <= 14)
{
LOG.Error($"text length check failed, " + rawText);
msg.IsFormatError = true;
return msg;
}
msg.MessagePart = new string[6];
msg.MessagePart[0] = rawText.Substring(0, 3); //device address
msg.MessagePart[1] = rawText.Substring(3, 2); // action
msg.MessagePart[2] = rawText.Substring(5, 3); //parameter
msg.MessagePart[3] = rawText.Substring(8, 2); //length
if (!int.TryParse(msg.MessagePart[3], out int length))
{
LOG.Error($"text {msg.MessagePart[3]} not valid, " + rawText);
msg.IsFormatError = true;
return msg;
}
msg.MessagePart[4] = rawText.Substring(10, length); //data
msg.MessagePart[5] = rawText.Substring(10 + length, 3);
if (!int.TryParse(msg.MessagePart[5], out int sum))
{
LOG.Error($"text {msg.MessagePart[5]} not valid, " + rawText);
msg.IsFormatError = true;
return msg;
}
int checkSum = 0;
string checkText = rawText.Substring(0, rawText.Length - 3 - 1);
foreach (var item in checkText)
{
checkSum += (int)item;
}
if (checkSum % 256 != sum)
{
LOG.Error($"check sum failed, " + rawText);
msg.IsFormatError = true;
return msg;
}
msg.DeviceAddress = msg.MessagePart[0];
msg.Action = msg.MessagePart[1];
msg.Parameter = msg.MessagePart[2];
msg.DataLength = length;
msg.Data = msg.MessagePart[4];
if (msg.Data == "NO_DEF" || msg.Data=="_RANGE" || msg.Data=="_LOGIC")
{
msg.IsError = true;
}
msg.IsResponse = true;
msg.IsAck = true;
msg.IsComplete = true;
return msg;
}
}
}
@@ -0,0 +1,343 @@
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TurboPumps.PfeifferHipace
{
public abstract class HipaceHandler : HandlerBase
{
protected const string QueryDataText = "=?";
public HipaceTurboPump PumpDevice { get; }
protected HipaceHandler(HipaceTurboPump pump, string deviceAddress, bool isQuery, string parameter, string data)
: base(BuildMessage(deviceAddress, isQuery, parameter, data))
{
PumpDevice = pump;
}
private static string BuildMessage(string deviceAddress, bool isQuery, string parameter, string data)
{
string msg = deviceAddress + (isQuery ? "00" : "10") + parameter + data.Length.ToString("D2") + data;
return msg + CalcSum(msg).ToString("D3") + "\r";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
ResponseMessage = msg;
handled = true;
return true;
}
private static int CalcSum(string value)
{
int sum = 0;
foreach (var item in value)
{
sum += (int)item;
}
return sum % 256;
}
}
//010
public class HipacePumpStationHandler : HipaceHandler
{
public HipacePumpStationHandler(HipaceTurboPump pump, string deviceAddress, bool isOn, bool isQuery)
: base(pump, deviceAddress, isQuery, "010", isQuery ? QueryDataText : (isOn ? "111111" : "000000"))
{
Name = "Pump " + (isOn ? "On" : "Off");
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (result.Data == "111111")
{
PumpDevice.NoteOnOff(true);
}
else if (result.Data == "000000")
{
PumpDevice.NoteOnOff(false);
}
else
{
PumpDevice.SetError(result.Data + " format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//023
public class HipaceMotorPumpHandler : HipaceHandler
{
public HipaceMotorPumpHandler(HipaceTurboPump pump, string deviceAddress, bool isOn)
: base(pump, deviceAddress, false, "023", isOn ? "111111" : "000000")
{
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (result.Data == "111111")
{
PumpDevice.NoteOnOff(true);
}
else if (result.Data == "000000")
{
PumpDevice.NoteOnOff(false);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//303
public class HipaceQueryErrorHandler : HipaceHandler
{
public HipaceQueryErrorHandler(HipaceTurboPump pump, string deviceAddress)
: base(pump, deviceAddress, true, "303", QueryDataText)
{
Name = "Query Error";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (int.TryParse(result.Data, out int code))
{
PumpDevice.SetErrorCode(code);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//398
public class HipaceQuerySpeedHandler : HipaceHandler
{
public HipaceQuerySpeedHandler(HipaceTurboPump pump, string deviceAddress)
: base(pump, deviceAddress, true, "398", QueryDataText)
{
Name = "Query Speed";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (int.TryParse(result.Data, out int value))
{
PumpDevice.SetSpeed(value);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//346
public class HipaceQueryTemperatureHandler : HipaceHandler
{
public HipaceQueryTemperatureHandler(HipaceTurboPump pump, string deviceAddress)
: base(pump, deviceAddress, true, "346", QueryDataText)
{
Name = "Query Temperature";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (int.TryParse(result.Data, out int value))
{
PumpDevice.SetTemperature(value);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//307
public class HipaceAccelerateHandler : HipaceHandler
{
public HipaceAccelerateHandler(HipaceTurboPump pump, string deviceAddress)
: base(pump, deviceAddress, true, "307", QueryDataText)
{
Name = "Query Accelerate";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (result.Data == "111111")
{
PumpDevice.SetIsAccelerate(true);
}
else if (result.Data == "000000")
{
PumpDevice.SetIsAccelerate(false);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//306
public class HipaceAtSpeedHandler : HipaceHandler
{
public HipaceAtSpeedHandler(HipaceTurboPump pump, string deviceAddress)
: base(pump, deviceAddress, true, "306", QueryDataText)
{
Name = "Query At Speed";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (result.Data == "111111")
{
PumpDevice.SetAtSpeed(true);
}
else if (result.Data == "000000")
{
PumpDevice.SetAtSpeed(false);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
//305
public class HipaceOverTempHandler : HipaceHandler
{
public HipaceOverTempHandler(HipaceTurboPump pump, string deviceAddress)
: base(pump, deviceAddress, true, "305", QueryDataText)
{
Name = "Query over temp";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HipaceMessage;
if (result.IsError)
{
PumpDevice.SetError(result.Data);
}
else
{
if (result.Data == "111111")
{
PumpDevice.SetOverTemp(true);
}
else if (result.Data == "000000")
{
PumpDevice.SetOverTemp(false);
}
else
{
PumpDevice.SetError(result.Data + "format error");
}
}
ResponseMessage = msg;
handled = true;
return true;
}
}
}
@@ -0,0 +1,331 @@
using System;
using System.Collections.Generic;
using Aitex.Core.Common.DeviceData;
using Aitex.Core.RT.DataCenter;
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;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TurboPumps.PfeifferHipace
{
public class HipaceTurboPump : PumpBase
{
public override bool IsError
{
get { return _errorCode != 0; }
}
public override bool IsOn
{
get { return _isOn; }
}
public override float Speed
{
get { return _speed; }
}
public override float Temperature
{
get { return _temperature; }
}
public override bool IsStable
{
get { return _isAtSpeed; }
}
public override AITPumpData DeviceData
{
get
{
AITPumpData data = new AITPumpData()
{
DeviceName = Name,
DeviceSchematicId = DeviceID,
DisplayName = Display,
DeviceModule = Module,
IsError = IsError,
IsOn = _isOn,
Speed = _speed,
Temperature = _temperature,
AtSpeed = _isAtSpeed,
OverTemp = _isOverTemp,
};
return data;
}
}
private HipaceConnection _connection;
private string _deviceAddress = "001";
private int _speed;
private int _temperature;
private bool _isOn;
private int _power;
private bool _isAccelerate;
private bool _isAtSpeed;
private bool _isOverTemp;
private bool _activeMonitorStatus;
private int _errorCode;
private RD_TRIG _trigPumpOnOff = new RD_TRIG();
private R_TRIG _trigError = new R_TRIG();
private R_TRIG _trigOverTemp = new R_TRIG();
private R_TRIG _trigWarningMessage = new R_TRIG();
private string _lastError = string.Empty;
private R_TRIG _trigCommunicationError = new R_TRIG();
private R_TRIG _trigRetryConnect = new R_TRIG();
private PeriodicJob _thread;
private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
private object _locker = new object();
private bool _enableLog = true;
private string _scRoot;
public HipaceTurboPump(string module, string name, string scRoot) : base(module, name)
{
_scRoot = scRoot;
_activeMonitorStatus = true;
_power = 0;
}
public override bool Initialize()
{
if(_connection != null && _connection.IsConnected)
{
return true;
}
base.Initialize();
DATA.Subscribe($"{Module}.{Name}.Power", () => _power);
DATA.Subscribe($"{Module}.{Name}.ErrorCode", () => _errorCode);
DATA.Subscribe($"{Module}.{Name}.IsAtSpeed", () => _isAtSpeed);
DATA.Subscribe($"{Module}.{Name}.IsAccelerate", () => _isAccelerate);
string portName = SC.GetStringValue($"{_scRoot}.{Module}.{Name}.Address");
int address = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.DeviceAddress");
_deviceAddress = address.ToString("D3");
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
_connection = new HipaceConnection(portName);
_connection.EnableLog(_enableLog);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
return true;
}
private bool OnTimer()
{
try
{
//temp comment ??
//_connection.MonitorTimeout();
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{Module}.{Name}.Address"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
}
return true;
}
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0 && _activeMonitorStatus)
{
_lstHandler.AddLast(new HipaceQueryErrorHandler(this, _deviceAddress));
_lstHandler.AddLast(new HipaceQuerySpeedHandler(this, _deviceAddress));
_lstHandler.AddLast(new HipaceQueryTemperatureHandler(this, _deviceAddress));
_lstHandler.AddLast(new HipacePumpStationHandler(this, _deviceAddress, true, true));
_lstHandler.AddLast(new HipaceAtSpeedHandler(this, _deviceAddress));
_lstHandler.AddLast(new HipaceAccelerateHandler(this, _deviceAddress));
_lstHandler.AddLast(new HipaceOverTempHandler(this, _deviceAddress));
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
_lstHandler.RemoveFirst();
}
}
if (handler != null)
{
_connection.Execute(handler);
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return true;
}
public override void Monitor()
{
try
{
_connection.EnableLog(_enableLog);
_trigPumpOnOff.CLK = _isOn;
if (_trigPumpOnOff.R)
{
EV.PostInfoLog(Module, $"{Module}.{Name} is on");
}
if (_trigPumpOnOff.T)
{
EV.PostInfoLog(Module, $"{Module}.{Name} is off");
}
_trigError.CLK = IsError;
if (_trigError.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} is error, error code {_errorCode:D3}");
}
_trigOverTemp.CLK = _isOverTemp;
if (_trigOverTemp.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} is over temperature");
}
_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;
_trigOverTemp.RST = true;
_trigWarningMessage.RST = true;
_connection.SetCommunicationError(false, "");
_trigCommunicationError.RST = true;
_enableLog = SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
_trigRetryConnect.RST = true;
base.Reset();
}
public override void SetPumpOnOff(bool isOn)
{
lock (_locker)
{
_lstHandler.AddLast(new HipacePumpStationHandler(this, _deviceAddress, isOn, false));
}
}
public void SetActiveMonitor(bool active)
{
_activeMonitorStatus = active;
}
internal void NoteOnOff(bool isOn)
{
_isOn = isOn;
}
public void SetSpeed(int speed)
{
_speed = speed;
}
public void SetTemperature(int temperature)
{
_temperature = temperature;
}
public void SetErrorCode(int errorCode)
{
_errorCode = errorCode;
}
public void SetAtSpeed(bool atSpeed)
{
_isAtSpeed = atSpeed;
}
public void SetOverTemp(bool overTemp)
{
_isOverTemp = overTemp;
}
public void SetIsAccelerate(bool isAccelerate)
{
_isAccelerate = isAccelerate;
}
public void SetError(string reason)
{
_trigWarningMessage.CLK = true;
if (_trigWarningMessage.Q)
{
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
}
}
}
}