How to read several slaves - Modbus RTU

Hello,

How can I read from multiple slaves? I know how to do it for one slave, but how do you handle multiple slaves?

The setup for slave ID 1 is working fine, but I would also like to retrieve the values for IDs 5 and 10.


mySerialMaster  : FbMbMasterSerial := ( xConnect    := TRUE,
udiBaudrate := 9600,
usiDataBits := 8,
eParity     := WagoTypesCom.eTTYParity.Odd,
eStopBits   := WagoTypesCom.eTTYStopBits.Two,
eHandshake  := WagoTypesCom.eTTYHandshake.None,
ePhysical   := WagoTypesCom.eTTYPhysicalLayer.RS485_HalfDuplex,
eFrameType  := eMbFrameType.RTU,
tTimeOut    := T#3000MS
);

utQuery : typMbQuery := (
bUnitId         := 1,        // Address
bFunctionCode   := 16#03,    // FC3 = read input registers
uiReadAddress   := 50770,
uiReadQuantity  := 2,
uiWriteAddress  := 0,
uiWriteQuantity := 0,
awWriteData     := [124(0)]
);

xTxTrigger      : BOOL;             (* Set this variable once to start a job.
                                       This variable will be automatically reset by the master
                                       when the job is completed.
                                    *)

utResponse      : typMbResponse;    (* Once the job is done, you can find the result in this structure.
                                    *)

tonDelay        : TON := (PT := T#50MS); // This is the silence time between two requests
//--- delay between two requests ----------------------
tonDelay( IN := (NOT tonDelay.Q) AND (NOT xTxTrigger));
xTxTrigger S= tonDelay.Q; // trigger the next request

//--- call the master cyclically --------------
mySerialMaster( I_Port      := _750_652_x,        // my serial port
utQuery     := utQuery,
xTrigger    := xTxTrigger,
utResponse  := utResponse
);

Thank you for your help.

Another question: Is it possible to retrieve multiple registers from a single slave?

1.1 Collect Write Data for Request 1
1.2 Start Request 1
1.3 Wait until Request 1 is done
1.4 Move Read Data Request 1 to target variables
2.1 Collect Write Data for Request 2
2.2 Start Request 2
2.3 Wait until Request 2 is done
2.4 Move Read Data Request 2 to target variables
3.1 Collect Write Data for Request 3
3.2 Start Request 3
3.3 Wait until Request 3 is done
3.4 Move Read Data Request 3 to target variables
.
.
.
n.1 Collect Write Data for Request n
n.2 Start Request n
n.3 Wait until Request n is done
n.4 Move Read Data Request n to target variables
go back to 1

Thanks Thruser, do you happen to have a code example, please?

See here. A slightly different approach for .1 and .4 Steps

It is for Modbus TCP but you can easily adapt it to Modubs RTU function blocks.

Noted, thanks :slight_smile:

Have a great day