Hi All,
I have a RN41 Bluetooth Module connected to a PIC Microcontroller and I have it set-up at a baud rate of 9600.
I have everything working well for the exception I am reading certain parts on the incoming string "not all connected", for example I trying to read a value of 8.27mpy and sometimes I get 8.27mpy but most of the time I get:
8 (first)
and then only only .29mpy
I have tried everything as I took Erel's Bluetooth example (BTW which is brilliant) and tried to use Asyncstreams without a prefix and a timer delay and even tried it with AsyncstreamsText (of which does not show any data from the incoming string, somehow I have perhaps confused myself trying a hundred different things,
please see below, perhaps there is something I have missed?, any help would be greatly appreciated,
I have a RN41 Bluetooth Module connected to a PIC Microcontroller and I have it set-up at a baud rate of 9600.
I have everything working well for the exception I am reading certain parts on the incoming string "not all connected", for example I trying to read a value of 8.27mpy and sometimes I get 8.27mpy but most of the time I get:
8 (first)
and then only only .29mpy
I have tried everything as I took Erel's Bluetooth example (BTW which is brilliant) and tried to use Asyncstreams without a prefix and a timer delay and even tried it with AsyncstreamsText (of which does not show any data from the incoming string, somehow I have perhaps confused myself trying a hundred different things,
please see below, perhaps there is something I have missed?, any help would be greatly appreciated,
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'Activity module
Sub Process_Globals
Private ast As AsyncStreamsText
Dim timerstreams As Timer
Dim AStream As AsyncStreams
End Sub
Sub Globals
Dim myBuffer As String
Dim txtInput As EditText
Dim txtLog As EditText
Dim btnSend As Button
Dim ticksOfInactivity As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
'timerstreams.Initialize("timerStreams", 100)
Activity.LoadLayout("2")
'If AStream.IsInitialized = False Then
If ast.IsInitialized = False Then
'AStream.Initialize(Main.Serial1.InputStream, Main.Serial1.OutputStream, "AStream")
ast.Initialize(Me,"ast", Main.serial1.InputStream, Main.serial1.OutputStream)
End If
txtLog.Width = 100%x
End Sub
Sub AStream_NewData (Buffer() As Byte)
'myBuffer = myBuffer & LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
'ticksOfInactivity=0
' timerstreams.enabled=True
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
'If Buffer.Length >= 6 Then
'myBuffer = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
'LogMessage("You",myBuffer)
'End If
End Sub
Sub AStream_Error
ToastMessageShow("Connection is broken.", True)
btnSend.Enabled = False
txtInput.Enabled = False
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 txtInput_EnterPressed
If btnSend.Enabled = True Then btnSend_Click
End Sub
Sub btnSend_Click
AStream.Write(txtInput.Text.GetBytes("UTF8"))
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub
Sub LogMessage(From As String, Msg As String)
txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End Sub