Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Detecting QSerialPort disconnected in middle of program execution
Forum Updated to NodeBB v4.3 + New Features

Detecting QSerialPort disconnected in middle of program execution

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • KiraK Offline
    KiraK Offline
    Kira
    wrote on last edited by
    #1

    Hello everyone,

    I need to detect and create exception if somebody detach the serialport when the program is running.
    I went through number of solution but there any inbuild feature to do the same.

    J.HilkJ 1 Reply Last reply
    0
    • KiraK Kira

      Hello everyone,

      I need to detect and create exception if somebody detach the serialport when the program is running.
      I went through number of solution but there any inbuild feature to do the same.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @kira

      please define this a bit more

      detach the serialport


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      KiraK 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @kira

        please define this a bit more

        detach the serialport

        KiraK Offline
        KiraK Offline
        Kira
        wrote on last edited by
        #3

        @j-hilk : Sure.
        If suppose i have connected a serial device like ardunio to my COM Port and i fetching data when user clicks the button. But if my program is running and somebody removes the cable can i generate run time error acknowledgement that the cable is removed.
        Please let me know in case of any other clarification

        J.HilkJ 1 Reply Last reply
        0
        • KiraK Kira

          @j-hilk : Sure.
          If suppose i have connected a serial device like ardunio to my COM Port and i fetching data when user clicks the button. But if my program is running and somebody removes the cable can i generate run time error acknowledgement that the cable is removed.
          Please let me know in case of any other clarification

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @kira

          well, in that case, not really.

          You can potentially detect, when the OS looses the Port from the internal list, via for example QSerialPortInfo::availablePorts(), But you would have to regulary poll that.

          Besides that, there is
          https://doc.qt.io/qt-5/qserialport.html#errorOccurred

          that should fire, when you try to access the port and nothing answers


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          3
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            UPD: It is possible, the QSP::errorOccurred() signal can not be even triggered in some cases (e.g. it depends on a serial port driver, on OS and on a solar flashes). In some cases, the file descriptor of a device will not report about the errors at the I/O operations when a device is pulled out. I say about the USB/serial devices... There are only one way to do this (to watch for the USB devices attach/detach) - it is to create a separate 'watcher' class himself. If you use Windows, then you can watch for the appropriate system WM messages (Google will help you). On Linux you can use the udev monitor API, of course, if the udev is installed (Google will help you). On OSX you can use similar system-specific mechanism (Google will help you). Earlier there are a separate library, called QextSerialPort, where was a class QExtSerialPortWatcher (as I remember). You can try to take some code from there. So, no any good cross-platform solution to do that (that's why QSP has not any separate 'watcher' class).

            KiraK 1 Reply Last reply
            4
            • K kuzulis

              UPD: It is possible, the QSP::errorOccurred() signal can not be even triggered in some cases (e.g. it depends on a serial port driver, on OS and on a solar flashes). In some cases, the file descriptor of a device will not report about the errors at the I/O operations when a device is pulled out. I say about the USB/serial devices... There are only one way to do this (to watch for the USB devices attach/detach) - it is to create a separate 'watcher' class himself. If you use Windows, then you can watch for the appropriate system WM messages (Google will help you). On Linux you can use the udev monitor API, of course, if the udev is installed (Google will help you). On OSX you can use similar system-specific mechanism (Google will help you). Earlier there are a separate library, called QextSerialPort, where was a class QExtSerialPortWatcher (as I remember). You can try to take some code from there. So, no any good cross-platform solution to do that (that's why QSP has not any separate 'watcher' class).

              KiraK Offline
              KiraK Offline
              Kira
              wrote on last edited by
              #6

              @kuzulis :thanks

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved