-
Nov 7th, 2014, 10:53 PM
#1
Thread Starter
New Member
Sending huge Data buffer to Serial Port
Hi
I am using VB.net 2008, on windows 7 machine
I am trying to send Data buffer to serial port
Dim DataOut(255) As Byte
other side I am using Terminal.exe to receive,
I am getting few bytes dropped,
But if I add delay between Char to Char, then I am getting properly,
How to calculate delay for different baud rates
currently I am using System.Threading.Thread.Sleep(1) for 9600
For Count = 0 To Tmp
TChar = DataOut(Count)
SerialPort1.Write(New Byte() {TChar}, 0, 1)
System.Threading.Thread.Sleep(1)
Next Count
My doubt is , is there any way we can get status of previous byte transmission finisned?
or How much delay needs to be added for different baud rate.
Thank you,
- Chinnni
-
Nov 8th, 2014, 08:16 PM
#2
Addicted Member
Re: Sending huge Data buffer to Serial Port
There is something wrong if you are having to use Thread.Sleep.
Are you using flow control on your serial port? Is it setup correctly?
You might be overflowing the serialport writebuffer, Its default size is 2048 bytes but I doubt it.
Sorry I cant be of more help but this might give you a direction to look in.
-
Nov 9th, 2014, 08:35 AM
#3
Re: Sending huge Data buffer to Serial Port
Instead of a loop, did you just try to send the buffer?
Code:
If tmp <= 255 Then
SerialPort1.Write(DataOut, 0, tmp)
End If
The above should work fine without dropping any characters.
If you think you are trying to send the buffer too often (for a rough estimate, divide the baud rate by 10, and that should be the maximum number of bytes going over the interface per second. For instance, 9600 baud would be 960 bytes per second, so if you're sending 256 bytes (0 to 255) per transmission, then you should limit yourself to transmitting 3 times per second, as 4 times (256) would exceed 960).
You could check the bytes remaining in the buffer to optimize your transfer rate, sending a new transmission when the remaining bytes in the buffer indicate there is room in the buffer to hold another transmission.
Code:
If (SerialPort1.WriteBufferSize - SerialPort1.BytesToWrite) > (tmp + 1) Then
SerialPort1.Write(DataOut, 0, tmp)
End If
I'm making a bit of an assumption here, as I've never tried the above code myself.
I've always gone the route of sending the buffers periodically at a rate that wouldn't exceed the bandwidth available for the baud rate.
-
Nov 9th, 2014, 09:19 AM
#4
Re: Sending huge Data buffer to Serial Port
Sending the entire 255 bytes at 9600 baud should not be an issue. Check your settings on both ends, and the cable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|