Documentation

MbusDataTableInterfacereadCoilsTable Method

Override this method to implement a Data Provider function to read Coils.

Namespace:  FieldTalk.Modbus.Slave
Assembly:  FieldTalk.Modbus.Slave (in FieldTalk.Modbus.Slave.dll) Version: 2.11.0-eval+eb1ecbe71c969eff5d7c05d58da16dade0474678
Syntax
protected virtual bool readCoilsTable(
	int startRef,
	bool[] bitArr
)

Parameters

startRef
Type: SystemInt32
Start register (Range: 1 - 65536)
bitArr
Type: SystemBoolean
Buffer which has to be filled with the reply data (Length: 0 - 2000). Each char represents one coil!

Return Value

Type: Boolean
true indicates a successful access and that valid reply data is contained in regArr. The Server Engine will reply the data passed in regArr to the master.

false indicates that access has been denied or is out of range. The Server Engine will reply to the master with an exception reply message

Remarks
When a slave receives a poll request for the 0:00000 data table it calls this method to retrieve the data.

Required: No

Default Implementation: Returns false which indicates to Server Engine that this address range is unsupported.

Examples
A simple implementation which holds the boolean application data in an array of bool called bitData could be:
protected override int readCoilsTable(Int32 startRef, bool[] bitArr)
{
    // Adjust Modbus reference counting from 1-based to 0-based
    startRef--;
    // Validate range
    if (startRef + bitArr.Length > localCoils.Length)
        return false;
    // Copy registers from local data array to Modbus
    for (int i = 0; i < bitArr.Length; i++)
        bitArr[i] = localCoils[startRef + i];
    return true;
}
See Also