Results 1 to 5 of 5

Thread: Can I use QtSerialPort to detect if a serial device is connected/disconnected?

  1. #1
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can I use QtSerialPort to detect if a serial device is connected/disconnected?

    Hey!
    I'm writing code for a button that communicates through a serial port. I have used QtSerialPort which have been great. Now I want to see if I can make my program automatically detect if my device is connected/disconnected? I hope to use QtSerialPort but otherwise I open to other solutions.
    Thanks!

  2. #2
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Can I use QtSerialPort to detect if a serial device is connected/disconnected?

    I don't think so Qt provide support for device interaction. To interact with device use OS native api.

  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 I use QtSerialPort to detect if a serial device is connected/disconnected?

    For the serial port in general not possible to determine whether connected to it a device.

    Only if the device is special and uses additional lines such as RTS, DTR and so forth, that is, puts these lines in "High",
    then we can define the connected device by reading the state of these lines dtr(), rts().

    Also, you can determine whether the device is connected - to periodically send requests to it, and if it does not respond - it is not connected.

  4. #4
    Join Date
    Jul 2012
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can I use QtSerialPort to detect if a serial device is connected/disconnected?

    Thanks! Don't think it support those lines. It only got read and write pins and is very simple. I'll try the periodical requests. Thanks for quick reponse!


    Added after 52 minutes:


    I realized that I that the port I'm using (COM7) disappears from the availablePorts() list when my device is unplugged. Also a call to isValid() returns false. But know I just check every 10 seconds and if the device is replugged before I check COM7 is in the list a it is valid. This means that I have to send a request and see if there is a response. I was wondering if I instead could do something so that I get a warning at once when the device is unplugged? Can I somehow call a slot function?
    Last edited by Kammersgaard; 24th July 2012 at 09:16.

  5. #5
    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 I use QtSerialPort to detect if a serial device is connected/disconnected?

    You can take a code from previous "older" version of parent of this library:

    https://gitorious.org/qserialdevice/...viceenumerator

    from a class SerialDeviceEnumerator. Here was implemented a notification when plug/unplug/disable/enable action,
    with return a list of available devices.

    Or you can polling availablePorts() with msecs intervals.

    You decide what to choose.

Similar Threads

  1. Adding QtSerialPort as a library -
    By HSPalm in forum Newbie
    Replies: 14
    Last Post: 26th June 2014, 16:16
  2. Replies: 6
    Last Post: 24th February 2012, 11:17
  3. cannot build qtserialport
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2011, 05:56
  4. database disconnected !
    By tinysoft in forum Newbie
    Replies: 1
    Last Post: 4th May 2011, 00:46
  5. QTcpSocket - How do I know when it is disconnected ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 3rd April 2006, 21:05

Tags for this Thread

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.