Add ModbusDevice as preparation for server implementations.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace AMWD.Protocols.Modbus.Common
|
||||
{
|
||||
@@ -10,5 +11,19 @@ namespace AMWD.Protocols.Modbus.Common
|
||||
if (BitConverter.IsLittleEndian)
|
||||
Array.Reverse(bytes);
|
||||
}
|
||||
|
||||
public static ushort NetworkUInt16(this byte[] bytes, int offset = 0)
|
||||
{
|
||||
byte[] b = bytes.Skip(offset).Take(2).ToArray();
|
||||
b.SwapNetworkOrder();
|
||||
return BitConverter.ToUInt16(b, 0);
|
||||
}
|
||||
|
||||
public static byte[] ToNetworkBytes(this ushort value)
|
||||
{
|
||||
byte[] b = BitConverter.GetBytes(value);
|
||||
b.SwapNetworkOrder();
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user