Morning,
Q. - I have a serial port connected to a Bluetooth adapter (one of those cheap SPP-C modules). I send it a couple of AT commands but the last character of the string is always missing. I can use teraterm and manually enter the AT commands aall is correct, when I log the sending strings all look correct, but the response always has the last character of the string missing. Sending the AT command from my app then reading back in teraterm confirms that the BT module has "dropped" the final character. so I must conclude there is something amiss in the sending routine.
Log also seems to be receiving some random CRLF's in the module replies. Any ideas ? TIA
Sending code
Reading code
Q. - I have a serial port connected to a Bluetooth adapter (one of those cheap SPP-C modules). I send it a couple of AT commands but the last character of the string is always missing. I can use teraterm and manually enter the AT commands aall is correct, when I log the sending strings all look correct, but the response always has the last character of the string missing. Sending the AT command from my app then reading back in teraterm confirms that the BT module has "dropped" the final character. so I must conclude there is something amiss in the sending routine.
Log also seems to be receiving some random CRLF's in the module replies. Any ideas ? TIA
Sending code
B4X:
Sub setbutton_MouseClicked (EventData As MouseEvent)
If astream.IsInitialized = False Then Return
Dim s As String
Dim buffer() As Byte
If btname.Text.Length > 0 Then
s ="AT+NAME"&btname.Text&CRLF
buffer = s.GetBytes("UTF8")
astream.Write(buffer)
Log("Sending: " & s)
End If
If Pinfield.Text.Length = 4 Then
s ="AT+PIN"&Pinfield.Text&CRLF
buffer = s.GetBytes("UTF8")
astream.Write(buffer)
Log("Sending: " & s)
End If
End Sub
Reading code
B4X:
Sub AStream_NewData (Buffer() As Byte)
Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log (s)
End Sub