54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using static InnovEnergy.Lib.Protocols.Modbus.Protocol.FunctionCode;
|
|
|
|
namespace InnovEnergy.Lib.Protocols.Modbus.Protocol;
|
|
|
|
[Flags]
|
|
public enum FunctionCode : byte
|
|
{
|
|
ReadCoils = 1,
|
|
ReadDiscreteInputs = 2,
|
|
ReadHoldingRegisters = 3,
|
|
ReadInputRegisters = 4,
|
|
|
|
WriteSingleCoil = 5,
|
|
WriteSingleRegister = 6,
|
|
WriteMultipleCoils = 15,
|
|
WriteMultipleRegisters = 16,
|
|
|
|
ReadWriteMultipleRegisters = 23,
|
|
|
|
Error = 128
|
|
}
|
|
|
|
|
|
public static class FunctionCodeExtensions
|
|
{
|
|
|
|
public static Boolean IsWriteOnly(this FunctionCode fc)
|
|
{
|
|
return fc is WriteSingleCoil
|
|
or WriteSingleRegister
|
|
or WriteMultipleCoils
|
|
or WriteMultipleRegisters;
|
|
}
|
|
|
|
public static Boolean IsMultiWrite(this FunctionCode fc)
|
|
{
|
|
return fc is WriteMultipleCoils
|
|
or WriteMultipleRegisters
|
|
or ReadWriteMultipleRegisters;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
} |