QSerialPort and baudrate settings



  • Under Windows 7, Qt 5.3 I have problems to set the baudrate of a QSerialPort:

    @QSerialPort *serial = new QSerialPort(this);
    serial->open(QIODevice::ReadWrite);
    serial->setBaudRate(115200);@

    setBaudRate returns true, but on some machines the baudrate is not actually set. I need to open/close the port with an external serial terminal (like RealTerm) with the desired baudrate in order to get it works.
    I tried to set the baudrate before opening the port with no chance.

    On other computers (same o.s., same Qt version, same USB/RS232 converter) it works fine.

    I cannot understand where is the mistake.
    Anyway, do you know any workaround to BE SURE the baudrate is really set? I'm puzzling over using Windows API or even launch a command-line terminal with QProcess....

    Thanks


  • Lifetime Qt Champion

    Hi,

    The only thing I can think of would be different driver version between computers. Did you by any chance look at that ?



  • Did you try swapping line 2. and 3. from the above?



  • Yes, I said:

    bq. I tried to set the baudrate before opening the port with no chance.


  • Lifetime Qt Champion

    @ franku, a QSerialPort needs to be opened first, then you do the settings.



  • According to the documentation, there's no need to open the port first:

    bq. If the setting is set before opening the port, the actual serial port setting is done automatically in the QSerialPort::open() method right after that the opening of the port succeeds.


  • Lifetime Qt Champion

    This page seem to have changed with time.

    Anyway thanks for pointing it out.



  • Thanks for the comment. I was working with QExtSerialPort sometime ago and I remember a similar problem before QSerialPort was introduced in a Qt distribution. So maybe I have mixed things up.
    You could also try to set the baudrate to i.e. 9600 first and then back to 150kBd again in order to change any underlying variable. But this still wouldn't explain why it works on some PCs and not on others.
    On the other hand it may help to debug down to the win32 code of QSerialPort on a system that works and on another that doesn't. Maybe this could help you discover why true ist returned from the software and nothing happens on the hardware.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.