首次上传

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,631 @@
using System;
using System.Collections.Generic;
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.OperationCenter;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.Communications;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.Aire
{
public class FfuAAF : BaseDevice, IConnection, IDevice
{
private FfuAAFConnection _connection;
private string _deviceAddress = "001";
public byte DeviceAddress { get; set; }
public byte GroupAddress { get; set; }
public byte Speedfactor { get; set; }
public int MaxSpeed1 { get; set; }
public int MaxSpeed2 { get; set; }
public int MaxSpeed3 { get; set; }
public int Status { get; set; }
private bool _isOn;
private bool _activeMonitorStatus;
private int _nMaxSpeed = 0;
public int NMaxSpeed { get => _nMaxSpeed; }
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;
private AsyncSerial serialPort;
private int _ffuSpeed;
private string[] StatusStringList = new string[] { "normal", "running fault", "stop fault" };
public int Speed
{
get { return _ffuSpeed; }
set { _ffuSpeed = value; }
}
public string Address
{
get; set;
}
public bool IsConnected
{
get
{
return _connection != null && _connection.IsConnected;
}
}
public bool Connect()
{
return true;
}
public bool Disconnect()
{
return true;
}
public FfuAAF(string scRoot, string module, string name, string port) : base(module, name, name, name)
{
_scRoot = scRoot;
_activeMonitorStatus = true;
//serialPort = new AsyncSerial(port, 9600, 8);
//serialPort.OnDataChanged += (OnDataChanged);
//serialPort.OnErrorHappened += (OnErrorHandler);
}
private void OnErrorHandler(ErrorEventArgs args)
{
}
private void OnDataChanged(string message)
{
}
public void SetGroupAddress(byte newGroupAddress)
{
_lstHandler.AddLast(new FfuAAFSetGroupAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x00, newGroupAddress }));
}
public void GetGroupAddress()
{
_lstHandler.AddLast(new FfuAAFGetGroupAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x00 }));
}
public void SetDeviceAddress(byte newDeviceAddress)
{
_lstHandler.AddLast(new FfuAAFSetAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x01, newDeviceAddress }));
}
public void GetDeviceAddress()
{
_lstHandler.AddLast(new FfuAAFGetAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x01 }));
}
public void QueryMaxSpeed1()
{
_lstHandler.AddLast(new FfuAAFQueryMaxSpeed1Handler(this, DeviceAddress, GroupAddress, new byte[] { 0x08 }));
}
public void QueryMaxSpeed2()
{
_lstHandler.AddLast(new FfuAAFQueryMaxSpeed2Handler(this, DeviceAddress, GroupAddress, new byte[] { 0x09 }));
}
public void QueryMaxSpeed3()
{
_lstHandler.AddLast(new FfuAAFQueryMaxSpeed3Handler(this, DeviceAddress, GroupAddress, new byte[] { 0x0a }));
}
/// <summary>
/// 查转速因子
/// </summary>
public void QuerySpeedFactor()
{
_lstHandler.AddLast(new FfuAAFQuerySpeedFactorHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x11 }));
}
public void SetSpeedFactor(byte newSpeedFactor)
{
_lstHandler.AddLast(new FfuAAFSetSpeedFactorHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x11, newSpeedFactor }));
}
public void QuerySpeed()
{
_lstHandler.AddLast(new FfuAAFQuerySpeedHandler(this, DeviceAddress, GroupAddress));
}
public void SetSpeed(int speed)
{
_lstHandler.AddLast(new FfuAAFSetSpeedHandler(this, DeviceAddress, GroupAddress, new byte[] { (byte)(speed * 250.0 / MaxSpeed2) }));
}
public void ResetDevice()
{
_lstHandler.AddLast(new FfuAAFResetDeviceHandler(this, DeviceAddress, GroupAddress));
}
public void QueryError()
{
_lstHandler.AddLast(new FfuAAFQueryStatusHandler(this, DeviceAddress, GroupAddress));
EV.PostInfoLog(Module, "Query error");
}
private int ChangedStatus(int value)
{
int returnValue = 0;
switch (value)
{
case 0:
returnValue = 0;
break;
case 0x80:
returnValue = 1;
break;
case 0x10:
returnValue = 2;
break;
default:
break;
}
return returnValue;
}
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");
Address = portName;
int address = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.DeviceAddress");
DeviceAddress = (byte)address;
DATA.Subscribe($"{Name}.DeviceAddress", () => DeviceAddress);
GroupAddress = (byte)SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.GroupAddress");
DATA.Subscribe($"{Name}.GroupAddress", () => GroupAddress);
Status = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.Status");
DATA.Subscribe($"{Name}.Status", () => StatusStringList[ChangedStatus(Status)]);
_deviceAddress = address.ToString("D3");
_enableLog = SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
Speedfactor = (byte)SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.Speedfactor");
DATA.Subscribe($"{Name}.Speedfactor", () => Speedfactor);
// _nMaxSpeed = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed1");
MaxSpeed1 = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed1");
DATA.Subscribe($"{Name}.MaxSpeed1", () => MaxSpeed1);
MaxSpeed2 = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed2");
DATA.Subscribe($"{Name}.MaxSpeed2", () => MaxSpeed2);
MaxSpeed3 = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed3");
DATA.Subscribe($"{Name}.MaxSpeed3", () => MaxSpeed3);
_connection = new FfuAAFConnection(portName);
_connection.EnableLog(_enableLog);
if (_connection.Connect())
{
EV.PostInfoLog(Module, $"{Module}.{Name} connected");
}
_thread = new PeriodicJob(1000, OnTimer, $"{Name} MonitorHandler", true);
_ffuSpeed = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.Speed");
DATA.Subscribe($"{Name}.Speed", () => _ffuSpeed);
OP.Subscribe($"{Name}SetFFUGroupAddress", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Set FFU Group Address.");
return false;
}
int.TryParse((string)param[2], out var newgroupAddress);
GroupAddress = (byte)newgroupAddress;
SetGroupAddress((byte)newgroupAddress);
EV.PostInfoLog(Module, $"{Name}Set FFU Group Address {newgroupAddress}");
return true;
});
OP.Subscribe($"{Name}GetFFUGroupAddress", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU Group Address.");
return false;
}
GetGroupAddress();
EV.PostInfoLog(Module, $"{Name}Get FFU Group Address {groupAddress}");
return true;
});
OP.Subscribe($"{Name}SetFFUDeviceAddress", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Set FFU Device Address.");
return false;
}
int.TryParse((string)param[2], out var newAddress);
SetDeviceAddress((byte)newAddress);
EV.PostInfoLog(Module, $"{Name}Set FFU Device Address {newAddress}");
return true;
});
OP.Subscribe($"{Name}GetFFUDeviceAddress", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU Device Address.");
return false;
}
GetDeviceAddress();
EV.PostInfoLog(Module, $"{Name}Get FFU Device Address {groupAddress}");
return true;
});
OP.Subscribe($"{Name}SetFFUSpeedfactor", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Set FFU speed factor.");
return false;
}
int.TryParse((string)param[2], out var newSpeedFactor);
SetSpeedFactor((byte)newSpeedFactor);
EV.PostInfoLog(Module, $"{Name}Set FFU speed factor {newSpeedFactor}");
return true;
});
OP.Subscribe($"{Name}GetFFUSpeedfactor", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU speed factor.");
return false;
}
QuerySpeedFactor();
EV.PostInfoLog(Module, $"{Name}Get FFU speed factor {groupAddress}");
return true;
});
OP.Subscribe($"{Name}GetFFUStatus", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU Status.");
return false;
}
QueryError();
EV.PostInfoLog(Module, $"{Name}Get FFU Status {groupAddress}");
return true;
});
OP.Subscribe($"{Name}SetFFUSpeed", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "invalid speed.");
return false;
}
int.TryParse((string)param[2], out var speed);
//SetSpeed((int)(speed * 250 * 1.0 / 1440));
SetSpeed(speed);
EV.PostInfoLog(Module, $"{Name} speed set to {speed}");
return true;
});
OP.Subscribe($"{Name}GetFFUSpeed", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "FFU Query speed.");
return false;
}
QuerySpeed();
EV.PostInfoLog(Module, $"{Name}FFU Query Speed {groupAddress}");
return true;
});
OP.Subscribe($"{Name}GetFFUMaxSpeed1", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU GetFFUMaxSpeed1.");
return false;
}
QueryMaxSpeed1();
EV.PostInfoLog(Module, $"{Name}Get FFU GetFFUMaxSpeed1 {groupAddress}");
return true;
});
OP.Subscribe($"{Name}GetFFUMaxSpeed2", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU GetFFUMaxSpeed2.");
return false;
}
QueryMaxSpeed2();
EV.PostInfoLog(Module, $"{Name}Get FFU GetFFUMaxSpeed2 {groupAddress}");
return true;
});
OP.Subscribe($"{Name}GetFFUMaxSpeed3", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Get FFU GetFFUMaxSpeed3.");
return false;
}
QueryMaxSpeed3();
EV.PostInfoLog(Module, $"{Name}Get FFU GetFFUMaxSpeed3 {groupAddress}");
return true;
});
OP.Subscribe($"{Name}SetFFUReset", (cmd, param) =>
{
if (int.TryParse((string)param[0], out var groupAddress))
{
EV.PostWarningLog(Module, "Set FFU Reset.");
return false;
}
ResetDevice();
EV.PostInfoLog(Module, $"{Name}Set FFU Reset {groupAddress}");
return true;
});
OP.Subscribe($"{Name}.SetFFUSpeedBySC", (cmd, param) =>
{
int speed = SC.GetValue<int>("System.FFUFanSpeedSetPoint");
SetSpeed(speed);
EV.PostInfoLog(Module, $"Set {Name} speed");
return true;
});
ConnectionManager.Instance.Subscribe($"{Name}", this);
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($"{_scRoot}.{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)
{
QuerySpeed();
}
if (_lstHandler.Count > 0)
{
handler = _lstHandler.First.Value;
_lstHandler.RemoveFirst();
}
}
if (handler != null)
{
_connection.Execute(handler);
}
}
return true;
}
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 Terminate()
{
try
{
if (_connection != null)
{
_connection.Disconnect();
_connection = null;
}
}
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>($"System.{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)
{
lock (_locker)
{
_lstHandler.Clear();
if (_connection.IsBusy) _connection.ForceClear();
List<byte> cmddata = new List<byte>() { 0x35, 0x40, 0x0, (byte)(speed * 250.0 / _nMaxSpeed) };
byte checksum = ModRTU_CRC(cmddata.ToArray());
cmddata.Add(checksum);
_connection.SendMessage(cmddata.ToArray());
}
}
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}");
}
}
private static byte ModRTU_CRC(byte[] buffer)
{
//ushort crc = 0xFFFF;
// var buf = System.Text.Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, buffer));
var buf = buffer;
var len = buffer.Length;
byte temp = buffer[0];
for (int i = 1; i < buffer.Length; i++)
{
temp = (byte)(temp ^ buffer[i]);
}
return (byte)~temp;
}
}
}
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Linq;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.Aire
{
public class FfuAAFMessage : BinaryMessage
{
public byte Preamble { get; set; }
public byte Command { get; set; }
public byte GroupAddress { get; set; }
public byte Data1 { get; set; }
public byte Data2 { get; set; }
}
public class FfuAAFConnection : SerialPortConnectionBase
{
private List<byte> _lstCacheBuffer = new List<byte>();
public FfuAAFConnection(string portName) : base(portName,9600,8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One,"\r",false)
{
}
public override bool SendMessage(byte[] message)
{
_lstCacheBuffer.Clear();
return base.SendMessage(message);
}
protected override MessageBase ParseResponse(byte[] rawMessage)
{
_lstCacheBuffer.AddRange(rawMessage);
byte[] temps = _lstCacheBuffer.ToArray();
FfuAAFMessage msg = new FfuAAFMessage();
msg.IsResponse = false;
msg.IsAck = false;
msg.IsComplete = false;
msg.RawMessage = _lstCacheBuffer.ToArray();
if (temps.Length < 4) return msg;
if (temps.LastOrDefault() != ModRTU_CRC(temps.Take(temps.Length - 1).ToArray()))
return msg;
msg.Preamble = temps[0];
msg.Command = temps[1];
msg.GroupAddress = temps[2];
if (temps.Length > 4) msg.Data1 = temps[3];
if (temps.Length > 5) msg.Data2 = temps[4];
msg.IsResponse = true;
msg.IsAck = true;
msg.IsComplete = true;
return msg;
}
private static byte ModRTU_CRC(byte[] buffer)
{
//ushort crc = 0xFFFF;
// var buf = System.Text.Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, buffer));
var buf = buffer;
var len = buffer.Length;
byte temp = buffer[0];
for (int i = 1; i < buffer.Length; i++)
{
temp = (byte)(temp ^ buffer[i]);
}
return (byte)~temp;
}
}
}
@@ -0,0 +1,370 @@
using System.Collections.Generic;
using MECF.Framework.Common.Communications;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.Aire
{
public abstract class FfuAAFHandler : HandlerBase
{
public FfuAAF Device { get; }
public byte DeviceAddress;
public byte GroupAddress;
public bool IsNeedFeedback;
protected FfuAAFHandler(FfuAAF device, byte prefix, byte command, byte groupAddress, byte[] datas)
: base(BuildMessage(prefix, command, groupAddress, datas))
{
Device = device;
IsNeedFeedback = true;
}
protected FfuAAFHandler(FfuAAF device, byte prefix, byte command, byte groupAddress, byte[] datas, bool needfeedback)
: base(BuildMessage(prefix, command, groupAddress, datas))
{
Device = device;
IsNeedFeedback = needfeedback;
}
private static byte[] BuildMessage(byte prefix, byte command, byte groupAddress, byte[] datas)
{
List<byte> result = new List<byte>() { prefix, command, groupAddress };
if (datas != null)
{
foreach (byte data in datas)
result.Add(data);
}
result.Add(ModRTU_CRC(result.ToArray()));
return result.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
ResponseMessage = msg;
handled = true;
return true;
}
private static byte ModRTU_CRC(byte[] buffer)
{
//ushort crc = 0xFFFF;
// var buf = System.Text.Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, buffer));
var buf = buffer;
var len = buffer.Length;
byte temp = buffer[0];
for (int i = 1; i < buffer.Length; i++)
{
temp = (byte)(temp ^ buffer[i]);
}
return (byte)~temp;
}
}
/// <summary>
/// 设置组地址
/// </summary>
public class FfuAAFSetGroupAddressHandler : FfuAAFHandler
{
public FfuAAFSetGroupAddressHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] datas)
: base(device, 0x55, (byte)(0xC0 + fanaddress), groupAddress, datas)
{
Name = "Set Group Address";
DeviceAddress = fanaddress;
GroupAddress = groupAddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
ResponseMessage = msg;
handled = true;
return true;
}
}
/// <summary>
/// 查询组地址
/// </summary>
public class FfuAAFGetGroupAddressHandler : FfuAAFHandler
{
public FfuAAFGetGroupAddressHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] values)
: base(device, 0x35, (byte)(0xE0 + fanaddress), groupAddress, values)
{
Name = "Query Group Address";
DeviceAddress = fanaddress;
GroupAddress = groupAddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
result.GroupAddress = result.Data1;
ResponseMessage = msg;
handled = true;
return true;
}
}
/// <summary>
/// 设置机地址
/// </summary>
public class FfuAAFSetAddressHandler : FfuAAFHandler
{
public FfuAAFSetAddressHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] datas)
: base(device, 0x55, (byte)(0xC0 + fanaddress), groupAddress, datas)
{
Name = "Set Device Address";
DeviceAddress = fanaddress;
GroupAddress = groupAddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
ResponseMessage = msg;
handled = true;
return true;
}
}
/// <summary>
/// 查询机地址
/// </summary>
public class FfuAAFGetAddressHandler : FfuAAFHandler
{
public FfuAAFGetAddressHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] values)
: base(device, 0x35, (byte)(0xE0 + fanaddress), groupAddress, values)
{
Name = "Query Device Address";
DeviceAddress = fanaddress;
GroupAddress = groupAddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
Device.DeviceAddress = result.Data1;
ResponseMessage = msg;
handled = true;
return true;
}
}
/// <summary>
/// 查询最高转速 1
/// </summary>
public class FfuAAFQueryMaxSpeed1Handler : FfuAAFHandler
{
public FfuAAFQueryMaxSpeed1Handler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] values)
: base(device, 0x35, (byte)(0xE0 + fanaddress), groupAddress, values)
{
Name = "Query Max Speed1";
DeviceAddress = fanaddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
Device.MaxSpeed1 = result.Data1;
ResponseMessage = msg;
handled = true;
return true;
}
}
/// <summary>
/// 查询最高转速 2
/// </summary>
public class FfuAAFQueryMaxSpeed2Handler : FfuAAFHandler
{
public FfuAAFQueryMaxSpeed2Handler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] values)
: base(device, 0x35, (byte)(0xE0 + fanaddress), groupAddress, values)
{
Name = "Query Max Speed2";
DeviceAddress = fanaddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
Device.MaxSpeed2 = result.Data1;
ResponseMessage = msg;
handled = true;
return true;
}
}
/// <summary>
/// 查询最高转速 3
/// </summary>
public class FfuAAFQueryMaxSpeed3Handler : FfuAAFHandler
{
public FfuAAFQueryMaxSpeed3Handler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] values)
: base(device, 0x35, (byte)(0xE0 + fanaddress), groupAddress, values)
{
Name = "Query Max Speed3";
DeviceAddress = fanaddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
Device.MaxSpeed3 = result.Data1;
ResponseMessage = msg;
handled = true;
return true;
}
}
public class FfuAAFQuerySpeedFactorHandler : FfuAAFHandler
{
public FfuAAFQuerySpeedFactorHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] values)
: base(device, 0x35, (byte)(0xE0 + fanaddress), groupAddress, values)
{
Name = "Query Speed Factor";
DeviceAddress = fanaddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
Device.Speedfactor = result.Data1;
ResponseMessage = msg;
handled = true;
return true;
}
}
public class FfuAAFSetSpeedFactorHandler : FfuAAFHandler
{
public FfuAAFSetSpeedFactorHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] datas)
: base(device, 0x55, (byte)(0xC0 + fanaddress), groupAddress, datas)
{
Name = "Set Speed";
DeviceAddress = fanaddress;
GroupAddress = groupAddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
ResponseMessage = msg;
handled = true;
return true;
}
}
public class FfuAAFQuerySpeedHandler : FfuAAFHandler
{
public FfuAAFQuerySpeedHandler(FfuAAF device, byte fanaddress, byte groupAddress)
: base(device, 0x15, (byte)(0x20 + fanaddress), groupAddress, null)
{
Name = "Query Speed";
DeviceAddress = fanaddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
Device.Speed = result.Data1 * 1440 / 250;//Device.NMaxSpeed
ResponseMessage = msg;
handled = true;
return true;
}
}
public class FfuAAFSetSpeedHandler : FfuAAFHandler
{
public FfuAAFSetSpeedHandler(FfuAAF device, byte fanaddress, byte groupAddress, byte[] datas)
: base(device, 0x35, (byte)(0x40 + fanaddress), groupAddress, datas)
{
Name = "Set Speed";
DeviceAddress = fanaddress;
GroupAddress = groupAddress;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
handled = false;
if (!result.IsResponse) return true;
ResponseMessage = msg;
handled = true;
return true;
}
}
public class FfuAAFResetDeviceHandler : FfuAAFHandler
{
public FfuAAFResetDeviceHandler(FfuAAF device, byte fanaddress, byte groupAddress)
: base(device, 0x15, (byte)(0x60 + fanaddress), groupAddress, null)
{
Name = "Reset Device";
}
}
public class FfuAAFQueryStatusHandler : FfuAAFHandler
{
public FfuAAFQueryStatusHandler(FfuAAF device, byte fanaddress, byte groupAddress)
: base(device, 0x35, fanaddress, groupAddress, new byte[] { 0x00 })
{
Name = "Query Status";
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as FfuAAFMessage;
//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;
}
}
}