Yes I tried what you suggested but it does not reconnect. There is no event being created to have it check to see if the device is online again. So I need something to check it every 10 secs or so. I can Serial.Listen for weeks and nothing gets fired.
After some trial and error I have my scanners working the way I need them to.
I think each barcode reader has it's own personality. My Symbol device connects fast the Inateck takes 20 secs or so.
I do get an error once in awhile after connection has been successful on the ast.Initialize(... line but I think it is timing issue. The ScanDevice (serial stream) must not be completely established prior to assigning the InputStream to the AsyncStreamsText. I'm testing it on a Note 4
Code:
Sub ScanDevice_Connected (Success As Boolean)
If Success Then
ProgressDialogHide
ToastMessageShow("Scanner Connected successfully", False)
Try
ast.Initialize(Me,"ast", ScanDevice.InputStream, ScanDevice.OutputStream)
Catch
End Try
Connected=True
Else
ScanDevice.Listen
Connected=False
End If
End Sub
It cannot be a Null Object Reference if it just connected.
---------- ERROR -----------------------
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.InputStream android.bluetooth.BluetoothSocket.getInputStream()' on a null object reference
at anywheresoftware.b4a.objects.Serial.getInputStream(Serial.java:254)
at com.dscorp.InScan50Standard.queryscreen._scandevice_connected(queryscreen.java:813)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA$3.run(BA.java:332)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5972)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)