Serial port: timestamping received bytes for splitting modbus communication
-
I would like to monitor and log a RS485 communication between a modbus master and a modbus slave. In this setup I can't see what bytes on the bus are from the master and what bytes are from the slave.
In my application, there's a short pause between the end of the modbus master message, and the start of the modbus answer from the slave, and there's a longer pause between the end of the answer from the slave, and the next message from the master.
I would like to use this timing information to split the messages, so I can then decode and log them.
I'm using Qserialport. This works fine, all the characters that were transmitted over the bus are received correctly, but there's no timing information anymore.
Is there a way to figure out when a serial byte has been received? Is there a mechanism to see the amount of time between the received bytes? Maybe a list of received bytes and timestamps?
Is there a way to generate a signal after each received byte, so the slot can figure out the elapsed time? -
@Cedric-air Welcome to the forum.
Unfortunately, the general answer to your question is no. QSerialPort, and QIODevice communication is, in general, asynchronous.
If this communication is slow enough you may find that you receive a readyRead() signal for every byte or two and that this signal emission time may be adequate to detect a comparatively long break in traffic. This would probably be fragile and depend on not blocking signal processing for any significant length of time. Using the synchronous functions in a polling thread may be another way to get closer to "real" time.
I do not think that the QtSerialBus functionality has anything to support eavesdropping. Libcpap could probably help with Modbus over Ethernet or TCP but not, I think, over serial.
-
@ChrisW67
Thank you. I can use a logic analyzer to receive the serial waveform, and then either call sigrok to decode it for me, or do that myself in the Qt program.Then I know I have all the timing information I need, and i can store the raw samples of the serial connection if either the serial, or the modbus decoder reports a problem.
https://hackaday.com/2022/03/02/need-a-logic-analyzer-use-your-pico/