Results 1 to 7 of 7

Thread: can't set serial port data bits

  1. #1
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default can't set serial port data bits

    Hi everyone,

    I had bit problem on setting up serial port parameters.
    Qt Code:
    1. port->setBaudRate(BAUD9600);
    2. port->setFlowControl(FLOW_OFF);
    3. port->setParity(PAR_NONE);
    4. port->setDataBits(DATA_8);
    5. port->setStopBits(STOP_1);
    6. port->setRts(true);
    7. port->setDtr(true);
    8. port->setTimeout(500);
    9.  
    10. if (port->open(QIODevice::ReadWrite))
    11. {
    12. qDebug()<<"Port Info";
    13. qDebug()<<"---------";
    14. qDebug()<<port->baudRate();
    15. qDebug()<<port->dataBits();
    16. qDebug()<<port->portName();
    17. qDebug()<<"---------";
    18. }
    To copy to clipboard, switch view to plain text mode 

    What I get back from dataBits() funtion is 3, not 8, what's wrong?

  2. #2
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can't set serial port data bits

    DATA_8 might be 3, silly me.

    But my problem is if port was set correctly, why can't it receive correct data?
    After I use VB application initialized the serial port, send out data correctly, then went back to this QT application, I can send and receive correctly.

    But if not using this VB application refresh the port, QT App won't run properly, has anyone met with problem before?

  3. #3
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't set serial port data bits

    yyiu002,

    Can you advise to use the library QSerialDevice. As an alternative QextSerialPort:

    http://qt-apps.org/content/show.php/...content=112039

    But version 0.2.0 is already out of date. The latest version is on the SVN here: fireforge.net

    But the site fireforge.net are no longer working .
    I will try to create a repository QSerialDevice today at: http://gitorious.org/

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't set serial port data bits

    DataBitsType retiurned by dataBits() is an enum. And 3 is DATA_8.
    Are You sure that all parameters are correct, ie. parity, stop bits.

  5. #5
    Join Date
    Oct 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: can't set serial port data bits

    are you using rts and dtr signals, if not set them false and make a try.

  6. #6
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can't set serial port data bits

    I also tried with qextserialport 's example project, event folder, it gives me the same thing, not working!
    Qt Code:
    1. QextSerialPort * port = new QextSerialPort("COM8", QextSerialPort::EventDriven);
    2. port->setBaudRate(BAUD9600);
    3. port->setFlowControl(FLOW_OFF);
    4. port->setParity(PAR_NONE);
    5. port->setDataBits(DATA_8);
    6. port->setStopBits(STOP_1);
    7. port->open(QIODevice::ReadWrite);
    8. if (!(port->lineStatus() & LS_DSR)) {
    9. out << "warning: device is not turned on" << endl;
    10. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can't set serial port data bits

    It works for me now, have to open the serial port first, then set parameters.

    Qt Code:
    1. port = new QextSerialPort(comPort, QextSerialPort::EventDriven);
    2. port->open(QIODevice::ReadWrite);
    3.  
    4. // qDebug()<<baudSel;
    5.  
    6. port->setBaudRate(baudSel);
    7. port->setDataBits(DATA_8);
    8. port->setParity(PAR_NONE);
    9. port->setStopBits(STOP_1);
    10. port->setFlowControl(FLOW_OFF);
    11. port->setTimeout(500);
    12. port->setRts(true);
    13. port->setDtr(true);
    To copy to clipboard, switch view to plain text mode 

    QextSerialPort seems work fine.

    will try QSerialPort later if having other problems and can't be resolved.

    Many thanks on everyone on helping me on this.

Similar Threads

  1. data from serial port
    By bhe in forum Newbie
    Replies: 4
    Last Post: 3rd May 2009, 10:19
  2. Replies: 9
    Last Post: 4th June 2008, 12:29
  3. serial port communiction
    By jagadish in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2007, 11:52
  4. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  5. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 02:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.