Erel, Starting a new thread here (left the thread AtomicInteger).
I stripped down AST's astreams_NewData to the following, adding a "Lock" (DataInSem), and a counter iP as Int in Class_Globals.
Then I logged some output, where I first let it run for bit, then hit a button and brought up a menu, waited a bit, then hit back-arrow to cancel, then logged what followed. Below is the log output.
The micro w/BT transmitting the data is sending about the same thing every time, with slight variation.
Basically: "B,H0000,V0127,F000,S000,D0,A0700,W12700,T10,E<CR><LF>" is repeated once a second from the micro.
As each partial string comes in the _NewData in Buffer(), Lock is taken, iP is incremented, converted to string, prepended to the incoming string conversion of buffer, the Logged, and lock released.
Log:
Installing file.
...
** Activity (main) Resume **
Serial connected: true
1B,H0000,V0127,F000,S000,D0,A0700,W12700,T10,E
2B
3,H0000,V0127,F000,S000,D0,A0000,W12
4700,T20,E
5B,H0000,V0127,F000,S000,D0,A0000,W1
62700,T20,E
7B,H0000,V0127,F000,S000,D0,A0000,W12700,T20,E
8B,H0000,V0127,F000,S000,D0,A0100,W12
9700,T30,E
10B
11,H0000,V0127,F000,S000,D0,A0100,W12
12700,T30,E
13B
14,H0000,V0127,F000,S000,D0,A0100,W12 < Button is hit right after this>
15700,T30,E
162700,T10,E
17000,V0127,F000,S000,D0,A0000,W12700
18B
19,T20,E
202700,T00,E
21B
22,H0000,V0127,F000,S000,D0,A0400,W1
232700,T00,E
24B
25,H0000,V0127,F000,S000,D0,A0700,W1
26000,V0127,F000,S000,D0,A0400,W12700,
27,H0000,V0127,F000,S000,D0,A0700,W1
282700,T10,E
29B,H0
30T00,E
31,H0000,V0127,F000,S000,D0,A0400,W1
32B
33B
34,H0000,V0127,F000,S000,D0,A0700,W1
35B,H0
362700,T10,E
37B
38,H0000,V0127,F000,S000,D0,A0000,W1
392700,T20,E
40B
41,H0000,V0127,F000,S000,D0,A0000,W1
422700,T20,E
43B
44,H0000,V0127,F000,S000,D0,A0100,W127
4500,T30,E
The phone app's button isn't pressed until line #14 is out. All is good to that point. The app menu comes up, I wait a few seconds, then hit back-arrow to cancel.
The output is not written to the B4A Gui 'log' window until the menu is cancelled.
Note the order of the text 'chunks', each numbered by iP, is now in order numerically of iP, but the string portions are out of order.
At output #33 the ordering returns to correct order.
Any ideas? It appears to me that AsyncStreams is delivering the substrings in the wrong order, when the App's GUI pulls up a menu.
Is the source for AsyncStreams (from RandomAccessFile) available to me?
I tried RAF 1.5.1, then 1.5.0. I didn't go back to January's RAF.
Edit: Modal Dialogs in the Activity will block events in AsyncStreams, resulting in out of order delivery of the message substrings (AsyncStreams will break up an incoming message as designed). Even if the AsyncStreams is in a Service.
I stripped down AST's astreams_NewData to the following, adding a "Lock" (DataInSem), and a counter iP as Int in Class_Globals.
B4X:
Private Sub astreams_NewData (Buffer() As Byte)
DataInSem.Wait
iP = iP + 1
Dim sP As String = iP
Dim s As String = BytesToString(Buffer, 0, Buffer.Length, charset)
Log(sP & s)
DataInSem.Unlock
End Sub
Then I logged some output, where I first let it run for bit, then hit a button and brought up a menu, waited a bit, then hit back-arrow to cancel, then logged what followed. Below is the log output.
The micro w/BT transmitting the data is sending about the same thing every time, with slight variation.
Basically: "B,H0000,V0127,F000,S000,D0,A0700,W12700,T10,E<CR><LF>" is repeated once a second from the micro.
As each partial string comes in the _NewData in Buffer(), Lock is taken, iP is incremented, converted to string, prepended to the incoming string conversion of buffer, the Logged, and lock released.
Log:
Installing file.
...
** Activity (main) Resume **
Serial connected: true
1B,H0000,V0127,F000,S000,D0,A0700,W12700,T10,E
2B
3,H0000,V0127,F000,S000,D0,A0000,W12
4700,T20,E
5B,H0000,V0127,F000,S000,D0,A0000,W1
62700,T20,E
7B,H0000,V0127,F000,S000,D0,A0000,W12700,T20,E
8B,H0000,V0127,F000,S000,D0,A0100,W12
9700,T30,E
10B
11,H0000,V0127,F000,S000,D0,A0100,W12
12700,T30,E
13B
14,H0000,V0127,F000,S000,D0,A0100,W12 < Button is hit right after this>
15700,T30,E
162700,T10,E
17000,V0127,F000,S000,D0,A0000,W12700
18B
19,T20,E
202700,T00,E
21B
22,H0000,V0127,F000,S000,D0,A0400,W1
232700,T00,E
24B
25,H0000,V0127,F000,S000,D0,A0700,W1
26000,V0127,F000,S000,D0,A0400,W12700,
27,H0000,V0127,F000,S000,D0,A0700,W1
282700,T10,E
29B,H0
30T00,E
31,H0000,V0127,F000,S000,D0,A0400,W1
32B
33B
34,H0000,V0127,F000,S000,D0,A0700,W1
35B,H0
362700,T10,E
37B
38,H0000,V0127,F000,S000,D0,A0000,W1
392700,T20,E
40B
41,H0000,V0127,F000,S000,D0,A0000,W1
422700,T20,E
43B
44,H0000,V0127,F000,S000,D0,A0100,W127
4500,T30,E
The phone app's button isn't pressed until line #14 is out. All is good to that point. The app menu comes up, I wait a few seconds, then hit back-arrow to cancel.
The output is not written to the B4A Gui 'log' window until the menu is cancelled.
Note the order of the text 'chunks', each numbered by iP, is now in order numerically of iP, but the string portions are out of order.
At output #33 the ordering returns to correct order.
Any ideas? It appears to me that AsyncStreams is delivering the substrings in the wrong order, when the App's GUI pulls up a menu.
Is the source for AsyncStreams (from RandomAccessFile) available to me?
I tried RAF 1.5.1, then 1.5.0. I didn't go back to January's RAF.
Edit: Modal Dialogs in the Activity will block events in AsyncStreams, resulting in out of order delivery of the message substrings (AsyncStreams will break up an incoming message as designed). Even if the AsyncStreams is in a Service.
Last edited: