Skip to main content

ModbusUtils Class

Namespace: GHIElectronics.TinyCLR.Devices.Modbus · Assembly: GHIElectronics.TinyCLR.Devices.Modbus

Class with modbus utility functions

public static class ModbusUtils

Methods

InsertUShort(byte[] buffer, int pos, ushort value)

public static void InsertUShort(byte[] buffer, int pos, ushort value)

Inserts a unsigned short value into a byte array in big-endian format.

ParameterTypeDescription
bufferbyte[]Byte array to write to
posintIndex to write to.
valueushortValue to write.

ExtractUShort(byte[] buffer, int pos)

public static ushort ExtractUShort(byte[] buffer, int pos)

Extracts a unsigned short value from an byte array in big-endian format.

ParameterTypeDescription
bufferbyte[]Byte array to read from
posintIndex to read from

Returns ushort — Returns the unsigned short value.

CalcCrc(byte[] buffer, int count)

public static ushort CalcCrc(byte[] buffer, int count)

Calculates the Modbus RTU CRC16 checksumm

ParameterTypeDescription
bufferbyte[]Buffer containing the telegram.
countintCount of bytes to use for CRC (not including the 2 bytes for CRC).

Returns ushort — Returns the 16 bit CRC