I managed to get the data but when i send data from the terminal, nothing comes. But if i send data from micricontroller via bluetooth, the data comes with this error. Moreover, [00 46 00 0b ff ff 00 00] must come but only [46 00 0b ff ff 00 00] comes. Where is the first bite?
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'Activity module
Sub Process_Globals
Dim AStream As AsyncStreams
Dim bc As ByteConverter
End Sub
Sub Globals
Dim readings As EditText
Dim label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("2")
readings.Color = Colors.black
If AStream.IsInitialized = False Then
'AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
AStream.Initialize(Main.Serial1.InputStream, Main.Serial1.OutputStream, "AStreams")
End If
End Sub
Sub AStreams_NewData (Buffer() As Byte)
readings.Text=Buffer(0)
label1.Text=("Data: " & bc.HexFromBytes(Buffer))
End Sub
Sub AStream_Error
ToastMessageShow("Connection is broken.", True)
End Sub
Sub AStream_Terminated
AStream_Error
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
AStream.Close
End If
End Sub
Sub LightOn_Click
AStream.Write(Array As Byte(0x00,0x05,0x3f))
End Sub