-> Hier kostenlos registrieren
Hallo,
Entschuldigung, Ich kann nicht spreche deutsch sehr gut.
I am going to poll multiple Modbus slaves from my PFC200 750-8202 Controller using my function block (MbSlave). unfortunately when the program runs, The Controller polls the first slave and leaves the others. could you please take a look at my codes?

Vielen Dank für eure Unterstützung!
Entschuldigung, Ich kann nicht spreche deutsch sehr gut.
I am going to poll multiple Modbus slaves from my PFC200 750-8202 Controller using my function block (MbSlave). unfortunately when the program runs, The Controller polls the first slave and leaves the others. could you please take a look at my codes?
FUNCTION_BLOCK MbSlave
VAR_INPUT
//--Define Com Port and Slave ID as Input Variables--//
ComPort : WagoTypesCom.I_WagoSysComBase ;
Slave_ID : BYTE ;
END_VAR
VAR_OUTPUT
//--Data polled from Measuring Center as Output variable--//
SlvData: ARRAY[0..50] OF DWORD;
END_VAR
VAR
//--- Declare Modbus Master Serial ------
MbSlv : FbMbMasterSerial := ( xConnect := TRUE,udiBaudrate := 19200,usiDataBits := 8,eParity := WagoTypesCom.eTTYParity.None,eStopBits := WagoTypesCom.eTTYStopBits.One,eHandshake := WagoTypesCom.eTTYHandshake.None,ePhysical:= WagoTypesCom.eTTYPhysicalLayer.RS485_HalfDuplex,eFrameType := eMbFrameType.RTU,tTimeOut := T#1S);
//-------------------------------------------------------------------------------
//Declare Modbus Queries
Poll_A: ARRAY[0..2] OF typMbQuery() :=
// Slaveaddress //read Holding registers // Startaddress // Quantity of wanted registers
[( bFunctionCode := 3, uiReadAddress := 0 , uiReadQuantity := 20 ),//Q1 INT32
( bFunctionCode := 3, uiReadAddress := 100 , uiReadQuantity := 30 ),//Q2 INT16
( bFunctionCode := 3, uiReadAddress := 200 , uiReadQuantity := 10 )//Q3 INT16
];
iQryCounter : BYTE :=0;
iRegCounter : BYTE :=0;
FB_F_Trig:F_Trig;
xTxTrigger : BOOL :=TRUE; (* This variable will be automaticly reset by the masterif the job is done.*)
delay:TON;
ResponseList:ARRAY [0..2] OF typMbResponse; //Store Query Response in array
END_VAR
//--- delay between two requests ----------------------
FB_F_Trig (clk:=xTxTrigger);
IF FB_F_Trig.Q THEN
xTxTrigger :=TRUE;
iQryCounter := (iQryCounter+1) MOD 3;//Next Query
END_IF
//---Fill the Slave ID
Poll_A[iQryCounter].bUnitId := Slave_ID;
//--- call the master for first query --------------
MbSlv(
I_Port := ComPort, // Link Serial Port
utQuery := Poll_A[iQryCounter],
xTrigger := xTxTrigger,
utResponse := ResponseList[iQryCounter] // Read responses
);
//--Reset the Counters------------------------------
iRegCounter := 0 ;
//-----------------------------------------
// Store response in SlvData
//-----------------------------------------
WHILE iRegCounter < Poll_A[iQryCounter].uiReadQuantity DO
CASE iQryCounter OF
0:
//Convert 2X16bit to 32bit
SlvData[iRegCounter/2] := ResponseList[iQryCounter].awData[iRegCounter+1] OR SHL(ResponseList[iQryCounter].awData[iRegCounter],16) ;
iRegCounter := iRegCounter + 2 ;
1:
//Convert 1X16bit to 32bit
SlvData[iRegCounter+10] := WORD_TO_DWORD(ResponseList[iQryCounter].awData[iRegCounter]) ;
iRegCounter := iRegCounter + 1 ;
2:
//Convert 1X16bit to 32bit
SlvData[(iRegCounter/4)+40] := WORD_TO_DWORD(ResponseList[iQryCounter].awData[iRegCounter]) ;
iRegCounter := iRegCounter + 4 ;
END_CASE
END_WHILE

Vielen Dank für eure Unterstützung!