Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved how to create App for communicate with device through USB serial communication

    General and Desktop
    5
    17
    2123
    Loading More Posts
    • 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.
    • V
      vicksoccer last edited by

      Hello,
      I have to create an App in qt for communicate with my device through USB b connector on fedora. I have device VID = 0c54 and PID = 005f, so that I can send and receive command. I tried with libusb and hidapi but in both case my device port is not opening, Null return value at hid_open. I have used code from https://github.com/signal11/hidapi also install approx all required dependencies. It will be great if someone can help me.

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @vicksoccer last edited by

        @vicksoccer For serial communication there is https://doc.qt.io/qt-5/qserialport.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 2
        • V
          vicksoccer last edited by

          thanks for reply!!

          USB Communication Device Class (CDC) - Abstract Control Model (ACM) is possible with qserialport on linux machine?? If yes can anyone share example..

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @vicksoccer last edited by

            @vicksoccer The documentation page I linked above contains a link to serial port examples.
            Does this device behave like a serial port?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 3
            • K
              kuzulis Qt Champions 2020 last edited by kuzulis

              USB Communication Device Class (CDC) - Abstract Control Model (ACM) is possible with qserialport on linux machine??

              Yes

              V 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion last edited by

                Hi
                Try the terminal example as it as dialog to setup comport and
                makes it easy to check out.
                Its available directly in Creator
                alt text

                1 Reply Last reply Reply Quote 4
                • V
                  vicksoccer @kuzulis last edited by vicksoccer

                  @kuzulis Thanks for your support!!
                  My device can be connected with USB B connector and RS232 both.
                  In device datasheet mention information of baudrate,partiy,databits etc only under RS232 section and under USB section mention only -

                  • USB version - USB 2.0 (480Mbps)
                  • Device class - Communication device class (CDC)
                  • Subclass -Abstract control mode (ACM)

                  I need to connect with USB only So trying with qSerialport.
                  detecting port by using QserialPortinfo done, it is tyACM0 but serialport open is getting failed.
                  baudrate, parity, databits is not mentioned for usb connection so I am confused, failure is because of this. Tried with other possible combinations also still not helping it.
                  Anything other need to do for communicate with cdc-acm device??

                  K 1 Reply Last reply Reply Quote 0
                  • K
                    kuzulis Qt Champions 2020 @vicksoccer last edited by

                    @vicksoccer , are you sure that you have a right permissions to open the ttyACM device? You can search required info in google. What is an error code?

                    V 1 Reply Last reply Reply Quote 1
                    • V
                      vicksoccer @kuzulis last edited by

                      @kuzulis
                      getting segmentation fault error in first line of qserialport code..

                      usb->setPortName(port);
                      usb->setBaudRate(QSerialPort::Baud9600);
                      usb->setDataBits(QSerialPort::Data8);
                      usb->setParity(QSerialPort::EvenParity);
                      usb->setStopBits(QSerialPort::OneStop);
                      usb->setFlowControl(QSerialPort::NoFlowControl);
                      if (usb->open(QIODevice::ReadWrite)) {
                      qDebug() << "Port open success!!";
                      } else {
                      qDebug() << "Port open failed!!";
                      }
                      nothing is happened with qserialport only port detection is succeed. I Dont know why, search on google also..

                      1 Reply Last reply Reply Quote 0
                      • V
                        vicksoccer last edited by

                        Thanks all for your kind support!!!
                        Problem solved.. Its done with qserialport itself,
                        Now my device port is opened need to work on send commands..

                        mrjj 1 Reply Last reply Reply Quote 0
                        • mrjj
                          mrjj Lifetime Qt Champion @vicksoccer last edited by

                          @vicksoccer

                          Hi
                          If possible, could you tell how you made the
                          segmentation fault error go away?
                          What was the issue and fix.

                          V 1 Reply Last reply Reply Quote 1
                          • V
                            vicksoccer @mrjj last edited by vicksoccer

                            @mrjj
                            I think fault is due to initialization of port is not proper.
                            this work for me for setting available device port and open it.

                            QSerialPort usb = new QSerialPort(port);
                            usb->setBaudRate(QSerialPort::Baud9600);
                            usb->setDataBits(QSerialPort::Data8);
                            usb->setParity(QSerialPort::EvenParity);
                            usb->setStopBits(QSerialPort::OneStop);
                            usb->setFlowControl(QSerialPort::NoFlowControl);
                            if (usb->open(QIODevice::ReadWrite)) {
                            qDebug() << "Port open success!!";
                            } else {
                            qDebug() << "Port open failed!! + usb->errorString()";
                            }

                            mrjj 1 Reply Last reply Reply Quote 0
                            • mrjj
                              mrjj Lifetime Qt Champion @vicksoccer last edited by

                              Hi
                              So you added the line
                              QSerialPort *usb = new QSerialPort(port);

                              and it then worked or something else ?

                              V 1 Reply Last reply Reply Quote 0
                              • V
                                vicksoccer @mrjj last edited by

                                @mrjj
                                Yes I have added this line only and its worked for me..

                                jsulm 1 Reply Last reply Reply Quote 0
                                • jsulm
                                  jsulm Lifetime Qt Champion @vicksoccer last edited by

                                  @vicksoccer Keep in mind that if you defined this "usb" variable somewhere else you're creating a new one with same name now.
                                  If you already have one then do it like this:

                                  usb = new QSerialPort(port);
                                  

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  V 1 Reply Last reply Reply Quote 1
                                  • V
                                    vicksoccer @jsulm last edited by

                                    @jsulm
                                    Yes,Sure :)
                                    Thanks

                                    1 Reply Last reply Reply Quote 0
                                    • S
                                      sammy_49ers last edited by

                                      I thought we are talking about HID devices ?

                                      Whatever, if you need driver support for USB HID devices take look at www.hidxplat.com.

                                      Thanks sammy

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post