Skip to main content

ModbusGateway Class

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

Modbus TCP/RTU Gateway

public class ModbusGateway : ModbusDevice

Constructors

ModbusGateway(byte deviceAddress)

public ModbusGateway(byte deviceAddress) : base(deviceAddress)

Creates a new Modbus Gateway without any master interfaces.

ParameterTypeDescription
deviceAddressbyteAddress of this device

ModbusGateway(byte deviceAddress, IModbusInterface masterInterface, int timeout)

public ModbusGateway(byte deviceAddress, IModbusInterface masterInterface, int timeout) : this(deviceAddress)

Creates a new Modbus Gateway with a single master interface and an 1:1 device id mapping

ParameterTypeDescription
deviceAddressbyteAddress of this device
masterInterfaceIModbusInterfaceMaster interface to add
timeoutintTimeout for master interface

Methods

AddMaster(IModbusInterface masterInterface, int timeout)

public void AddMaster(IModbusInterface masterInterface, int timeout)

Adds an additional master interface with a 1:1 device id mapping

ParameterTypeDescription
masterInterfaceIModbusInterfaceMaster interface to add
timeoutintTimeout for master interface

AddMaster(IModbusInterface masterInterface, int timeout, Hashtable addressMap)

public void AddMaster(IModbusInterface masterInterface, int timeout, Hashtable addressMap)

Adds an additional master interface with an custom device id mapping

ParameterTypeDescription
masterInterfaceIModbusInterfacemaster interface to add
timeoutintTimeout for master interface
addressMapHashtableA hashtable where the key is the incoming device id that is mapped to it's value as device id on the master interface. Both, key and value of the hashtable must be of type byte.

OnGetDeviceIdentification(ModbusObjectId objectId)

protected override string OnGetDeviceIdentification(ModbusObjectId objectId)

Is called when the value of the object id is needed for a ReadDeviceIdentification request.

ParameterTypeDescription
objectIdModbusObjectIdObject id.

Returns string — Returns the value of the requested object id.

GetConformityLevel()

protected override ModbusConformityLevel GetConformityLevel()

Is called when the maximum conformity level is needed for a ReadDeviceIdentification request.

Returns ModbusConformityLevel — Returns the maximum conformity level which is provided by this device.

OnHandleTelegram(IModbusInterface intf, byte deviceAddress, bool isBroadcast, short telegramLength, object telegramContext, ModbusFunctionCode fc, short dataPos, short dataLength)

protected override void OnHandleTelegram(IModbusInterface intf, byte deviceAddress, bool isBroadcast, short telegramLength, object telegramContext, ModbusFunctionCode fc, short dataPos, short dataLength)

Handles a received message.

ParameterTypeDescription
intfIModbusInterfaceInterface by which te message was received.
deviceAddressbyteAddress of the target device
isBroadcastbooltrue if the message is a broadcast. For broadcast messages no reponse is sent.
telegramLengthshortLength of the message in bytes.
telegramContextobjectInterface specific message context.
fcModbusFunctionCodeFunction code.
dataPosshortIndex of function code specific data.
dataLengthshortLength of the function code specific data in bytes.