I have the code shown below. It listens for incoming serial data but will also send a request to the device when this is working.
When this gets to this point --> Log ("******** ASTREAM 1 ****************") - it crashes - prior to that is all fine and connection is established.
I don't need the PREFIX version of AsyncStreams for this purpose - and it will send one character ("?") to request and get a value back from the device.
the abridged unfiltered log is below the code.
Any ideas on a solution?
There again, maybe this is not the way to read/write to a "raw" serially connected device. ?️?️
When this gets to this point --> Log ("******** ASTREAM 1 ****************") - it crashes - prior to that is all fine and connection is established.
I don't need the PREFIX version of AsyncStreams for this purpose - and it will send one character ("?") to request and get a value back from the device.
the abridged unfiltered log is below the code.
Any ideas on a solution?
There again, maybe this is not the way to read/write to a "raw" serially connected device. ?️?️
AsyncStreams initialisation error:
Private Sub btnReadSerialData_Click
Private labelNAME As String
Private labelMAC As String
clv.Clear
Log ("****** Pressed serial button *******")
'' read serial data from here......
''''' serial.Connect("50:65:83:6F:92:15")
Log ("******** SERIAL ****************")
Log (" Serial initialised")
Log (serial.IsInitialized)
''''
serial.Listen
labelNAME = ConnectedName
labelMAC = ConnectedMAC
Label3.text = labelNAME & " " & labelMAC
Log ("************************")
''' Found: device-1.0,50:65:83:6F:92:15, RSSI = -42, (MyMap) {1=[B@30e2fe5, -1=[B@fc05aba, 9=[B@6677d6b, 18=[B@e0930c8, 10=[B@976e561, 2=[B@b896886, 0=[B@4fe8547}
' If AStreams.IsInitialized Then AStreams.Close
' 'prefix mode! Change to non-prefix mode if communicating with non-B4X device.
' AStream.InitializePrefix(serial.InputStream, False, serial.OutputStream, "astreams")
''''
Log ("************************")
Log ("*** GET THE PAIRED DEVICE ***")
ToastMessageShow (" GET THE PAIRED DEVICE ", True)
whosisthere
Log ("************************")
' Log ("******* Phone *****************")
' Log(serial.Address)
' Log (serial.Name)
' Log ("************************")
' buffer = "?"
''''get stuff from raingauge-1.0 now
Log ("******** ASTREAM 1 ****************")
'
AStreams.Initialize(serial.InputStream, serial.OutputStream, "AStreams")
' AStream.Write(buffer.GetBytes("utf8"))
' AStreams.Close
Log ("******** ASTREAM 2 ****************")
Disconnect
End Sub
******** ASTREAM 1 ****************
b4xmainpage_btnreadserialdata_click (java line: 163)
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:256)
at b4a.Raingauge.b4xmainpage._btnreadserialdata_click(b4xmainpage.java:163)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8587)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
FATAL EXCEPTION: main
Process: b4a.Raingauge, PID: 12167
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:256)
at b4a.Raingauge.b4xmainpage._btnreadserialdata_click(b4xmainpage.java:163)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8160)
at android.widget.TextView.performClick(TextView.java:16222)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8587)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
isSocketAllowedBySecurityPolicy start : device null
connect() for device 506583 called by pid: 12167
getBluetoothService() called with no BluetoothManagerCallback