how to create App for communicate with device through USB serial communication
-
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. -
@vicksoccer For serial communication there is https://doc.qt.io/qt-5/qserialport.html
-
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..
-
@vicksoccer The documentation page I linked above contains a link to serial port examples.
Does this device behave like a serial port? -
USB Communication Device Class (CDC) - Abstract Control Model (ACM) is possible with qserialport on linux machine??
Yes
-
Hi
Try the terminal example as it as dialog to setup comport and
makes it easy to check out.
Its available directly in Creator
-
@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?? -
@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?
-
@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.. -
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.. -
Hi
If possible, could you tell how you made the
segmentation fault error go away?
What was the issue and fix. -
@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()";
} -
Hi
So you added the line
QSerialPort *usb = new QSerialPort(port);and it then worked or something else ?
-
@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);
-
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