none
Maximum baud rate of the SerialPort

    質問

  • Hi all,

    I'm using Visual Studio C# 2005.  I try to communicate with a PDA, HP iPaq, through the serialport.

    After creating the SerialPort object, I fail to open it because "The maximum baud rate for the device is 65536.".

    My code looks like:

     

    using System.IO.Ports;

    ...

    SerialPort sp = new SerialPort("COM5", 115200);

    try

    {

        sp.Open();

    }

    catch(Exception e)

    {

        Console.WriteLine(e.ToString());

    }

    ...

     

    It seems that the serialport does not support anything with baudrate greater than 65536 (= 2^16 = 16bits interger).  However, I write a simple test program to test the serialport, and I can successfully open a serialport with baudrate = 9999600.

    I have no idea with this bug now, anyone can help me?  Thanks!!!

     

    2007年6月28日 18:12

回答

  • Thanks for replying!  I've fixed the bug yesterday and I will explain this here.

     

    Since the PDA does not have any real SerialPort, the COM port I'm using is actualy a virtual COM port.  The speed of virtual COM does not do anything.(http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=334306&SiteID=1)

     

    I tried to open the serialport with baudrate = 115200 and I failed to open it because of the encounted error message: "The maximum baud rate for the device is 65536."  So I just changed the value of baudrate to 57600 which is the biggest number under 65536.  I found that the data I received is the same as before.  This means the baudrate should not affect anything.  After that I found I made a mistake on the size of an array and that was all what I need to fix!  I had been mislead by the baudrate for a long time.

     

    When I move everything to the laptop, the baudrate does something.  Since the laptop is connected with a real COM port, the baudrate has to be exact same with the hardware.  So in this case, the baudrate is set back to 115200 and then everything works.

     

    I think the SerialPort library over .net environment supports baudrate up to 65536 only because we don't need to set the real baudrate for an virtual COM port.

    2007年7月5日 14:14

すべての返信

  • Hi Harrison Zhuo,

      Did you encounter an exception with error message:  "The maximum baud rate for the device is 65536.".

      So could you please show us the stack trace of the exception?

    Thanks!

    2007年7月4日 8:48
  • It is a problem with the serial port driver you use.  I'm guessing it is some kind of USB device, bugs in their drivers are common.  Try a driver upgrade.
    2007年7月4日 18:17
  • Thanks for replying!  I've fixed the bug yesterday and I will explain this here.

     

    Since the PDA does not have any real SerialPort, the COM port I'm using is actualy a virtual COM port.  The speed of virtual COM does not do anything.(http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=334306&SiteID=1)

     

    I tried to open the serialport with baudrate = 115200 and I failed to open it because of the encounted error message: "The maximum baud rate for the device is 65536."  So I just changed the value of baudrate to 57600 which is the biggest number under 65536.  I found that the data I received is the same as before.  This means the baudrate should not affect anything.  After that I found I made a mistake on the size of an array and that was all what I need to fix!  I had been mislead by the baudrate for a long time.

     

    When I move everything to the laptop, the baudrate does something.  Since the laptop is connected with a real COM port, the baudrate has to be exact same with the hardware.  So in this case, the baudrate is set back to 115200 and then everything works.

     

    I think the SerialPort library over .net environment supports baudrate up to 65536 only because we don't need to set the real baudrate for an virtual COM port.

    2007年7月5日 14:14
  • Hey! Harrison,

     

    I'm glad to hear that it has worked. Great job!

      Thank you for sharing your valuable solution with us here!

     

    I believe that many members will benefit from your experience.

     

    Cheer!Smile

    2007年7月6日 6:46
  • Hi all
    forgive my poor English. I am working on a system which have a usb-serial device.

    My code looks like:

    using System.IO.Ports;

    ...

    SerialPort sp= new SerialPort();

    sp.BaudRate = 9600;
    sp.DataBits = 8;
    sp.Parity = Parity.None;
    sp.StopBits = StopBits.One;
    sp.PortName = "COM8";
    sp.RtsEnable = true;

    sp.open();

    ...

    First time running my Application, all things work right. But when I restarted the Application, the follow message received.
    The maximum baud rate for the device is -5990584

    I changed BaudRate to 4800, recompile the program, no problem, restart the application error again with the same message above.
    I have tried several numbers of BaudRate. Got the same results.

    somebody have any idea please help.

    2008年6月18日 8:11
  • Ugh.  Take the card to the parking lot and back over it a few times with your car so it never bug you again.  Then get one from a more reputable manufacturer.
    Hans Passant.
    2008年6月18日 9:50
  • I totally agree with Nobugz, but before you buy yet another hopeless USB-serial converter with yet another buggy driver, consider a PCI card instead like e.g. the H-line from VSCOM with 16C950 UART http://www.vscom.de/1_1_13.htm . I am using such a card myself up to 921.6 kbit/s with no driver problems.

    Not only is USB a hopeless polled bus itself, but most USB-serial converters use the FT232xx chip family from Future Technology Devices Ltd., which among other things do not store the error and break bits together with the data like the 16Cx50 serial do. Two hopeless technologies on top of each other can only lead to problems.

    Everything should be made as simple as possible, but not simpler.
    2008年6月18日 14:56
  • Is this as true today as it was 5 years ago ?

    Can I open my (BlueTooth over USB) "serial port" at 115200 and send/receive at 921600 ?

    I'm getting this error

    System.ArgumentOutOfRangeException: The maximum baud rate for the device is 115200

    2012年10月23日 22:18