2023-04-20 13:03:13 +00:00
|
|
|
using static InnovEnergy.Lib.Protocols.Modbus.Protocol.FunctionCode;
|
|
|
|
|
2023-02-16 12:57:06 +00:00
|
|
|
namespace InnovEnergy.Lib.Protocols.Modbus.Protocol;
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
public enum FunctionCode : byte
|
|
|
|
{
|
2023-04-20 13:03:13 +00:00
|
|
|
ReadCoils = 1,
|
|
|
|
ReadDiscreteInputs = 2,
|
|
|
|
ReadHoldingRegisters = 3,
|
|
|
|
ReadInputRegisters = 4,
|
2023-02-16 12:57:06 +00:00
|
|
|
|
2023-04-20 13:03:13 +00:00
|
|
|
WriteSingleCoil = 5,
|
|
|
|
WriteSingleRegister = 6,
|
|
|
|
WriteMultipleCoils = 15,
|
|
|
|
WriteMultipleRegisters = 16,
|
2023-02-16 12:57:06 +00:00
|
|
|
|
2023-04-20 13:03:13 +00:00
|
|
|
ReadWriteMultipleRegisters = 23,
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
Error = 128
|
|
|
|
}
|
|
|
|
|
2023-04-20 13:03:13 +00:00
|
|
|
|
2023-02-16 12:57:06 +00:00
|
|
|
public static class FunctionCodeExtensions
|
|
|
|
{
|
|
|
|
|
|
|
|
public static Boolean IsWriteOnly(this FunctionCode fc)
|
|
|
|
{
|
2023-04-20 13:03:13 +00:00
|
|
|
return fc is WriteSingleCoil
|
|
|
|
or WriteSingleRegister
|
|
|
|
or WriteMultipleCoils
|
|
|
|
or WriteMultipleRegisters;
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Boolean IsMultiWrite(this FunctionCode fc)
|
|
|
|
{
|
2023-04-20 13:03:13 +00:00
|
|
|
return fc is WriteMultipleCoils
|
|
|
|
or WriteMultipleRegisters
|
|
|
|
or ReadWriteMultipleRegisters;
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Boolean IsError(this FunctionCode fc)
|
|
|
|
{
|
|
|
|
return fc >= FunctionCode.Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
|
|
|
|
public static FunctionCode Error(this FunctionCode fc)
|
|
|
|
{
|
|
|
|
return fc | FunctionCode.Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|