Android Question changes the Astreams to AST


Licensed User
Hallo , I changes the Astreams to AST,
But there is a mistake

Sub Process_Globals
Private ast As AsyncStreamsText
End Sub

Sub Serial1_Connected (Success As Boolean)
    If Success Then
        ToastMessageShow("Connection Successfully", False)
        ast.Initialize(Me, "ast",Serial1.InputStream, Serial1.OutputStream)
        'AStreams.Initialize(Serial1.InputStream, Serial1.OutputStream, "AStreams")
        connected = True
        vib.Vibrate (100)
        connected = False
        Msgbox("BT Not found ", "Error Connecting")
        vib.Vibrate (60)
    End If
End Sub

Sub mnudisconnect_click
    connected = False:ast.Close:Serial1.Disconnect 'connected = False:AStreams.Close:Serial1.Disconnect
    ToastMessageShow("Disconnecting Successfully", False)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        ast.Close   '  AStreams.Close
    End If
End Sub

Sub AStreams_NewData (Buffer() As Byte) 'Sub AStreams_NewData (Buffer() As Byte)
    Dim bc As ByteConverter
    Dim msg As String = bc.StringFromBytes(Buffer, "UTF8")
    Log("msg = " & msg.Length & " [" & msg & "]")
        Dim EqualsAt As Int = msg.IndexOf("=")    'INI
    If EqualsAt < 0 Then
    Log("invalid setting line: " & msg)
        Dim SettingId As String = msg.SubString2(0, EqualsAt)
        Dim SettingValue As String = msg.SubString(EqualsAt + 1)

            Select Case SettingId 
            Case "s1"
                Label1.Text = SettingValue

            Case "s2"
            Label2.Text = SettingValue

            Case "s3"
                Label4.Text = SettingValue
        End Select
    End If
End Sub

Sub sent_data
    If connected Then
        If ast.IsInitialized = False Then :Return:End If 'If AStreams.IsInitialized = False Then :Return:End If
        Dim buffer() As Byte
        buffer = data_button.GetBytes("UTF8")
            ast.Write(buffer) ' AStreams.Write(buffer)
    End If
    getar.Vibrate (50)
End Sub
Generating R file.    (0.00s)
Compiling generated Java code.    Error
B4A line: 285
ast.Write(buffer) ' AStreams.Write(buffer)
javac 1.8.0_221
src\axc\P\ error: no suitable method found for NumberToString(byte[])
_ast._write /*String*/ (BA.NumberToString(_buffer));
    method BA.NumberToString(double) is not applicable
      (argument mismatch; byte[] cannot be converted to double)
    method BA.NumberToString(float) is not applicable
      (argument mismatch; byte[] cannot be converted to float)
    method BA.NumberToString(int) is not applicable
      (argument mismatch; byte[] cannot be converted to int)
    method BA.NumberToString(long) is not applicable
      (argument mismatch; byte[] cannot be converted to long)
    method BA.NumberToString(Number) is not applicable
      (argument mismatch; byte[] cannot be converted to Number)
1 error
where did the error come from, is there a solution?
thank you


Licensed User

AsyncStreamsText deliver the incoming data as String and it expect a String to send.

Example from the Class thread

Note the differences to your Code

Sub ast_NewText(Text As String)
   Log("Text: " & Text)
End Sub

Sub ast_Terminated
   Log("Connection terminated")
End Sub

Sub Activity_Click
   ast.Write("this is an example..." & Chr(10) & Chr(13))
End Sub
Last edited: