Bluetooth Serial Receive Problems

Rigsby

Member
Licensed User
Longtime User
Hi,

I am trying to receive data via bluetooth, and have a problem, any views or help would be great. Sending is no problem, just receiving.

Using the tutorials, I have partial success.

Using the AsyncStreams method, and the tutorial, as recommended, when you receive data, it mashes up the data. Randomly, some characters are misplaced, and moved, and some characters are dropped. It does not seem to be baudrate dependant, as it does it just as much at 1200 as at 19200 (the max I need).

Using the older Serial tutorials, and polling the streams using a timer, it works fine, and never drops a character. However, the data that is being received can have CR/LF or LF/CR/CR or CR as the end of lines. Works fine with CR/LF, but textreader.readline blocks if using anything but CR/LF

So my questions are..

Anyone have a reliable solution to the Asyncstreams ? or is there a workaround to the blocking call for Readline when a LF is never received.

Thanks
 

Rigsby

Member
Licensed User
Longtime User
Erel

Thank your for the reply. I think I have sorted a solution.

In the AStream_NewData sub, I was getting the buffer data, and concatenating a string strReceivedData to write as a single TextWriter.Write when I want to save the file after all the data has finished, as I need to process the data before saving. I don't know if this was the problem, but writing each buf as a TextWriter.Write(buf) seems to have solved the problem and all data is in the correct order. I notice that scrolling the data to a text box, when the amount of data is large and fast can cause my device to hang, so a simple byte count to a label works fine instead.

Thanks

Sub AStream_NewData (Buffer() As Byte)

buf = BytesToString(Buffer, 0, Buffer.Length, "UTF8")

'strReceivedData = strReceivedData & buf
bytesReceived = bytesReceived + buf.Length
write_data_to_file.Write(buf)
lblCountBytesReceived.Text = bytesReceived
 
Upvote 0
Top