Android Question USB serial

Liew

Member
Licensed User
Longtime User
Hi Erel,
May I know why am I getting only 1 byte as a time on the serial receive stream when a serial data is available.
Program segment:
Private Sub serial_DataAvailable (Buffer() As Byte)
Log("New data: " & bc.HexFromBytes(Buffer))
End Sub
I expect a block of data for processing but it comes back byte by byte. Is there anything I need to set?
Please advice.
Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
don´t do! This is a Communityforum

It is expected that the data does not come in one packet. You need to capture them.

PS: Please use CODE tags when posting code.
 
Upvote 0

Liew

Member
Licensed User
Longtime User
don´t do! This is a Communityforum

It is expected that the data does not come in one packet. You need to capture them.

PS: Please use CODE tags when posting code.
Hi DonManfred,
I am sorry as I seldom use this forum and perhaps post question at the wrong place.
We normally get a stream of data block using TCP Socket stream and it is easy to decode
But for this USB serial, data comes one byte at a time. It is difficult to decode as the data must have a unique header and trailer in order to recognize it.
So I wander why USB serial so different in its data capturing behavior.
Thanks.
Liew
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
So I wander why USB serial so different in its data capturing behavior.
All RS232 style serial devices from the dawn of time have this feature. It is a bit odd if you are really only getting one byte each time unless you are running at a very low baud rate but it is entirely normal for a block of data sent at one end to arrive as several interrupts at the other. Robust serial comms is not as simple as many people think. As you point out you need headers and byte counts or headers and trailers to identify blocks of data, and it is non-trivial to design code that can can cope with data corruption and missing bytes - particularly if they are a header, trailer or byte count.
 
Upvote 0

Liew

Member
Licensed User
Longtime User
All RS232 style serial devices from the dawn of time have this feature. It is a bit odd if you are really only getting one byte each time unless you are running at a very low baud rate but it is entirely normal for a block of data sent at one end to arrive as several interrupts at the other. Robust serial comms is not as simple as many people think. As you point out you need headers and byte counts or headers and trailers to identify blocks of data, and it is non-trivial to design code that can can cope with data corruption and missing bytes - particularly if they are a header, trailer or byte count.
I am using 9600bps for the testing. I will try to set a higher rate and see what I will get.
Thanks.
Liew
 
Upvote 0
Top