Results 1 to 12 of 12

Thread: Qextserial on debian linux and readyRead slot

  1. #1
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Qextserial on debian linux and readyRead slot

    Hi All,
    I would like to use Qextserial in debian linux with readyRead signal. There is no error on init, but it cannot send signal.
    Here is my settings:

    Qt Code:
    1. mSerialPort = new QextSerialPort("/dev/ttyUSB0", QextSerialPort::EventDriven);
    2. mSerialPort->setBaudRate(BAUD921600);
    3. mSerialPort->setDataBits(DATA_8);
    4. mSerialPort->setStopBits(STOP_1);
    5. mSerialPort->setParity(PAR_NONE);
    6. mSerialPort->setFlowControl(FLOW_OFF);
    7. mSerialPort->setQueryMode(QextSerialPort::EventDriven);
    8. mSerialPort->setRts(true);
    9. mSerialPort->setDtr(true);
    10.  
    11. QObject::connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(dataAvailable()));
    12. mSerialPort->open(QIODevice::ReadWrite);
    13. if (!mSerialPort->isOpen())
    14. log_exception(PacketDriverException, "cannot open %s", "/dev/ttyUSB0");
    To copy to clipboard, switch view to plain text mode 

    I read a post here

    http://www.qtcentre.org/threads/1562...th-readyRead()

    from 2008, it said I can' t use signal in linux
    Is it true?
    How can I set to use signals?

    thx a lot
    Zamek

  2. The following user says thank you to zamek42 for this useful post:

    ebirdseystew (18th December 2013)

  3. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qextserial on debian linux and readyRead slot

    Hi,

    This is a deprecated library. Use QtSerialPort instead that is developed by Qt team. It is a part of Qt 5 and also can be used on Qt 4 as a module.
    Òscar Llarch i Galán

  4. The following 2 users say thank you to ^NyAw^ for this useful post:

    ebirdseystew (18th December 2013)

  5. #3
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qextserial on debian linux and readyRead slot

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    This is a deprecated library. Use QtSerialPort instead that is developed by Qt team. It is a part of Qt 5 and also can be used on Qt 4 as a module.
    Thx for your response. I changed to QtSerialPort, but unfortunately it doesn't works
    QExtSerial can read but didn't send signal, QtSerial doesn't read in polling mode

    There is hardware which sends 80bytes of frames with 921600 8N1 no flow.
    Here is the code which I tried:
    Qt Code:
    1. mSerialPort.setPortName("/dev/ttyUSB0");
    2. mSerialPort.open(QIODevice::ReadWrite);
    3.  
    4. if (!mSerialPort.isOpen())
    5. log_exception(PacketDriverException, "cannot open %s", "/dev/ttyUSB0");
    6.  
    7. if (! (mSerialPort.setBaudRate(921600, QSerialPort::AllDirections) &&
    8. mSerialPort.setDataBits(QSerialPort::Data8) &&
    9. mSerialPort.setStopBits(QSerialPort::OneStop) &&
    10. mSerialPort.setParity(QSerialPort::NoParity) &&
    11. mSerialPort.setFlowControl(QSerialPort::NoFlowControl)))
    12. log_exception(PacketDriverException, "cannot set params of %s", "/dev/ttyUSB0");
    13.  
    14. mSerialPort.clearError();
    15. mSerialPort.flush();
    16. mSerialPort.clear(QSerialPort::AllDirections);
    17.  
    18. QObject::connect(&mSerialPort, SIGNAL(readyRead()), this, SLOT(dataAvailable()));
    19. QObject::connect(&mSerialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error()));
    20. QByteArray b = mSerialPort.readAll();
    21. std::cout<<b.size()<<std::endl;
    To copy to clipboard, switch view to plain text mode 

    There is no error and data comings to port. Size of b is 0.
    What did I do wrong?

    thx
    Zamek

  6. The following user says thank you to zamek42 for this useful post:

    ebirdseystew (18th December 2013)

  7. #4
    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: Qextserial on debian linux and readyRead slot

    Qt Code:
    1. YourClass::dataAvailable()
    2. {
    3. QByteArray b = mSerialPort.readAll();
    4. std::cout<<b.size()<<std::endl;
    5. }
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to kuzulis for this useful post:

    ebirdseystew (18th December 2013)

  9. #5
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qextserial on debian linux and readyRead slot

    Hi,

    Quote Originally Posted by kuzulis View Post
    Qt Code:
    1. YourClass::dataAvailable()
    2. {
    3. QByteArray b = mSerialPort.readAll();
    4. std::cout<<b.size()<<std::endl;
    5. }
    To copy to clipboard, switch view to plain text mode 
    Yes my dataAvailable is:
    Qt Code:
    1. void PacketDriver::dataAvailable()
    2. {
    3. if (mSerialPort.isReadable())
    4. readChar(mSerialPort.readAll());
    5. }
    6.  
    7. void PacketDriver::error()
    8. {
    9. QString err=mSerialPort.errorString();
    10. qDebug()<<err;
    11. mSerialPort.clearError();
    12. }
    To copy to clipboard, switch view to plain text mode 

    but I use readAll at end of open, because there is no signal. After I open the port and there are incoming data I have to read something with readAll.
    I started this with QExtSerial, which can read after open, but it cannot send signals. QtSerial cannot read after open and cannot send signal
    The hardware continuously send 80 bytes of frames at every 5 ms. Cutecom and gtkterm can read it.

  10. The following user says thank you to zamek42 for this useful post:

    ebirdseystew (18th December 2013)

  11. #6
    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: Qextserial on debian linux and readyRead slot

    So, the readyRead() signal does not emitted never? Can you test it with use the Terminal example from the QtSerialPort?

  12. The following user says thank you to kuzulis for this useful post:

    ebirdseystew (18th December 2013)

  13. #7
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qextserial on debian linux and readyRead slot

    Quote Originally Posted by kuzulis View Post
    So, the readyRead() signal does not emitted never? Can you test it with use the Terminal example from the QtSerialPort?
    Hi Kuzulis,

    creaderasync example works well. And I try to modify it, because it passing QSerialPort as a pointer in constructor, but I need to instantiate QSerialport in my constructor.
    There is the problem, because when I try to instantiate in constructor it doesn't works, but no error!

    Here is my test version:
    Qt Code:
    1. #include "serialportreader.h"
    2.  
    3. #include <QCoreApplication>
    4. #include <iostream>
    5.  
    6. QT_USE_NAMESPACE
    7.  
    8. #ifdef TEST
    9. SerialPortReader::SerialPortReader(QObject *parent)
    10. #else
    11. SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent)
    12. #endif
    13. : QObject(parent)
    14. #ifndef TEST
    15. , m_serialPort(serialPort)
    16. #endif
    17. , m_standardOutput(stdout)
    18. {
    19. #ifdef TEST
    20. m_serialPort = new QSerialPort();
    21.  
    22. if (!m_serialPort->open(QIODevice::ReadWrite))
    23. return;
    24.  
    25. if (!m_serialPort->setBaudRate(921600))
    26. return;
    27.  
    28. if (!m_serialPort->setDataBits(QSerialPort::Data8))
    29. return;
    30.  
    31. if (!m_serialPort->setParity(QSerialPort::NoParity))
    32. return;
    33.  
    34. if (!m_serialPort->setStopBits(QSerialPort::OneStop))
    35. return;
    36.  
    37. if (!m_serialPort->setFlowControl(QSerialPort::NoFlowControl))
    38. return;
    39. #endif
    40. connect(m_serialPort, SIGNAL(readyRead()), SLOT(handleReadyRead()));
    41. connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), SLOT(handleError(QSerialPort::SerialPortError)));
    42. }
    43.  
    44. SerialPortReader::~SerialPortReader()
    45. {
    46. }
    47.  
    48. void SerialPortReader::handleReadyRead()
    49. {
    50. m_readData = m_serialPort->readAll();
    51. std::cout<<"read, size:"<<m_readData.length()<<std::endl;
    52.  
    53. if (!m_timer.isActive())
    54. m_timer.start(5000);
    55. }
    56.  
    57. void SerialPortReader::handleTimeout()
    58. {
    59. if (m_readData.isEmpty()) {
    60. m_standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(m_serialPort->portName()) << endl;
    61. } else {
    62. m_standardOutput << QObject::tr("Data successfully received from port %1").arg(m_serialPort->portName()) << endl;
    63. m_standardOutput << m_readData << endl;
    64. }
    65.  
    66. }
    67.  
    68. void SerialPortReader::handleError(QSerialPort::SerialPortError serialPortError)
    69. {
    70. if (serialPortError == QSerialPort::ReadError) {
    71. m_standardOutput << QObject::tr("An I/O error occurred while reading the data from port %1, error: %2").arg(m_serialPort->portName()).arg(m_serialPort->errorString()) << endl;
    72. QCoreApplication::exit(1);
    73. }
    74. }
    To copy to clipboard, switch view to plain text mode 

    So, how can I instantiate QSerialport at constructor?

    thx
    Zamek

  14. The following user says thank you to zamek42 for this useful post:

    ebirdseystew (18th December 2013)

  15. #8
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qextserial on debian linux and readyRead slot

    Some advance:

    Is it true I need to use connect before I open the port? In terminal example does this.
    I tried to this, and in open I get an error: "No such file or direcory". I tried /dev/ttyUSB0 and ttyUSB0 too.

    Qt Code:
    1. PacketDriver::PacketDriver(const QString& cfgPrefix)
    2. : mFifo(cfgPrefix)
    3. {
    4. mSerialPort = new QSerialPort(this);
    5.  
    6. connect(mSerialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error()));
    7. connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    8.  
    9. mSerialPort->setPortName("/dev/ttyUSB0");
    10.  
    11. if (!mSerialPort->open(QIODevice::ReadWrite))
    12. log_exception(PacketDriverException, "cannot open /dev/ttyUSB0");
    13.  
    14. if (!mSerialPort->setBaudRate(921600))
    15. log_exception(PacketDriverException, "cannot set baud 921600");
    16.  
    17. if (!mSerialPort->setDataBits(QSerialPort::Data8))
    18. log_exception(PacketDriverException, "cannot set databits 8");
    19.  
    20. if (!mSerialPort->setParity(QSerialPort::NoParity))
    21. log_exception(PacketDriverException, "cannot set noparity");
    22.  
    23. if (!mSerialPort->setStopBits(QSerialPort::OneStop))
    24. log_exception(PacketDriverException, "cannot set one stopbits");
    25.  
    26. if (!mSerialPort->setFlowControl(QSerialPort::NoFlowControl))
    27. log_exception(PacketDriverException, "cannot set noflow");
    28. }
    29.  
    30. void PacketDriver::error()
    31. {
    32. QString err=mSerialPort->errorString();
    33. std::cout<<"Error:"<<err.toStdString()<<std::endl;
    34. }
    35.  
    36. void PacketDriver::onReadyRead()
    37. {
    38. std::cout<<"dataAvailable";
    39. if (mSerialPort->bytesAvailable()) {
    40. QByteArray bytes = mSerialPort->readAll();
    41. std::cout<<", bytes:"<<bytes.length()<<std::endl;
    42. readChar(bytes);
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 

    Could I debug into QtSerial?

    thx
    Zamek

  16. The following user says thank you to zamek42 for this useful post:

    ebirdseystew (18th December 2013)

  17. #9
    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: Qextserial on debian linux and readyRead slot

    Seems, you missed setup a port name, like:

    Qt Code:
    1. SerialPortReader::SerialPortReader(...)
    2. {
    3. ...
    4.  
    5. m_serialPort = new QSerialPort();
    6.  
    7. m_serialPort->setPortName("/dev/ttyUSB0"); // << :)
    8.  
    9. if (!m_serialPort->open(QIODevice::ReadWrite))
    10. return;
    11. ...
    12. }
    To copy to clipboard, switch view to plain text mode 

    UPD:

    Is it true I need to use connect before I open the port? In terminal example does this.
    Yes, you can... Has no difference do it before or after than open(). But if you do QObject::connect() after open(), don't forget after close() to call QObject::disconnect().

    I tried to this, and in open I get an error: "No such file or direcory". I tried /dev/ttyUSB0 and ttyUSB0 too.
    It because maybe really a port is not present.

    Could I debug into QtSerial?
    Yes, of course.
    Last edited by kuzulis; 15th December 2013 at 14:32.

  18. The following user says thank you to kuzulis for this useful post:

    ebirdseystew (18th December 2013)

  19. #10
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qextserial on debian linux and readyRead slot

    hi,

    Quote Originally Posted by kuzulis View Post
    Seems, you missed setup a port name, like:
    Yes thx, it was a little mistake, I already found it...

    It because maybe really a port is not present.
    No, the port continuously works, cutecom, gtkterm and qtserialport example terminal can use it and works well. There is a hw, which always sends 80 bytes of frames at every 5 ms.
    I used to check with lsof /dev/ttyUSB0 to opened locks. I am the member of dialout groups.

    What do I need to set for debugging into source of qtserialport?
    When I debug my program, I see the address of serialport, but I can't see the variables and I cannot step into a function.

    thx
    Zamek

  20. The following user says thank you to zamek42 for this useful post:

    ebirdseystew (18th December 2013)

  21. #11
    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: Qextserial on debian linux and readyRead slot

    What do I need to set for debugging into source of qtserialport?
    Build *.so library as "debug" target... Or directly connect the sources via "serialport-lib.pri" file (imho, *.pri - it is preffered and simple to do gebugging).

  22. The following user says thank you to kuzulis for this useful post:

    ebirdseystew (18th December 2013)

  23. #12
    Join Date
    Dec 2013
    Posts
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qextserial on debian linux and readyRead slot

    Hi Kuzulis,

    I found the problem. I wrote this test inside an infinite loop, so the main thread couldn't runs and there was no emitted event on received char.
    It was good lesson for me: the main thread cannot blocked!

    Many thx to you

    Zamek

Similar Threads

  1. Replies: 0
    Last Post: 1st August 2011, 14:06
  2. QtIOCompressor fix for Mac (Debian Linux?)
    By qdm in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2010, 03:17
  3. Replies: 1
    Last Post: 1st November 2007, 15:09
  4. Look and Feel on Debian Linux
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 10:11
  5. QT4 minimum requirements Debian GNU/Linux Sarge
    By Everall in forum Installation and Deployment
    Replies: 10
    Last Post: 21st February 2006, 13:21

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.