Android Question Bluetooth AStreams_NewData timing


Licensed User
Longtime User
I have some questions with regards the way the data is processed by Serial Class, from a timing point of view.
To be more specific, I have the following setup:
1. One application written in VB6 running on my PC. PC is paired over bluetooth with my phone. The VB6 app opens the Bluetooth corresponding COM port and send every 100 ms a packet of 25 bytes. The packet contains among other data the interval in milliseconds since the previous packet was sent (called from now on 'timeSent'), taken with GetTickCount function. Even though the packets are sent on the tick event of a 100 ms timer, I see that the 'timeSent' is around 150 ms. But that is not the problem. Also, the packet contains the value of a boolean variable, called from now on 'Val'. 'Val' is toggled on another timer, every 600 ms. A pictureBox image is updated every time 'Val' is toggled. The packet also contains the number of the packet, from now on called 'Counter' just to make sure on the second application that no packet is missed.
2. One application written in b4a running on my android phone. The application receives the 25 bytes package sent from the PC and should display on a panel one of 2 images, depending on the value of 'Val' variable. My expected behaviour is that the pictureBox in the VB6 app and the panel on the phone app are updated in the very same time, so their images are always perfectly synchronized. But the problem is that this is not happening at all. The panel on the phone app seems to be updated some times faster, some times slower, but never in the same time with the pictureBox on the vb6 App.

For some reasons, it seems that the data on the phone device does not arrive at the expected time, at least not in AStreams_NewData function.

When a packet arrives, I compute the interval passed since the last received packet with the help of function, called 'timeReceived'. On the phone app, I have a debug array that stores the received packet 'Counter', 'timeSent', 'timeReceived' and 'Val'. I have uploaded a capture of this debug variable. As you can see, the 'timeSent' is almost constant, arround 156-157 ms. But the timeReceived varies a lot, from 92 to 201 ms.

So my first question is: does anyone have idea why the received data is not coming at the same rate with the transmitted one ? My expectation is that when a packet is sent from PC app, it instantaneously gets in the AStreams_NewData function. No buffering, no delays. So I don't understand why some packets come faster than other, even though are transmitted at the aprox same rate.

The second question is: is there a better solution for what I am trying to do ? I really need that the image on the PC app and the one on the phone to toggle perfectly synchronous, and that with the help of a bluetooth connection. This is the whole purpose of my application.

Thank you in advance for your time to have read my long story.


  • DebugVar.png
    46.6 KB · Views: 194


Licensed User
Longtime User
Thank you for the response, Erel. I am not displaying any modal dialog, nor using the DoEvents function.
I have manage in the end to have the phone and PC perfectly synchronized by:
- not loading the updated image every time it changed with the help of LoadBitmap function as I did before. Instead, I am loading the 2 images in 2 separate panels at Activity_Create() and then, on NewData() just make visible/invisible the needed one.
- running the application in release mode. This really made the difference. With all my optimizations, in Debug mode I can see the image on the phone updated with a delay of about 200-300 ms. In release mode, the update is done perfectly synchronous with the PC app.

Once again, many thanks all for reading my long email and for the help.
Upvote 0