Android Question MsgboxAsync with AsyncStreams object

GaNdAlF89

Active Member
Licensed User
Longtime User
Hi to all!
I need to connect to a physical (with laser) barcode reader via bluetooth, and I receive the barcode read using the AsyncStreams object. I need a MsgboxAsync inside both the "AsyncStreamReader_NewText (strBuffer As String)" and "AsyncStreamReader_Error" events.
Since these are events not related to an user interaction (the barcde reader is always active, in an entrance door, but when it reads a barcode, an operator have to make a decision), how can I do to make "As Resumable" both the _NewText and _Error events? Thank you.

Current code:
B4X:
Sub BTSerialReader_Connected (Success As Boolean)
    If Success=True Then
       BTAsyncStreamReader.Initialize(Me,"BluetoothAsyncStreamReader",BTSerialReader.InputStream,BTSerialReader.OutputStream)
       'etc
End Sub

Sub BluetoothAStreamReader_NewText (strBuffer As String)
    Dim TipoMov As List
    TipoMov.Initialize2(Array As String("In","Out"))
       
    Dim ro As Object = InputListAsync(TipoMov,"Seleziona tipologia di...",-1,False)
    Wait For (ro) InputList_Result (res As Int)
    If res = 0 Then
        'etc...
End Sub
Sub BluetoothAStreamReader_Error
     MsgboxAsync("Reading error...","Attention")
     Wait For Msgbox_Result (res As Int)
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot wait for two different events at the same point.

You can do something like this:
B4X:
Sub BTSerialReader_Connected (Success As Boolean)
    If Success=True Then
       BTAsyncStreamReader.Initialize(Me,"BluetoothAsyncStreamReader",BTSerialReader.InputStream,BTSerialReader.OutputStream)
        Wait For MyNewText (Success As Boolean, Text As String)
         'do whatever you need here
End Sub

Sub BluetoothAStreamReader_NewText (strBuffer As String)
 CallSubDelayed3(Me, "MyNewText", True, strBuffer)
End Sub

Sub BluetoothAStreamReader_Error
CallSubDelayed3(Me, "MyNewText", False, "")
End Sub
 
Upvote 0

GaNdAlF89

Active Member
Licensed User
Longtime User
You cannot wait for two different events at the same point.

You can do something like this:
B4X:
Sub BTSerialReader_Connected (Success As Boolean)
    If Success=True Then
       BTAsyncStreamReader.Initialize(Me,"BluetoothAsyncStreamReader",BTSerialReader.InputStream,BTSerialReader.OutputStream)
        Wait For MyNewText (Success As Boolean, Text As String)
         'do whatever you need here
End Sub

Sub BluetoothAStreamReader_NewText (strBuffer As String)
CallSubDelayed3(Me, "MyNewText", True, strBuffer)
End Sub

Sub BluetoothAStreamReader_Error
CallSubDelayed3(Me, "MyNewText", False, "")
End Sub
Thanks for the reply. Meanwhile I thought at this solution:
B4X:
Sub BTSerialReader_Connected (Success As Boolean)

    If Success=True Then

       BTAsyncStreamReader.Initialize(Me,"BluetoothAsyncStreamReader",BTSerialReader.InputStream,BTSerialReader.OutputStream)
       'nothing else here
  
End Sub

Sub BluetoothAStreamReader_NewText (strBuffer As String)

    Wait For BluetoothAStreamReader_MyResponse(True,strBuffer) Complete (Result As Object)

End Sub

Sub BluetoothAStreamReader_Error

    Wait For BluetoothAStreamReader_MyResponse(False,"") Complete (Result As Object)

End Sub

Sub BluetoothAStreamReader_MyResponse (Success As Boolean, Text as String) As Resumable
  
    'my prevoius code from _NewText and _Error, based on Success...
  
    Return Null
End Sub
Is it correct?
 
Upvote 0
Top