I am using qextserialport on a Raspberry Pi to communicate with an PanStamp (Arduino compatible device).
This PanStamp connected to the Pi executes two functions:
- Send some sensor's readings each second (about 12 bytes);
- Send all data it receives through a wireless link (about 60 bytes about 6 times per second).
My architecture is:
- Hub: PanStamp + Raspberry Pi;
- Satellite: PanStamp + a few sensors.
There are two situations:
- Satellite on sending data wirelessy to the Hub. I this situation the Pi receives lots of data through it's serial port every second;
- Satellite off, the Pi receives about 12 bytes each second through serial port.
When the satellite is off the readyRead()
signal is not generated every time a byte arrives and it drives my program to a "out of sync" condition where to each data packet read one or more stays in the buffer (that keeps growing).
However when I turn the satellite on and the Pi starts to receive lots of data this "out of sync" condition disappear, there are a burst of data (the buffer grows faster and after is empted) and the my program starts to work "in real time".
Here is a example of my program's output: www.tiago.eti.br/storage/iSEDE.log
As you can see in the log the bytes available keeps growing and the data send every second (line starting with HUB:
is not being processed every second. there is a time stamp at the beginning). After a while there is a burst (satellite has been turned on) and there is lots of data being processed every second, the satellite's data start to be processed (lines starting with an 8
), the buffer is emptied and my program starts processing data in "real time".
So what can I do to avoid the buffer from growing too much and do not lose data?
I tried to call the function that is connected to readyRead()
when the buffer gets bigger than 100 bytes but it created a mess and I started to lose some packets.