首次上传

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,278 @@
using System;
using System.Collections.Generic;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.MayAir
{
public class FfuMayAir : BaseDevice, IConnection
{
private FfuMayAirConnection _connection;
private string _deviceAddress = "001";
private bool _isOn;
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 string Address
{
get
{
return "";
}
}
public bool IsConnected
{
get
{
return _connection!=null && _connection.IsConnected;
}
}
public bool Connect()
{
return true;
}
public bool Disconnect()
{
return true;
}
public FfuMayAir(string module, string name, string scRoot) : base(module, name, name, name)
{
_scRoot = scRoot;
_activeMonitorStatus = true;
}
public void QuerySpeed()
{
}
public void ResetDevice()
{
}
public void QueryError()
{
_lstHandler.AddLast(new FfuMayAirQueryStatusHandler(this, 1, 0));
EV.PostInfoLog(Module, "Query error");
}
public bool 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 FfuMayAirConnection(portName);
_connection.EnableLog(_enableLog);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
_thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
return true;
}
private bool OnTimer()
{
try
{
_connection.MonitorTimeout();
if (!_connection.IsConnected || _connection.IsCommunicationError)
{
lock (_locker)
{
_lstHandler.Clear();
}
_trigRetryConnect.CLK = !_connection.IsConnected;
if (_trigRetryConnect.Q)
{
_connection.SetPortAddress(SC.GetStringValue($"{Module}.{Name}.Address"));
if (!_connection.Connect())
{
EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
}
}
return true;
}
HandlerBase handler = null;
if (!_connection.IsBusy)
{
lock (_locker)
{
if (_lstHandler.Count == 0 && _activeMonitorStatus)
{
}
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 NoteError()
{
}
public 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");
}
_trigCommunicationError.CLK = _connection.IsCommunicationError;
if (_trigCommunicationError.Q)
{
EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
}
public 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;
}
public void SetPumpOnOff(bool isOn)
{
lock (_locker)
{
}
}
public void SetActiveMonitor(bool active)
{
_activeMonitorStatus = active;
}
internal void NoteOnOff(bool isOn)
{
_isOn = isOn;
}
public void SetSpeed(float speed)
{
}
public void SetErrorCode(int errorCode)
{
_errorCode = errorCode;
}
public void SetError(string reason)
{
_trigWarningMessage.CLK = true;
if (_trigWarningMessage.Q)
{
EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
}
}
}
}
@@ -0,0 +1,93 @@
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.MayAir
{
public class FfuMayAirMessage : BinaryMessage
{
public byte Prefix { get; set; }
public byte Action { get; set; }
public byte Command { get; set; }
public byte DeviceAddress { get; set; }
public byte GroupAddress { get; set; }
public byte Data1 { get; set; }
public byte Data2 { get; set; }
}
public class FfuMayAirConnection : SerialPortConnectionBase
{
public FfuMayAirConnection(string portName) : base(portName)
{
}
protected override MessageBase ParseResponse(byte[] rawMessage)
{
FfuMayAirMessage msg = new FfuMayAirMessage();
//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,123 @@
using System.Collections.Generic;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.MayAir
{
public abstract class FfuMayAirHandler : HandlerBase
{
public FfuMayAir Device { get; }
protected FfuMayAirHandler(FfuMayAir device, byte prefix, byte command, byte deviceAddress, byte groupAddress, byte data1, byte data2)
: base(BuildMessage(prefix, command, deviceAddress, groupAddress, data1, data2))
{
Device = device;
}
protected FfuMayAirHandler(FfuMayAir device, byte prefix, byte command, byte deviceAddress, byte groupAddress, byte data1)
: base(BuildMessage(prefix, command, deviceAddress, groupAddress, data1))
{
Device = device;
}
protected FfuMayAirHandler(FfuMayAir device, byte prefix, byte command, byte deviceAddress, byte groupAddress)
: base(BuildMessage(prefix, command, deviceAddress, groupAddress))
{
Device = device;
}
private static byte[] BuildMessage(byte prefix, byte command, byte deviceAddress, byte groupAddress)
{
List<byte> result = new List<byte>() { prefix, (byte)(command | deviceAddress), groupAddress };
result.Add(CalcSum(result));
return result.ToArray();
}
private static byte[] BuildMessage(byte prefix, byte command, byte deviceAddress, byte groupAddress, byte data1)
{
List<byte> result = new List<byte>(){prefix, (byte)(command | deviceAddress), groupAddress, data1};
result.Add(CalcSum(result));
return result.ToArray();
}
private static byte[] BuildMessage(byte prefix, byte command, byte deviceAddress, byte groupAddress, byte data1, byte data2)
{
List<byte> result = new List<byte>() { prefix, (byte)(command | deviceAddress), groupAddress, data1, data2 };
result.Add(CalcSum(result));
return result.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
ResponseMessage = msg;
handled = true;
return true;
}
private static byte CalcSum(List<byte> value)
{
int sum = 0;
foreach (var item in value)
{
sum += (int)item;
}
return 0;
}
}
public class FfuMayAirQuerySpeedHandler : FfuMayAirHandler
{
public FfuMayAirQuerySpeedHandler(FfuMayAir device, byte deviceAddress, byte groupAddress)
: base(device, 0x15, 0x20, deviceAddress, groupAddress)
{
Name = "Query Speed";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuMayAirMessage;
ResponseMessage = msg;
handled = true;
return true;
}
}
public class FfuMayAirQueryStatusHandler : FfuMayAirHandler
{
public FfuMayAirQueryStatusHandler(FfuMayAir device, byte deviceAddress, byte groupAddress)
: base(device, 0x35, 0x00, deviceAddress, groupAddress, 0x00)
{
Name = "Query Status";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuMayAirMessage;
//if (result.IsError)
//{
// Device.SetError(result.Data);
//}
//else
//{
// if (int.TryParse(result.Data, out int code))
// {
// Device.SetErrorCode(code);
// }
// else
// {
// Device.SetError(result.Data + "format error");
// }
//}
ResponseMessage = msg;
handled = true;
return true;
}
}
}