B4J Question How to measure time between astream1_NewText events?

Discussion in 'B4J Questions' started by positrom2, Sep 30, 2014.

  1. positrom2

    positrom2 Active Member Licensed User

    I would like to measure the time between subsequent data arriving in the
    astream1_NewText sub (using AsyncstreamsText).
    Dim dt,dt1 As Long
    Sub astream1_NewText(Text As String)
    If m Mod 2 =0 Then
    End If
    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?
  2. Daestrum

    Daestrum Well-Known Member Licensed User

    move the 'log(dt1 - dt)' to before the 'end if' line.
  3. positrom2

    positrom2 Active Member Licensed 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?
  4. Erel

    Erel Administrator Staff Member Licensed User

    What do you mean with real-time? You are sending data over the network. Don't expect the data to arrive immediately.
  5. positrom2

    positrom2 Active Member Licensed User

    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.
    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice