Results 1 to 11 of 11

Thread: QextSerialPort question

  1. #1
    Join Date
    Mar 2012
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default QextSerialPort question

    Hello, I'm trying to establish a communication between a microprocessor and my Ubuntu PC.

    I'm using Qextserialport library. But some error occured I don't know why.

    I tested the portname and it's like that attached "ttyACM0"

    Qt Code:
    1. QextSerialPort *deneme = new QextSerialPort();
    2. deneme->setPortName("/dev/ttyACM0");
    3. deneme->setBaudRate(BAUD9600);
    4. deneme->setParity(PAR_NONE);
    5. deneme->setDataBits(DATA_8);
    6. deneme->setStopBits(STOP_1);
    7.  
    8. if ( !(deneme->open(QIODevice::ReadWrite)) )
    9. {
    10. qDebug("error"); }
    11. if(deneme->isOpen())
    12. {
    13. qDebug("opened");
    14. deneme->close();
    15. }
    To copy to clipboard, switch view to plain text mode 

    When I run it, It just waits and "error" occured. What I am missing you think?

    Thanks in advance
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 142 Times in 135 Posts

    Default Re: QextSerialPort question

    Possibly a permissions problem?

  3. #3
    Join Date
    Mar 2012
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: QextSerialPort question

    Probably. How should i overcome it?

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 142 Times in 135 Posts

    Default Re: QextSerialPort question

    I use QextSerialPort on my Debian box to communicate with a weather station console. Had to add my user account to the dialout group.
    $ ls -l /dev/ttyS0
    crw-rw---T 1 root dialout 4, 64 May 10 18:01 /dev/ttyS0
    sudo adduser user dialout

  5. #5
    Join Date
    Mar 2012
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Smile Re: QextSerialPort question

    onur@onur-pc:~$ ls -l /dev/ttyACM0
    crw-rw---- 1 root dialout 166, 0 2012-05-11 14:11 /dev/ttyACM0
    and then i try to run
    onur@onur-pc:~$ sudo adduser onur dialout
    the output is

    The user `onur' is already a member of `dialout'.
    sorry for the such noob questions.

  6. #6
    Join Date
    Feb 2008
    Posts
    491
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 142 Times in 135 Posts

    Default Re: QextSerialPort question

    Quote Originally Posted by sidenelen View Post
    sorry for the such noob questions.
    No prob, this is the newbie forum after all.

    Try your code without the "if" on the open statement:
    Qt Code:
    1. . . .
    2. deneme->open(QIODevice::ReadWrite)
    3. if(deneme->isOpen())
    4. {
    5. . . .
    To copy to clipboard, switch view to plain text mode 

    Edit:

    Obviously I'm stabbing in the dark with the above.

    Did your microprocessor docs specify the port settings you are using? Here are the settings that I use:
    Qt Code:
    1. port = new QextSerialPort("/dev/ttyS0");
    2. port->setBaudRate(BAUD19200);
    3. port->setFlowControl(FLOW_OFF);
    4. port->setParity(PAR_NONE);
    5. port->setDataBits(DATA_8);
    6. port->setStopBits(STOP_2);
    7. port->open(QIODevice::ReadWrite)
    To copy to clipboard, switch view to plain text mode 
    Last edited by norobro; 11th May 2012 at 23:41.

  7. #7
    Join Date
    Mar 2012
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: QextSerialPort question

    I've changed the code like that

    Qt Code:
    1. QextSerialPort *deneme = new QextSerialPort();
    2. deneme->open(QIODevice::ReadWrite);
    3. deneme->setQueryMode(QextSerialPort::EventDriven);
    4. deneme->setPortName("/dev/ttyACM0");
    5. deneme->setBaudRate(BAUD9600);
    6. deneme->setParity(PAR_NONE);
    7. deneme->setDataBits(DATA_8);
    8. deneme->setStopBits(STOP_1);
    9.  
    10. if (deneme->isOpen()) qDebug("connection established");
    11. else qDebug("failed to connect");
    12. if (deneme->bytesAvailable()>0) {
    13. qDebug("byte=",deneme->bytesAvailable());
    14. }
    15. else
    16. {
    17. qDebug("theres nothing");
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Now it always says "connection established", even if i write some wrong port name like "tty12334324".

    But bytesAvailable() returns "-1" when i'm trying to learn how many bytes are available to read.

    By the way, I'm sure some data coming from the microprocessor with parameters that i wrote. Cause i've try it with another desktop program which is reading data from the same microprocessor truly.

  8. #8
    Join Date
    Feb 2008
    Posts
    491
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 142 Times in 135 Posts

    Default Re: QextSerialPort question

    Do you not need to send data to your device to get a response?

    Try something like this:
    Qt Code:
    1. QString cmd("a command for your device");
    2. deneme->write(cmd.toAscii(), cmd.length());
    3. deneme->waitForReadyRead();
    4. qDebug() << "Bytes availible:" << deneme->bytesAvailible() << "data:" << deneme->readAll();
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Mar 2012
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: QextSerialPort question

    i tried it, still the same dunno wheres the missing.

  10. #10
    Join Date
    Feb 2008
    Posts
    491
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 142 Times in 135 Posts

    Default Re: QextSerialPort question

    Sorry I haven't been any help. Sending LF to my device wakes it up and it responds with CRLF, then you can start sending commands.

    You might try the QSerialDevice library. The author is a member of this site: thread

  11. The following user says thank you to norobro for this useful post:

    sidenelen (13th May 2012)

  12. #11
    Join Date
    Mar 2012
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: QextSerialPort question

    I don't know how but i finally got it! thank you so much for your patient help

Similar Threads

  1. New Qextserialport
    By pherthyl in forum Qt Programming
    Replies: 0
    Last Post: 20th August 2009, 02:09
  2. Newbie Question with Qextserialport.tar.gz
    By nomad in forum Qt-based Software
    Replies: 2
    Last Post: 13th July 2009, 14:32
  3. QExtSerialport question
    By bnilsson in forum Qt Programming
    Replies: 0
    Last Post: 6th June 2009, 23:29
  4. i have a question about using qextserialport
    By to_guliang in forum Qt Programming
    Replies: 14
    Last Post: 29th May 2008, 08:33
  5. Question about using the QextSerialPort~
    By coffeemorphism in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2007, 15:16

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
  •  
Qt is a trademark of The Qt Company.