scoob - 2024-04-26

Hello,

I have been trying to use the ModbusFB functions so I can put some code into libraries, but it seems to be very slow for me.

I have a Modbus device with 100ms registers.

I previously setup 10 channels in the 'traditional' Modbus Slave with channels and mappings - and set a cyclic trigger at 100ms - this worked fine.

I then tried the ModbusFB example, and setup reading the same 10 blocks of modbus addresses, copying the example and putting all of the requests into an array and triggering the requests sequentially.
I timed how long the requests are taking to get round to each one, and it is around 1s 450ms.

How do I speed this up to match the cyclic time?

IF NOT(init) THEN
    init := TRUE;
    // Set the required IP address:
    ipAddress[0]                        := 192;
    ipAddress[1]                        := 168;
    ipAddress[2]                        := 1;
    ipAddress[3]                        := 10;
    // Pass the required IP address to the clinet FB:
    client_NetworkSwitch.aIPaddr        := ipAddress;
    client_NetworkSwitch.udiLogOptions  := (ModbusFB.LoggingOptions.ClientConnectDisconnect OR ModbusFB.LoggingOptions.ClientReceivedValidReplies);
    // Try to connect the client
    client_NetworkSwitch(xConnect:=TRUE);

    // Configure all the channels to read connecting them to the client:
    portStatus_Request(rClient := client_NetworkSwitch, uiStartItem := 4096, uiQuantity := 32, pData := ADR(portStatus), udiReplyTimeout := udiReplyTimeout);
    portSpeed_Request(rClient := client_NetworkSwitch, uiStartItem := 4352, uiQuantity := 32, pData := ADR(portSpeed));
    flowControl_Request(rClient := client_NetworkSwitch, uiStartItem := 4608, uiQuantity := 32, pData := ADR(flowControl));
    linkUpCounter_Request(rClient := client_NetworkSwitch, uiStartItem := 5888, uiQuantity := 32, pData := ADR(linkUpCounter));
    txPacketCounter1_Request(rClient := client_NetworkSwitch, uiStartItem := 8192, uiQuantity := 100, pData := ADR(txPacketCounter1));
    txPacketCounter2_Request(rClient := client_NetworkSwitch, uiStartItem := 8292, uiQuantity := 28, pData := ADR(txPacketCounter2));
    rxPacketCounter1_Request(rClient := client_NetworkSwitch, uiStartItem := 8448, uiQuantity := 100, pData := ADR(rxPacketCounter1));
    rxPacketCounter2_Request(rClient := client_NetworkSwitch, uiStartItem := 8548, uiQuantity := 28, pData := ADR(rxPacketCounter2));
    txErrors_Request(rClient := client_NetworkSwitch, uiStartItem := 8704, uiQuantity := 64, pData := ADR(txErrors));       
    rxErrors_Request(rClient := client_NetworkSwitch, uiStartItem := 8960, uiQuantity := 64, pData := ADR(rxErrors));       

    // Trigger all client requests initially 
    FOR clientRequestsCnt := 0 TO (SIZEOF(clientRequests)/SIZEOF(clientRequests[0]))-1 DO
        pClientRequest := clientRequests[clientRequestsCnt];
        pClientRequest^.xExecute := TRUE;
    END_FOR
    // Prepare sequential trigger / control of client requests. 
    clientRequestsCnt := 0;
    pClientRequest := clientRequests[clientRequestsCnt];
END_IF

// Call the client to do request processing:
client_NetworkSwitch();

// Now we trigger client request sequentially ...
IF NOT pClientRequest^.xExecute AND NOT pClientRequest^.xDone  AND run AND client_NetworkSwitch.xConnected THEN
    pClientRequest^.xExecute := TRUE;
END_IF
// .. and check result/error
IF pClientRequest^.xExecute AND run AND client_NetworkSwitch.xConnected THEN
    IF pClientRequest^.xDone THEN
        // Prepare next trigger of client request (a rising edge of xExecute) 
        pClientRequest^.xExecute := FALSE;
        IF clientRequestsCnt < SIZEOF(clientRequests)/SIZEOF(clientRequests[0])-1 THEN
            // next client request
            clientRequestsCnt := clientRequestsCnt + 1;
        ELSE
            clientRequestsIterationCounter := clientRequestsIterationCounter + 1;
            clientRequestsCnt := 0;
        END_IF
        pClientRequest := clientRequests[clientRequestsCnt];
    END_IF
END_IF

I did try a semi-coded way using the IoDrvModbusTCP library, and setting the slave com settings, then 10 commands and 10 requests, then using a TP on xDone as a pause, before triggering another request - this is time the delay is around 120ms - so the device is fine with the speed, just something I am doing wrong in the ModbusFB method I am sure.

 

Related

Talk.ru: 1
Talk.ru: 2
Talk.ru: 3