Innovenergy_trunk/csharp/Lib/Protocols/Modbus/Protocol/FunctionCode.cs

54 lines
1.5 KiB
C#
Raw Normal View History

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
{
ReadCoils = 1,
ReadDiscreteInputs = 2,
ReadHoldingRegisters = 3,
ReadInputRegisters = 4,
2023-02-16 12:57:06 +00:00
WriteSingleCoil = 5,
WriteSingleRegister = 6,
WriteMultipleCoils = 15,
WriteMultipleRegisters = 16,
2023-02-16 12:57:06 +00:00
ReadWriteMultipleRegisters = 23,
2023-02-16 12:57:06 +00:00
Error = 128
}
2023-02-16 12:57:06 +00:00
public static class FunctionCodeExtensions
{
public static Boolean IsWriteOnly(this FunctionCode fc)
{
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)
{
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;
}
}