B4J Question How to measure time between astream1_NewText events?

positrom2

Active Member
Licensed User
Longtime User
I would like to measure the time between subsequent data arriving in the
astream1_NewText sub (using AsyncstreamsText).
B4X:
Dim dt,dt1 As Long
Sub astream1_NewText(Text As String)
m=m+1
If m Mod 2 =0 Then
dt=DateTime.now
Else
dt1=DateTime.now
End If
Log(dt1-dt)
The log values vary randomly between -100,0,83,1... etc although the data are being sent regularly every 50ms via bluetooth.

Could somebody suggest?
 

Daestrum

Expert
Licensed User
Longtime User
move the 'log(dt1 - dt)' to before the 'end if' line.
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Looks better, mostly I get 100 (might be right) but values scatter, 0,0,4,100,100....
I have read that Asyncstreams (and Java) isn't really real-time...:(
Or, any other suggestion?
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Don't expect the data to arrive immediately.
Yes, I was aware of that, but that probably is not to be the reason for the problem:
The µC sends data steadily (20/s). When the app is started, there is apparently data in some buffer (I don't know where that is located). Accordingly the B4J app plots this buffered data very fast and the plot does not reflect the current values the µC is sending -the plot is "dead" for a while (the same with B4A). When the buffer is becoming empty,the plotting speed is reduced as it should and the plot "immediately" responds to changed data sent from the µC.
I tried to empty the B4J-buffer by using purge, but that does not change the situation.
sp1.Open("COM7")
sp1.Initialize("")
sp1.SetParams(921600,8,1,0) 'the baud rate is unimportant here because of BT
astream1.Initialize(Me, "astream1",sp1.GetInputStream, sp1.GetOutputStream)
sp1.purgeport(8)
Therefore I tried to measure the speed of the incoming data to suspend the plot until the buffer is empty.

I think when the data are retrieved from the buffer faster than they are coming in we can watch them in "real time" on that time scale. The problem is to empty the buffer or to find a way to know that "ancient" data are being processed. The latter I tried by measuring the speed of data seen by Asyncstreams -with limited success.
 
Upvote 0
Top