52 lines
2.1 KiB
C#
52 lines
2.1 KiB
C#
namespace InnovEnergy.Lib.Protocols.Modbus.Protocol;
|
|
|
|
[Flags]
|
|
public enum FunctionCode : byte
|
|
{
|
|
ReadCoil = 1, ReadCoilError = ReadCoil | Error ,
|
|
ReadDiscreteInputs = 2, ReadDiscreteInputsError = ReadDiscreteInputs | Error ,
|
|
ReadHoldingRegisters = 3, ReadHoldingRegistersError = ReadHoldingRegisters | Error ,
|
|
ReadInputRegisters = 4, ReadInputRegistersError = ReadInputRegisters | Error ,
|
|
|
|
WriteSingleCoil = 5, WriteSingleCoilError = WriteSingleCoil | Error ,
|
|
WriteSingleRegister = 6, WriteSingleRegisterError = WriteSingleRegister | Error ,
|
|
WriteMultipleCoils = 15, WriteMultipleCoilsError = WriteMultipleCoils | Error ,
|
|
WriteMultipleRegisters = 16, WriteMultipleRegistersError = WriteMultipleRegisters | Error ,
|
|
|
|
ReadWriteMultipleRegisters = 23, ReadWriteMultipleRegistersError = ReadWriteMultipleRegisters | Error ,
|
|
|
|
Error = 128
|
|
}
|
|
|
|
public static class FunctionCodeExtensions
|
|
{
|
|
|
|
public static Boolean IsWriteOnly(this FunctionCode fc)
|
|
{
|
|
return fc == FunctionCode.WriteSingleCoil ||
|
|
fc == FunctionCode.WriteSingleRegister ||
|
|
fc == FunctionCode.WriteMultipleCoils ||
|
|
fc == FunctionCode.WriteMultipleRegisters;
|
|
}
|
|
|
|
public static Boolean IsMultiWrite(this FunctionCode fc)
|
|
{
|
|
return fc == FunctionCode.WriteMultipleCoils ||
|
|
fc == FunctionCode.WriteMultipleRegisters ||
|
|
fc == FunctionCode.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;
|
|
}
|
|
|
|
|
|
} |