Hello, we are currently working on a simple digital twin prototype. The system consists of hardware, digital twin framework, and web app. The idea is to create a virtual replica of a physical system. The Hardware system consists of Raspberry pi and a few sensors. We are using openplc in order to control/monitor the system. All the systems are in place. Now, we would like to log the data obtained from the physical system and use that to reconstruct the virtual system on open foam (visualization). We are trying to collect the data at 200Hz over Modbus. We are reading around 20 variables (including floats/boolean/integers) data over Modbus/TCP.

The following approaches are what we have tried so far:

1. First, we wrote a simple Modbus client code (pymodbusTCP). It worked well but took a lot of time to collect the data over Modbus/TCP. We used to get data for every 100ms on an average or sometimes 50 ms. This number was never constant. Basically, we didn't get a good data rate (hardly we achieved around10-20Hz).

2. Next, we wrote a c++ code to get the data from the open plc platform over Modbus/TCP. This time the data rate is better if there is no delay induced in code. Two strange things we are unable to understand
  1. If the delay is not given in code (continuous mode) we were able to fetch around 12-20 samples (each sample around 300 us to 1ms) for the duration of 5 ms. But after fetching the above samples modus read operation takes 50ms time for the next set of samples. This anomaly was periodic.
  2. When the delay of 5 ms is introduced in code we were able to fetch each data after every ~ 50 ms.

Questions: 1. Is it possible to obtain the data at 200Hz for logging purposes from openplc?
2. Do you guys have any idea of the 50ms gap between the read operation?
3. If we use the dnp3 protocol instead of Modbus/TCP, is it possible to achieve a good data rate?
4. Some forums say that dnp3 is a sophisticated protocol compared to Modbus. Are there any additional configurations required in order to get data from dnp3?

Any inputs on these would be a great help. Also, I have attached a c++ code, header file and example log file for your reference in zip format.

Thank you.
Quote 0 0
Modbus is definitely not the right option to do what you want. Modbus requests are processed in a separate thread and won’t ever be synchronized with the running scan cycles. This means that even if you accomplish to read it in a periodic fashion, you might be reading outdated data from the thread buffer.

If you want to log data from your system the right way is to instrument OpenPLC code. You will have to edit /webserver/core/main.cpp where the main scan cycle loop is and then read your data in there. I recommend reading it into a ram disk to avoid delay issues with SD card IO. Your logging will be synchronized and as fast as your scan cycle. There is no point to log faster than the scan cycle as data is not updated between scan cycles. 
Quote 0 0