Qaseem
Hi,

what is the best way to log the slave's values every time it is delivered to the OpenPLC without duplication?

I wrote a script in the custom layer at HWLCB to log the slave's value to a text file.  I notice that some values are logged more than once in the log file (using polling time 2000ms). So I tried many settings in the PLC polling time  100ms, 70 ms, 72ms, 60 ms, and even 10ms and found that the OpenPLC didn't log all values (when polling time set to 10ms, 60ms and 70) or logged more values (71ms, 72ms and 100ms). 
I read in the other post that we need to balance between the task's cyclic time and the polling time but I couldn't reach the point where the openPLC log the same sequence of values as the sensor's log. How can I do that?
Should I place this script in the main.cpp or master_modbus file instead?

Thanks,
Quote 0 0
thiagoralves
If you want to log right when you receive the data, your code must be in the modbus_master.cpp file. Just beware that writing to disk in the middle to this operation can affect the real time performance significantly. If possible, I recommend writing to a RAM disk to avoid delays.
Quote 0 0
Qaseem
Thanks for your recommendation. I need to test writing to a RAM and found two alternatives zram and log2ram. Do you recommend any library that works with the OpenPLC?
Quote 0 0
thiagoralves
You don’t have to use any library. Read this:  https://www.jamescoyle.net/how-to/943-create-a-ram-disk-in-linux

Once you have your ramdisk mounted, you just write to it (i.e. /mnt/ramdisk) instead of writing to disk.
Quote 0 0
Qaseem
Great! Many thanks!
Quote 0 0