Results 1 to 4 of 4

Thread: Sending huge Data buffer to Serial Port

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    1

    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

  2. #2
    Addicted Member
    Join Date
    Oct 2008
    Location
    USA
    Posts
    150

    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.
    Think.... Question.....

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width