Android Question Astreams.Write error

Declan

Well-Known Member
Licensed User
Longtime User
I am using AsyncStreamsText to communicate with an Arduino via the USB port.
My code to Write:
B4X:
Sub spnrTransferStock_ItemClick (Position As Int, Value As Object)
    If Value <> "SELECT AREA TO TRANSFER STOCK TO" Then
        lblTransferStockTip.Text = "SCAN PRODUCT TO TRANSFER"
' Switch Scanner ON
    Dim stringTX As String
    stringTX = "s" & Chr(13) & Chr(10)
    astreams.Write(stringTX)
    End If
End Sub

Initialization occurs here:
B4X:
Sub ConnectUSB
        If usb.UsbPresent = usb.USB_NONE Then
        Log("Msgbox - no device")
        Msgbox("No USB device or accessory detected!", "Error")
        Log("Msgbox - returned")
        Return
    End If
    Log("Checking permission")
    If (usb.HasPermission) Then
'        Msgbox(usb.DeviceInfo, "Device Information")
        Dim dev As Int
        dev = usb.Open(9600)       
        If dev <> usb.USB_NONE Then
            astreams.Initialize(Me, "astreams",usb.GetInputStream,usb.GetOutputStream)
        Else
            Log("Error opening USB port")
        End If
    Else
        usb.RequestPermission
    End If
End Sub

But I receive this error:
B4X:
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
~w:1004,main,122
** Activity (main) Resume **
ExecuteHtml: SELECT barcode As [BARCODE], description As [PRODUCT], unitsonhand As [ON HAND], date As [DATE RECEIVED] FROM mainstore ORDER BY description
asyncstreamstext_write (B4A line: 1335)
astreams.Write(stringTX)
java.lang.RuntimeException: Object was not initialized.
    at anywheresoftware.b4a.debug.Debug.PushSubsStack(Debug.java:122)
    at b4a.example.asyncstreamstext._write(asyncstreamstext.java:215)
    at b4a.example.main._spnrtransferstock_itemclick(main.java:3838)
    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$2.run(BA.java:299)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5624)
    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:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

java.lang.RuntimeException: Object was not initialized.

But astreams is initialized?
 

Declan

Well-Known Member
Licensed User
Longtime User
Dunno - never tried rapid debug :oops:
I finaly resolved the issue I was having - block commented the initialize out :oops:
 
Upvote 0
Top