Hello
I have app with sync communication between tablet and microprocessor but due many hangups(waiting for reply etc) I want to use asyncstreams.
I totaly newbie so VERY thanks for help.
I found here code which I wanted try on my tablet, but it generate error:
Code:
when I try compile it error is here:
error:
Parsing code. 0.01
Compiling code. 0.11
Compiling layouts code. 0.00
Generating R file. 0.16
Compiling generated Java code. Error
B4A line: 114
ASt.Write(buffer)
javac 1.8.0_25
src\b4a\example\main.java:391: error: no suitable method found for NumberToString(byte[])
_ast._write(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
I have app with sync communication between tablet and microprocessor but due many hangups(waiting for reply etc) I want to use asyncstreams.
I totaly newbie so VERY thanks for help.
I found here code which I wanted try on my tablet, but it generate error:
Code:
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#ApplicationLabel: BlackBox Simple Remote
#CanInstallToExternalStorage: true
#SupportedOrientations: portrait
#FullScreen: true
'Activity module
Sub Process_Globals
Dim Serial1 As Serial
Dim TextReader1 As TextReader
Dim TextWriter1 As TextWriter
Dim connected As Boolean
Private ASt As AsyncStreamsText
Dim RX As String
End Sub
Sub Globals
Dim PWS As PhoneWakeState
Dim txtSend As EditText
Dim Azimuth As Int
Dim Elevation As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Manual")
If FirstTime Then
Serial1.Initialize("Serial1")
PWS.KeepAlive(True)
End If
Activity.AddMenuItem("Connect", "MenuConnect")
Activity.AddMenuItem("Disconnect", "MenuDisconnect")
Activity.AddMenuItem("Exit","MenuExit")
Activity.Title = "BlackBox Simple Remote"
End Sub
Sub Activity_Resume
If Serial1.IsEnabled = False Then
Msgbox("Please enable Bluetooth.", "")
Else
Serial1.Listen 'listen for incoming connections
End If
End Sub
Sub menuConnect_Click
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res = InputList(l, "Choose device", -1) 'show list with paired devices
If res <> DialogResponse.CANCEL Then
Serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address
End If
End Sub
Sub MenuExit_click
PWS.ReleaseKeepAlive
Serial1.Disconnect
connected = False
ExitApplication
End Sub
Sub Serial1_Connected (Success As Boolean)
If Success Then
ToastMessageShow("Connected successfully", False)
ASt.Initialize(Me,"ASt",Serial1.InputStream, Serial1.OutputStream)
connected = True
Else
connected = False
Msgbox(LastException.Message, "Error connecting.")
End If
End Sub
Sub menuDisconnect_Click
Serial1.Disconnect
connected = False
End Sub
Sub Activity_Pause(UserClosed As Boolean)
If UserClosed Then
'Log("closing")
'AStreams.Close
End If
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
Dim x As Byte
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
If msg.StartsWith("+") Then
x = 1
Azimuth = msg.SubString2(2,5)
Elevation = msg.SubString2(7,10)
Else
x= 0
End If
End Sub
Sub AStreams_Error
ToastMessageShow(LastException.Message, True)
End Sub
Sub btnSend_Click
If ASt.IsInitialized = False Then Return
If txtSend.Text.Length > 0 Then
Dim buffer() As Byte
buffer = txtSend.Text.GetBytes("UTF8")
ASt.Write(buffer)
txtSend.SelectAll
'Log("Sending: " & txtSend.Text)
End If
txtSend.Text = ""
End Sub
Sub Send_Single_Command (Command As String)
Dim Buffer() As Byte
Dim B As String
B = Command & Chr(13)
Buffer = B.GetBytes("UTF8")
ASt.Write(Buffer)
End Sub
Sub UP_Click
Send_Single_Command("U")
End Sub
Sub down_Click
Send_Single_Command("D")
End Sub
Sub CW_Click
Send_Single_Command("R")
End Sub
Sub ccw_Click
Send_Single_Command("L")
End Sub
Sub Stop_Click
Send_Single_Command("S")
End Sub
Sub button_az_0_Click
Send_Single_Command("M000")
End Sub
Sub Button_az_90_Click
Send_Single_Command("M090")
End Sub
Sub Button_az_180_Click
Send_Single_Command("M180")
End Sub
Sub Button_az_270_Click
Send_Single_Command("M270")
End Sub
Sub Button_az_360_Click
Send_Single_Command("M360")
End Sub
Sub Button_el_0_Click
Send_Single_Command("Y000")
End Sub
Sub Button_el_22_Click
Send_Single_Command("Y022")
End Sub
Sub Button_el_45_Click
Send_Single_Command("Y045")
End Sub
Sub Button_el_67_Click
Send_Single_Command("Y067")
End Sub
Sub Button_el_90_Click
Send_Single_Command("Y090")
End Sub
Sub GotoManual_Click
Activity.RemoveAllViews
Activity.LoadLayout("manual")
End Sub
Sub GotoPreset_Click
Activity.RemoveAllViews
Activity.LoadLayout("preset")
End Sub
when I try compile it error is here:
B4X:
ASt.Write(buffer)
error:
Parsing code. 0.01
Compiling code. 0.11
Compiling layouts code. 0.00
Generating R file. 0.16
Compiling generated Java code. Error
B4A line: 114
ASt.Write(buffer)
javac 1.8.0_25
src\b4a\example\main.java:391: error: no suitable method found for NumberToString(byte[])
_ast._write(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