I have a modbus read node which communicates a PLC at 20 ms polling rate, and returns the status of a memory address (true or false). I have set up a flow which calculates the status change between false and true (through a RBE filter node) and a message counter counts the number of messages and resets every minute through internal clock within the message counter, the output of the message counter is fed into a function which divides the result by 2 (since one false+ one true = 1 count) and rounds off to next integer if it is an odd number.
so far so good.
Here is my issue. If the number of messages (true+false put together) is even, i don't have any problem, but if it happens to be odd (the object being counted passes under the sensor, triggering it, and before the sensor is deactivated, the minute counter reaches 00 seconds, resetting it), then it rounds off to next integer in the process increasing one count extra compared to physical count.
false+true+false+true = 4/2 = 2)
false+true+false+true+false = 5/2 = 2.5 = 3)
the count varies with physical count and it is highly random depending upon at the stroke of 00 in internal clock , the total number of message happens to be odd or even.
in the below picture we can see,
at 5:03 it is 12, so will result in 6, (equal to physical count)
at 5:04 it is 10, so will result in 5, (equal to physical count)
at 5:05 it is 10, so will result in 5, (equal to physical count)
at 5:06 however, it is 11, so will result in 6, (one higher than physical count)
this over an hour or a day, accumulates and gives me wrong count.
how do i tackle this ?
I would like to move the last message before the stroke of 00 to next minute if it happens to be odd, else do nothing.