Results 1 to 5 of 5

Thread: QSerialDevice never comes back if device unavailable

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QSerialDevice never comes back if device unavailable

    QSerialDevice is working just fine - reads and writes with no problems (thanks for all of your hard work Denis!), unless the h/w or s/w device on the other end of the serial port is unavailable (like the power is off to the device). Then when you try to write a command to it, it goes away and freezes the application. Not sure how to resolve this.

    I would like to give the user a QMessageBox with a warning when this happens.

    Thanks for any ideas.

  2. #2
    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: QSerialDevice never comes back if device unavailable

    If the words "device unavailable" you mean the situation when the remote device is powered off or there was a break of communication (cable break RS-232), there are two options:
    1. If the data exchange with the device you are using two wires: Rx and Tx - it is impossible to determine the availability of hardware or unavailability of the unit! For this purpose, use the software definition of the device: the device first sends a query and await a response from the device during a timeout. If no answer for the timeout - the device is not available.
    2. If the data exchange with the device you are using more than two wires (such as modems) - then we can determine the availability / unavailability of device (see the description of the standard and goal lines of port RTS, CTS.RI, etc.).
    For this case, sufficient to include hardware control "Hardware flow control" - and then the data exchange will occur on the standard. (if I'm not mistaken)

    hen when you try to write a command to it, it goes away and freezes the application.
    show the source code. likely you do something wrong doing.

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSerialDevice never comes back if device unavailable

    Thanks for your response.
    No doubt it is something I am doing wrong.
    Yes, the device is software, so no flow control.
    Here is the code and the debug output:

    Qt Code:
    1. PreferencesDialog::PreferencesDialog(QWidget *parent) :
    2. QDialog(parent),
    3. m_ui(new Ui::PreferencesDialog)
    4. {
    5. m_ui->setupUi(this);
    6.  
    7. //01202010 - Set up CAT preference values
    8. AbstractSerial *MyDevice = new AbstractSerial();
    9. // Getting Available Ports
    10. QStringList list = MyDevice->serialDevicesAvailable();
    11. list.sort();
    12. int len = list.size();
    13.  
    14. for (int i = 0; i < len; i ++) {
    15. m_ui->cbPort->addItem(list[i]);
    16. qDebug() << "Port is " << list[i]; // see debug output below
    17. }
    18. MyDevice->close();
    19. delete MyDevice;
    20.  
    21. // debug output
    22. Port is "COM1"
    23. Port is "COM2"
    24. Port is "COM3"
    25. Windows: NativeSerialEnginePrivate::nativeClose
    26. -> hd == INVALID_HANDLE_VALUE. Error!
    27. //
    28.  
    29.  
    30. // Get tx vfo
    31. cmd = "FT;";
    32. len = 8;
    33. ba = cmd.toAscii();
    34. QByteArray ra = readWrite(port, len, ba);
    35. ///
    36.  
    37.  
    38. QByteArray SerialComm::readWrite(QString port, int len, QByteArray ba) {
    39. AbstractSerial *MyDevice = new AbstractSerial();
    40. MyDevice->setDeviceName(port);
    41. if (MyDevice->open(QIODevice::ReadWrite | QIODevice::Unbuffered)) {
    42. qDebug() << "serial device status is " << MyDevice->deviceName();
    43.  
    44. qDebug() << "Writing the command";
    45. MyDevice->write(ba); // see debug output below
    46. qDebug() << "Command written";
    47.  
    48. //printDataToHex(ba);
    49. ba.clear();
    50. }
    51.  
    52. // debug output
    53. Windows: NativeSerialEnginePrivate::nativeOpen
    54. -> Trying to open device: "COM3"
    55.  
    56. Windows: NativeSerialEnginePrivate::nativeOpen
    57. -> Opened device: "COM3" succesfully. Ok!
    58.  
    59. serial device status is "COM3"
    60. Writing the command
    61. // no response now
    To copy to clipboard, switch view to plain text mode 

    Doesn't make any difference if I try to timeout the write(ba) command - it just never returns.

  4. #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: QSerialDevice never comes back if device unavailable

    Hmm .. All my works. I did rewrote the program from the /examples for reading and writing command "FT;" (see the archive as an attachment).
    I tried to write the command "FT;" simply in the serial port PC, which was not connected to anything. I have a "freeze" was not! Maybe you have a "curve" port driver or faulty port?
    Attached Files Attached Files

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

    waynew (24th January 2010)

  6. #5
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSerialDevice never comes back if device unavailable

    Thanks for your help Kuzulis. My application is trying to reach a software serial port through a virutal port programmed pair that are established with the program com0com.
    Perhaps that is where the problem lies. I will try a different program for making the virtual pair and see if that solves the problem.

    OK, I have switched from com0com to VSP Manager and the problem is cured.
    Last edited by waynew; 24th January 2010 at 13:51.

Similar Threads

  1. QSerialDevice
    By clinisbut in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 13:30
  2. new library QSerialDevice
    By kuzulis in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 05:42
  3. SQLite driver unavailable
    By kandalf in forum Installation and Deployment
    Replies: 5
    Last Post: 11th February 2009, 16:36
  4. Replies: 2
    Last Post: 5th February 2007, 17:42
  5. QSound Unavailable
    By superutsav in forum Newbie
    Replies: 2
    Last Post: 3rd February 2006, 16:38

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.