Serial port not recieving all bytes after first recieve event?

DanielB33

Active member
Joined
Mar 29, 2013
Messages
40
Programming Experience
1-3
I need to update a real time display with information for 7 bytes of data every 300ms or so. When receiving the seven bytes, I get all (correct) data for the first receive event. After the first receive event I usually I only receive 1 byte. Changing the threshold does not seem to help. Previously I was implementing the same program but my micro had usb, I used this to make a virtual COM port. With this configuration everything worked perfectly, but now that I am using usart (rs-232) with a serial to usb cable things are not working the same. This implies that the datarecieved event is firing before I get all my data. Increasing my datarate by 10 fold showed better results, but not anywhere near perfect. Is there a way to hald my receiving until I know I received all the data I need??? Once I request data, can I put my recievehandler to sleep for a few ms??? (without putting the rest of my program to sleep) Thanks for your time. (I have verified that I get correct output via teraterm) Public mySerialPort AsNewSerialPort
PublicSub CommPortSetup()
With mySerialPort
.PortName = cboCOM.Text

.BaudRate = 921600 '115200
.DataBits = 8
.Parity = Parity.None
.StopBits = StopBits.One
.Handshake = Handshake.None
'.RtsEnable = True
.DtrEnable = True
.WriteTimeout = 200
.ReadTimeout = 200
.ReceivedBytesThreshold = 8


AddHandler mySerialPort.DataReceived, AddressOf DataReceivedHandler '
EndWith
Try

mySerialPort.Open()
If (mySerialPort.IsOpen) Then
EndIf

Catch ex AsException
' MsgBox(ex.Message) 'Send
EndTry
EndSub
 
I solved this by reading my rx buffer by polling rather than interrupting to get received information, and using start of transmit and end of transmit packets. A circular buffer made it work very well.
 
Back
Top