Why do I have a 200ms request period in Wireshark when I configure it for 100ms in the Modbus task, using ST language in TwinCAT3?

I create a program to obtain data through Modbus-TCP server (192.168.2.16) on TwinCAT3 to obtain data from other PC (slave: 192.168.2.20):

enter image description here

Also I create and configure the modbus server task with 100ms.
enter image description here

However, I noted in wireshark that the period of request is around 200ms and not 100ms. Why the period is 200ms?

enter image description here

I was hoping that the period would be the same (100ms)

  • Please provide enough code so others can better understand or reproduce the problem.

    – 
    Bot

  • For future posts, try providing the code as text (can be formatted to display as code section), instead of images of the code.

    – 




Answer

Your function-block is taking more than a single cycle to run.


Explanation

Depending on the application a function-block can take multiple cycles to complete, which is why they are often configured with:

  • bExecute: The function-block is activated on a rising edge at this input
  • bBusy: Indicates TRUE while the function-block is running

In your case I believe that you will be seeing a single cycle of bBusy being high after you have set bExecute to TRUE. This is often the case when a function-block needs to communicate with some external object (like a network device).


Solution

The recommended solution to your timing problem is to reduce your cycle time (5/10ms should do), and then set ‘bExecute’ on your desired cycle time.
This allows the function-block to run for several cycles and return its data before starting a new request.

Leave a Comment