GithubHelp home page GithubHelp logo

fpoussin / qtusb Goto Github PK

View Code? Open in Web Editor NEW
393.0 24.0 161.0 1.27 MB

A cross-platform USB Module for Qt.

License: GNU Lesser General Public License v3.0

Python 5.60% C++ 66.68% CSS 2.20% Batchfile 1.51% C 1.94% CMake 22.06%
qt usb libusb qt5

qtusb's Introduction

QtUsb GitHub version Total alerts Language grade: C/C++

GCC: Build Status
MSVC: Build status

A Cross-platform USB Module for Qt built around libusb-1.0 and libhidapi
Can be used as a library, or included directly into the project

Features

  • Bulk transfer
  • Interrupt transfer
  • Hotplug detection
  • Device enumeration and filtering
  • HID

Install library

Ubuntu (stable versions only)

sudo add-apt-repository ppa:fpoussin/ppa
sudo apt install libqt5usb5 libqt5usb5-dev

Windows
Check the releases page or appveyor build artifacts for binary archives

Build

Unix
You need libusb-1.0-0-dev, libhidapi-dev and pkg-config packages installed

mkdir build && cd build
qmake ..
make install

Alternatively build as static module (best for portability)

mkdir build && cd build
qmake CONFIG+=qtusb-static ..
make install

MSVC
You need the Windows SDKs to compile libusb
These are available from the Visual Studio Installer
The following script builds and deploys QtUsb into your Qt installation

build_msvc.bat 2017|2019 x64|x86 module|static QT_PATH
ie: build_msvc.bat 2017 x64 static C:\Qt\5.14.1\msvc2017_64

Qt Creator
The module can also be built normally within QT creator regardless of the platform.
All dependencies are built with qmake.

Using

Option 1: Using the module (static or dynamic)
You'll need to add the module to your project file:

qt += usb

Include headers:

#include <QUsbDevice>
#include <QUsbEndpoint>

Option 2: Importing the code in your project
This will tie your app to a specific Qt version as it uses private headers
You need to include the pri file into your qmake file:

include(QtUsb/src/usb/files.pri)

Include headers:

#include "qusbdevice.h"
#include "qusbendpoint.h"

Documentation

QCH files can be found with each release, they are also included in ubuntu packages.
You have to manually install them in Qt Creator on Windows.
Online documentation can be found here

Downloads

Ubuntu PPA Windows binaries are in the releases section.

qtusb's People

Contributors

codefruit avatar dakejahl avatar digitalaspirin avatar fpoussin avatar kwakobo avatar nerdoc avatar petrmanek avatar romviktor avatar treaves avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qtusb's Issues

Windows how to install Qt Usb module?

I have downloaded the file(qt5.12-usb-msvc-x86、qt5.12-usb-msvc-x64、qtusb-0.5.0-beta2.qch), but I don't know how to install it on Windows. Is there any specific instructions? Or download the decompression overlay directly into QT?

OSX: Project ERROR: Could not find hidapi-libusb using PKGCONFIG

Describe the bug
When doing a make, I get
Project ERROR: Could not find hidapi-libusb using PKGCONFIG
However hidapi and libusb are installed. There is no brew formula for hidapi-libusb

PLatform:

  • OS: MacOS
  • Version:Catalina

To Reproduce
Steps to reproduce the behavior:
git clone https://github.com/fpoussin/QtUsb.git
cd QtUsb
mkdir build && cd build
make

Expected behavior
It shoudl compile

Additional context
It fails with
Project MESSAGE: Build as Qt module
Project ERROR: Could not find hidapi-libusb using PKGCONFIG
make[1]: *** [sub-usb-make_first] Error 3
make: *** [sub-src-make_first] Error 2

dd

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

getAvailableDevices() returns empty list.

I'm presuming I'm doing something wrong, but why do I get no results from this:

#include <QCoreApplication>
#include <QUsb>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QUsbManager devices;

    QtUsb::FilterList list = devices.getPresentDevices();
    foreach(QtUsb::DeviceFilter filter, list)
    {
        qDebug("%04x:%04x", filter.vid, filter.pid);
    }

    return a.exec();
}

Crash in QUsb Constructor

Describe the bug
Created and ran a program that called the QUsb constructor. The program started consuming large amounts of memory and then crashed.

PLatform:

  • OS: Windows
  • Version: 10

To Reproduce
Steps to reproduce the behavior:

  1. Build the following program:
#include <QCoreApplication>
#include <QUsb>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    QUsb usb;
    return app.exec();
}
  1. Run the program.

Expected behavior
No crash.

Additional context
The problem appears to be in QUsb::devices() in the while loop that traverses the linked list of HID devices. In particular, this line in the while loop:

    cur_hid_dev = hid_devs->next;

should be this:

    cur_hid_dev = cur_hid_dev->next;

0.3.0: won't compile with Qt 5.8.0

g++ -c -m64 -pipe -O2 -fPIC -O2 -Wall -W -D_REENTRANT -fPIC -DQUSB_LIBRARY -DQLIBUSB -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/lib64/qt/mkspecs/linux-g++-64 -I. -I/usr/lib64/qt/include/QtCore -I/usr/lib64/qt/include -I. -Ishared -o shared/qbaseusb.o qbaseusb.cpp
g++ -c -m64 -pipe -O2 -fPIC -O2 -Wall -W -D_REENTRANT -fPIC -DQUSB_LIBRARY -DQLIBUSB -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/lib64/qt/mkspecs/linux-g++-64 -I. -I/usr/lib64/qt/include/QtCore -I/usr/lib64/qt/include -I. -Ishared -o shared/qusbmanager.o qusbmanager.cpp
In file included from qusbmanager.cpp:1:0:
qusbmanager.h: In function ‘int hotplugCallback(libusb_context*, libusb_device*, libusb_hotplug_event, void*)’:
qusbmanager.h:49:8: error: ‘void QUsbManager::deviceInserted(QtUsb::FilterList)’ is protected
   void deviceInserted(QtUsb::FilterList filters);
        ^
qusbmanager.cpp:28:45: error: within this context
     emit manager->deviceInserted(device_list);
                                             ^
In file included from qusbmanager.cpp:1:0:
qusbmanager.h:55:8: error: ‘void QUsbManager::deviceRemoved(QtUsb::FilterList)’ is protected
   void deviceRemoved(QtUsb::FilterList filters);
        ^
qusbmanager.cpp:36:46: error: within this context
       emit manager->deviceRemoved(device_list);
                                              ^
Makefile.Shared:224: recipe for target 'shared/qusbmanager.o' failed
make[2]: *** [shared/qusbmanager.o] Error 1

Weird behavior on Raspberry Pi4

Describe the bug
Only on Raspberry Pi (4), the inserted VID:PID is often wrong. The same code works fine on OSX, Linux (Ubuntu 18.04 x86). Usually the first insert after invoking the application is correct. What then happens is the VID:PID on removal is not the same. Subsequent inserts and removals are

PLatform:

To Reproduce
Steps to reproduce the behavior:
Compile as usual, monitor for insertion and removal events.
Insert a device of a known VID:PID. Remove device. Observe the right VID:PID was printed. Repeat several times.

Expected behavior
The proper VID:PID will always be shown.

Additional context
I'm using a iPhone with 05AC:12A8. Log is of me inserting the device into various ports of a hub. The iPhone's VIDPID is 05AC:12A8
insert.txt

enum bmRequestType values are not shifted properly

The values for bmRequestType enum are not properly initialized:

requestStandard = (0x00 < 5),
requestClass = (0x01 < 5),
requestVendor = (0x02 < 5),
requestReserved = (0x03 < 5),

The values should be:
requestStandard = (0x00 << 5),
requestClass = (0x01 << 5),
requestVendor = (0x02 << 5),
requestReserved = (0x03 << 5),

The SimpleBulkTransfer example would crash

I download and build the QtUSB using the Qt5.6, then modify the SimpleBulkTransfer example's VID and PID, and the write buffer data, when I run it, the program would crash:

***[ virtual qint32 QUsbDevice::write(const QByteArray*, quint32) ]***
Sending 5 bytes: "0A:FF:01:00:01"
ASSERT: "uint(i) < uint(size())" in file /home/XXX/.Qt5.6.0_install/5.6/gcc_64/include/QtCore/qbytearray.h, line 470

And I have detect that the following line in qlibusb.cpp file at read function is cause:
datastr.append(s.sprintf("%02X:", (uchar)buf->at(i)));
Which seems the ASSERT in QByteArray's at function is not passed:

inline char QByteArray::at(int i) const
{ Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }

My modification is (the vid and pid is faked):

diff --git a/examples/SimpleBulkTransfer/usbexample.cpp b/examples/SimpleBulkTransfer/usbexample.cpp
index f5d4ce5..26441cc 100644
--- a/examples/SimpleBulkTransfer/usbexample.cpp
+++ b/examples/SimpleBulkTransfer/usbexample.cpp
@@ -7,14 +7,36 @@
 UsbExample::UsbExample(QObject *parent) : QObject(parent) {
   this->setupDevice();
 
-  QByteArray send, recv;
+//  QByteArray send, recv;
+  QByteArray send;
 
-  send.append((char)0xAB);
+  //send.append((char)0xAB);
+  //0a ff 01 00 01
+  send.append((char)0x0a);
+  send.append((char)0xff);
+  send.append((char)0x01);
+  send.append((char)0x00);
+  send.append((char)0x01);
 
   if (this->openDevice()) {
     qDebug("Device open!");
+    qDebug() << "Send Data: " << send.toHex();
     this->write(&send);
+    //qDebug("Read Data");
+    //this->read(&recv);
+  }
+  while (1) {
+    //qDebug("Before Sleep");
+     QByteArray recv;
+    sleep(1);
     this->read(&recv);
+    //qDebug("Read data: " + recv.toStdString());
+    if(recv.size() != 0 || !recv.isEmpty()) {
+            //qDebug() << recv.toHex();
+            //qDebug() << "get data";
+    } else {
+       //qDebug() << "Empty";
+    }
   }
 }
 
@@ -29,15 +51,18 @@ void UsbExample::setupDevice() {
   mUsbDev->setDebug(true);
 
   //
-  mFilter.pid = 0x3748;
-  mFilter.vid = 0x0483;
+  mFilter.vid = 0xXXXX;
+  mFilter.pid = 0xYYYY;
 
 
   //
   mConfig.alternate = 0;
-  mConfig.config = 0;
-  mConfig.interface = 1;
-  mConfig.readEp = 0x81;
-  mConfig.writeEp = 0x02;
+  mConfig.config = 1;
+  mConfig.interface = 0;
+  //mConfig.readEp = 0x05; // 88 IN, 05 OUT
+  //mConfig.writeEp = 0x88;
+
+  mConfig.readEp = 0x88; // 88 IN, 05 OUT
+  mConfig.writeEp = 0x05;
 }
 
 bool UsbExample::openDevice() {
@@ -45,10 +70,14 @@ bool UsbExample::openDevice() {
 
   QtUsb::DeviceStatus ds;
   ds = mUsbManager.openDevice(mUsbDev, mFilter, mConfig);
+  //ds = mUsbManager.openDevice(mUsbDev, mFilter, NULL);
 
   if (ds == QtUsb::deviceOK) {
     // Device is open
+      qDebug("Open success");
     return true;
+  } else {
+      qDebug("Open Failed!!");
   }
   return false;
 }

Qt Creator build failure

Describe the bug
When trying to build QtUsb I receive an error about not being able to find libusb-1.0

21:57:17: Running steps for project QtUsb...
21:57:17: Configuration unchanged, skipping qmake step.
21:57:17: Starting: "/usr/bin/make" -j24
cd src/ && ( test -e Makefile || /Users/silverdr/sources/Qt5.9.9/5.9.9/clang_64/bin/qmake -o Makefile /Users/silverdr/sources/QtUsb/src/src.pro -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug ) && /Volumes/Scratch/Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile 
cd usb/ && ( test -e Makefile || /Users/silverdr/sources/Qt5.9.9/5.9.9/clang_64/bin/qmake -o Makefile /Users/silverdr/sources/QtUsb/src/usb/usb.pro -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug ) && /Volumes/Scratch/Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile 
Project MESSAGE: Build as Qt module for macos osx macx mac darwin unix posix
Project ERROR: Could not find libusb-1.0 using pkg-config
make[1]: *** [sub-usb-make_first] Error 3
make: *** [sub-src-make_first] Error 2
21:57:18: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project QtUsb (kit: Desktop Qt 5.9.9 clang 64bit)
When executing step "Make"
21:57:18: Elapsed time: 00:02.

Of course I have libusb-1.0 installed and pkg-config finds it easily when invoked from the command line:

silverdr$ pkg-config --cflags libusb-1.0
-I/usr/local/Cellar/libusb/1.0.24/include/libusb-1.0

PLatform:

  • OS: OS X
  • Version: 10.14.6

To Reproduce
Steps to reproduce the behavior:

  1. clone the repository afresh
  2. open QtUsb project in Qt Creator
  3. Invoke Build
  4. See error

Expected behavior
Project with all dependencies gets built

Additional context
I am new to Qt and Qt Creator so this might be a factor that I am missing something "obvious"

Multiple read/write endpoints

Currently, it looks like you can only have one read ep and one write ep with this code. What about when a device has multiple read or write endpoints?

It seems not working on debian buster

When I git clone the code and run:

mkdir build
cd build
qmake ..
make

The system told me fatal error: private/qobject_p.h: No such file or directory
And I re-edit the makefile under build/src/usb/Makefile, add the -I to include these path
But the system showed me more errors

Fix QDoc with Qt >= 5.11

Currently the documentation needs to be generated with Qt 5.10, as later versions do not find some headers

QUsbInfo missing?

I'm trying to compile an existing project on a new machine(Ubuntu, 20.04).
But Qt complains about a non-existing "QUsbInfo" include file.
And it is right, I also cannot find it.
I'm relatively sure that my project worked before and your documentation also tells about QUsbInfo(https://fpoussin.github.io/doxygen/qtusb/0.6.x/qusbinfo.html#details). But I cannot see it in ../src/usb.
Was it renamed, moved or has it disappeared?

Cheers,
Uwe

Question: how to use with CMake?

Hello,

I would like to use QtUsb in my project but don't know how to integrate it, since I use a CMake 3 build system (not qmake). Is there a recommended way to do it?

Cheers, Petr

Platform not supported

I tried the git and latest version, in both i get:

qmake 
make
cd src/ && /usr/lib64/qt4/bin/qmake /home/slavko/tmp/QtUsb-0.2.0/src/src.pro -o Makefile
Project ERROR: Platform not supported!
Makefile:33: recipe for target 'src/Makefile' failed
make: *** [src/Makefile] Error 2

I am on latest Funtoo Linux with gcc 5.3, please what i can do with this?

got fatal error: qusbglobal.h: No such file or directory

Ubuntu 20.04

did the following install from the Readme

sudo add-apt-repository ppa:fpoussin/ppa
sudo apt install libqt5usb5 libqt5usb5-dev

compile a file with include file <QusbDevice>

ex ListDevices from example directory

Unit Tests

There are currently no unit tests, this needs to change.

Problem to install library on ubuntu

Hi, sorry if this is trivial, but i cant solve some problem.
System:

  • ubuntu 20.04
  • ubuntu 18.04

when i am trying to install library with make install i am getting this error:

cd src/ && ( test -e Makefile || /usr/lib/qt5/bin/qmake -o Makefile /home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/src.pro ) && make -f Makefile install
make[1]: Entering directory '/home/chegewara/demos/esp32s2/qt_hid/QtUsb/build/src'
cd usb/ && ( test -e Makefile || /usr/lib/qt5/bin/qmake -o Makefile /home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/usb/usb.pro ) && make -f Makefile install
make[2]: Entering directory '/home/chegewara/demos/esp32s2/qt_hid/QtUsb/build/src/usb'
g++ -c -include .pch/Qt5Usb -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-deprecated-copy -Wno-redundant-move -Wno-format-overflow -Wno-init-list-lifetime -D_REENTRANT -fPIC -DQT_BUILD_USB_LIB -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_BUILD_USB_LIB -DQT_BUILDING_QT -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_CORE_LIB -I/home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/usb -I. -I/home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/usb -I../../include -I../../include/QtUsb -I../../include/QtUsb/0.6.2 -I../../include/QtUsb/0.6.2/QtUsb -isystem /usr/include/libusb-1.0 -isystem /usr/local/include/hidapi -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o .obj/qusbendpoint.o /home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/usb/qusbendpoint.cpp
In file included from /home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/usb/qusbendpoint.cpp:1:
/home/chegewara/demos/esp32s2/qt_hid/QtUsb/src/usb/qusbendpoint_p.h:6:10: fatal error: private/qiodevice_p.h: No such file or directory
    6 | #include <private/qiodevice_p.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:497: .obj/qusbendpoint.o] Error 1

im not sure, but most likely its caused by missing libqt5usb5 libqt5usb5-dev, which i cant install because of this error:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libqt5usb5 : Depends: hidapi-libusb0 but it is not installable
E: Unable to correct problems, you have held broken packages.

Thanks for help

I can not build in Windows

Describe the bug
I downloaded the git repo and downloaded hid, lusb repos as well. Loading the QtUSB pro file and compiling does not work

PLatform:
win 10

To Reproduce
Steps to reproduce the behavior:
download repo and other repos and try to compile on a fresh win 10 system

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -DQT_NO_LINKED_LIST -DQT_BUILD_USB_LIB -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_BUILD_USB_LIB -DQT_BUILDING_QT -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x040800 -DQT_DEPRECATED_WARNINGS_SINCE=0x060000 -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_CORE_LIB -IC:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb -I. -IC:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb -IC:\Users\SHERIF\Desktop\USBProject\QtUsb\src\deps\msvc -IC:\Users\SHERIF\Desktop\USBProject\QtUsb\libusb -IC:\Users\SHERIF\Desktop\USBProject\QtUsb\libusb\libusb -IC:\Users\SHERIF\Desktop\USBProject\QtUsb\hidapi -IC:/Users/SHERIF/Desktop/USBProject/QtUsb/src/usb/../../hidapi/hidapi -I....\include -I....\include\QtUsb -I....\include\QtUsb\0.7.0 -I....\include\QtUsb\0.7.0\QtUsb -Itmp -ID:\Qt\5.15.2\mingw81_64\include\QtCore\5.15.2 -ID:\Qt\5.15.2\mingw81_64\include\QtCore\5.15.2\QtCore -ID:\Qt\5.15.2\mingw81_64\include -ID:\Qt\5.15.2\mingw81_64\include\QtCore -I.moc\release -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.7.25-winx64\include -IC:\Utils\postgresql\pgsql\include -ID:\Qt\5.15.2\mingw81_64\mkspecs\win32-g++ -o .obj\release\qusbendpoint.o C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.cpp
In file included from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.cpp:2:
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb_p.h:13:12: fatal error: hidapi/hidapi.h: No such file or directory
#include <hidapi/hidapi.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
mingw32-make[3]: *** [Makefile.Release:584: .obj/release/qusb.o] Error 1
mingw32-make[3]: *** Waiting for unfinished jobs....
In file included from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbdevice.h:5,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.h:4,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint_p.h:4,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.cpp:1:
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:17:1: error: expected class-name before '{' token
{
^
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:18:5: error: 'Q_OBJECT' does not name a type
Q_OBJECT
^~~~~~~~
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:18:5: note: the macro 'Q_OBJECT' had not yet been defined
In file included from D:\Qt\5.15.2\mingw81_64\include/QtCore/qobject.h:46,
from D:\Qt\5.15.2\mingw81_64\include/QtCore/qiodevice.h:45,
from D:\Qt\5.15.2\mingw81_64\include/QtCore/qtextstream.h:43,
from D:\Qt\5.15.2\mingw81_64\include\QtCore/qdebug.h:49,
from D:\Qt\5.15.2\mingw81_64\include\QtCore/QDebug:1,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbdevice.h:7,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.h:4,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint_p.h:4,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.cpp:1:
D:\Qt\5.15.2\mingw81_64\include/QtCore/qobjectdefs.h:170: note: it was later defined here
#define Q_OBJECT \

In file included from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbdevice.h:5,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.h:4,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint_p.h:4,
from C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusbendpoint.cpp:1:
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:19:1: error: expected '}' before end of line
Q_DECLARE_PRIVATE(QUsb)
^ ~~~~~~~
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:17:1: note: to match this '{'
{
^
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:19:1: error: expected unqualified-id before end of line
Q_DECLARE_PRIVATE(QUsb)
^ ~~~~~~~
C:\Users\SHERIF\Desktop\USBProject\QtUsb\src\usb\qusb.h:19:1: error: expected declaration before end of line
mingw32-make[3]: *** [Makefile.Release:679: .obj/release/qusbendpoint.o] Error 1
mingw32-make[3]: Leaving directory 'C:/Users/SHERIF/Desktop/USBProject/build-QtUsb-Desktop_Qt_5_15_2_MinGW_64_bit-Release/src/usb'
mingw32-make[2]: *** [Makefile:45: release] Error 2
mingw32-make[2]: Leaving directory 'C:/Users/SHERIF/Desktop/USBProject/build-QtUsb-Desktop_Qt_5_15_2_MinGW_64_bit-Release/src/usb'
mingw32-make[1]: *** [Makefile:50: sub-usb-make_first] Error 2
mingw32-make[1]: Leaving directory 'C:/Users/SHERIF/Desktop/USBProject/build-QtUsb-Desktop_Qt_5_15_2_MinGW_64_bit-Release/src'
mingw32-make: *** [Makefile:52: sub-src-make_first] Error 2
22:47:13: The process "D:\Qt\Tools\mingw810_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project QtUsb (kit: Desktop Qt 5.15.2 MinGW 64-bit)
When executing step "Make"
22:47:13: Elapsed time: 00:16.

Avoid keyword 'interface' in QUsb::Config

Triggers compiler error C2236.

The offending classmember is here:
qusb.h:39

When including windows headers, the identifier name "interface" breaks the build. Swapping the classmember to 'usb_interface' to correct this issue, although I'm not sure that identifier is best or what that particular data member represents. (usb IF was an assumption)

quint8 usb_interface;

Platform:

  • OS: Windows
  • Version 10 19042

can't r get usb input data by QUsbEndpoint::interruptEndpoint

Describe the bug
A clear and concise description of what the bug is.

void UsbExample::setupDevice()
{
    /* There are 2 ways of identifying devices depending on the platform.
   * You can use both methods, only one will be taken into account.
   */

    printf("\nsetupDevice");

    m_usb_dev->setLogLevel(QUsbDevice::logDebug);

    //脉搏仪
    m_filter.pid = 0x2007;
    m_filter.vid = 0x5131;

    //
    m_config.alternate = 0;
    m_config.config = 1;
    m_config.interface = 0;

    //
    m_usb_dev->setId(m_filter);
    m_usb_dev->setConfig(m_config);

}
bool UsbExample::openDevice()
{
    qDebug("Opening");
    printf("\nOpening");

    if (m_usb_dev->open() == QUsbDevice::statusOK) {
        // Device is open
        return  this->openHandle();
    }
    return false;
}

bool UsbExample::openHandle()
{
    printf("\nOpening Handle");
    bool a = false, b = false;
    m_read_ep = new QUsbEndpoint(m_usb_dev, QUsbEndpoint::interruptEndpoint, USB_ENDPOINT_IN);
    //m_write_ep = new QUsbEndpoint(m_usb_dev, QUsbEndpoint::bulkEndpoint, USB_ENDPOINT_OUT);

    connect(m_read_ep, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    //connect(m_write_ep, SIGNAL(bytesWritten(qint64)), this, SLOT(onWriteComplete(qint64)));

    a = m_read_ep->open(QIODevice::ReadOnly);
    if (a) {
        m_read_ep->setPolling(true);
    }

//    b = m_write_ep->open(QIODevice::WriteOnly);

//    printf("\n===m_read_ep.type %d",m_read_ep->m_type);
    return a;
    //return a && b;
}

void UsbExample::onReadyRead()
{
    printf("\nonReadyRead");
    this->read(&m_recv);

   // this->write(&m_send);
}

PLatform:

  • OS: [win7]
  • Version [windows7]
    -qt 5.12.7 mingw64

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Closing and reopening device connection causes a deadlock

Hi,
It seems like closing and reopening the device causes a deadlock.

// Methods refering to "SimpleBulkExample". 

/* Say you want to close the device due to an error*/
closeDevice (); // returns success

/* Try to re-open device*/
openDevice (); // returns success

/* Write some data to the device.  Eventually, QUsbEndpointPrivate::writeUsb will be called which locks
m_buf_mutex, but cb_out is never executed to release it.*/
m_write_ep->write (...);

/* By calling again write again, it causes a deadlock */
m_write_ep->write (...);

hid_enumerate(0x0,0x0) vs QUsbInfo::devices()

Hello, i see you use libusb_get_device_list() in QUsbInfo::devices(). But this way i couldnt find my hid while hid_enumerate could. Is there an additonal way to find hid? Thanx

P.s. QHidDevice:open still works for this device while QUsbInfo::devices() could find it

QT modules usb not found

I'm using ubuntu 18.04, and want to try using Qt USB by adding repo to my ubuntu.
I'm succeed install in my pc using apt install libqt5usb5 and libqt5usb5-dev.

after install I want to try this module to my QT (qt5.9), unfortunately this error come up.
"Unknown module(s) in QT: usb"

How to check in my pc, is my module installed correctly?

Error during installation of the Qt USB library - returned code "0x2"

Describe the bug
A clear and concise description of what the bug is.-Okay, I'll try.

Friends, help me figure out the error that occurs when installing the Qt USB library . this error occurs when executing the command - " build_msvc2017.bat x64 G:\Qt\5.12.3\msvc2017_64". The Visual Studio 2019 command line is used . Here it is the error - ```
NMAKE : fatal error U1077: " C:\Program Files (x86)\Microsoft Visual Studio\2019\
Enterprise\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\cl.EXE": returned code
"0x2"

This error occurs several times.

**PLatform:**
 - OS: [e.g. Ubuntu]
 - Version [e.g. 18.04]

64 bit operating system,
Windows 7, Visual Studio  community 2019,
Separate component for VS:
NET Framework 4.6.1 Targeting Pack,
SDK  Framework  4.8,
IntelliCode,
Live Share,
C++ Clang for Windows,
C++ modules for build tools version 142 (x64 or x86 experimental),
Update for the distributed C++ component 2019,
SDK for universal CRT for Windows,
C++/CL support for build tools version 142 (14.24),
CMake C++ tools for Windows,
C++ Clang-cl for build tools version 142(x64/x86),
IncrediBuild - faster build times,
MSVC versions-140 C++VS 2015 build tools (versions 14.00),
MSVC versions-142 libraries C++VS 2019 for x68/x86, eliminating Spectre risks (version 14.24),
MSVC versions-142 C++VS 2019 build tools (versions 14.00), for x68  or x86,
Web deployment,
Tools related to connecting and publishing,
C++ profiling tools,
C++ Address Sanitizer,
IntelliTrace,
Jit debugger,
Package SDK for TypeScript 3.7,
Package SDK for Windows 10 (10.0.16299.0),
Package SDK for Windows 10 (10.0.17134.0),
Package SDK for Windows 10 (10.0.18362.0),
ATL library for the latest version of Build Tools v 142 (x86 or x64),
MFC library for the latest version of Build Tools v 142 (x86 or x64)
Package manager NuGet,
Code map,
Class designer,
Editor DGML?
Windows driver KIT.

Qt Creator 4.11.1.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

All the way, just in case:

Path=C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Common Files\Oracle\Java\jav
apath;C:\ProgramData\Oracle\Java\javapath;C:\Omega\SoapySDR_win64_install;C:\Program File
s\CMake\bin\;C:\Windows\System32;C:\Windows\SysWOW64\WindowsPowerShell\v1.0;C:\Omega\Soap
ySDR_win64_install\bin\;C:\Omega\CubicSDR_win64\x64\modules\;C:\Windows;C:\Program Files
(x86)\GnuWin32\bin;C:\SysGCC\mingw64\bin;C:\Program Files\PothosSDR\lib\SoapySDR\modules0
.8;G:\MATLAB\R2019b\runtime\win64;G:\MATLAB\R2019b\bin;G:\MATLAB\R2019b\polyspace\bin;C:\
Program Files\Git\cmd;C:\Program Files\bladeRF\x64;C:\Program Files\GTK2-Runtime Win64\bi
n;C:\boost_1_72_0;C:\Boost\boost_1_72_0\libs;C:\Program Files\bladeRF\matlab;G:\Premake;G
:G:\test\wxWidgets-3.1.3\include;G:\test\wxWidgets-3.1.3\lib;G:\test\wxWidgets\include;C:
\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\bi
n\Hostx64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Curr
ent\Bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC


**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.

Code snippets with errors.

This message appears several times- "The system cannot find the specified path."but it seemed to me that it does not affect the process, maybe I'm wrong.

`G:\QtUsb>build_msvc2017.bat x64 G:\Qt\5.12.3\msvc2017_64
The system cannot find the specified path.
Microsoft (R) Build Engine версии 16.4.0+e901037fe для .NET Framework
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

Build started 13.03.2020 12:48:20.
Проект "G:\QtUsb\libusb\msvc\libusb_static_2017.vcxproj" в узле 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsof
t\VC\v150\Microsoft.CppBuild.targets(402,5): warning MSB8038: Spectre risk elimination is enabled , but no Spectre libraries with eliminated risks were found.

`G:\Qt\5.12.3\msvc2017_64\include\QtCore\qglobal.h(45): fatal error C1083: Не уда
ется открыть файл включение: type_traits: No such file or directory,
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\
Enterprise\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\cl.EXE" : возвращенный код
"0x2"
Stop.
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\
Enterprise\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\nmake.exe" : returned code "0x2"
Stop.
NMAKE : fatal error U1077: cd :returned code "0x2"

`ils\postgresql\pgsql\include -IG:\Qt\5.12.3\msvc2017_64\mkspecs\win32-msvc -TP .
.\..\include\QtUsb\QtUsbDepends
QtUsbDepends
G:\Qt\5.12.3\msvc2017_64\include\QtCore\qglobal.h(45): fatal error C1083: Не уда
ется открыть файл включение: type_traits: No such file or directory,
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\
Enterprise\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\cl.EXE" : returned code
Stop.
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio\2019\
Enterprise\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\nmake.exe" : returned code "0x2"
Stop.
NMAKE : fatal error U1077: cd : returned code "0x2"
Stop.
NMAKE : fatal error U1077: cd : returned code "0x2"
Stop.

G:\QtUsb>`
Stop.
NMAKE : fatal error U1077: cd :returned code "0x2"
Stop.
The system cannot find the specified path."
`
I hope for your help. Sincerely Sergey
((I'm waiting for an answer like a bird of summer)))


add getReport(size_t length, int timeout_ms) and sendReport(const QByteArray &data)

Is your feature request related to a problem? Please describe.

int QHIDevice::sendReport(const QByteArray &data) {
    if (_device != nullptr) return -1;
    return hid_send_feature_report(_device,reinterpret_cast<const unsigned char*>(data.constData()),data.size());
}

void QHIDevice::getReport(size_t length, int timeout_ms) {
	if (_device == nullptr) return;
	_timeout.start(timeout_ms);
    expectData = length;
    recvBuf.clear();
    poll.start();
}

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Broken MSVC Compilation

Describe the bug
NMAKE : fatal error U1073: don't know how to make 'D:/Projects/Libraries/QtUsb/src/usb/../../libusb/libusb/os/poll_windows.c'

10:01:29: Running steps for project QtUsb... 10:01:29: Configuration unchanged, skipping qmake step. 10:01:29: Starting: "E:\Qt\Tools\QtCreator\bin\jom.exe" cd src\ && ( if not exist Makefile E:\Qt\5.14.2\msvc2017_64\bin\qmake.exe -o Makefile D:\Projects\Libraries\QtUsb\src\src.pro -spec win32-msvc "CONFIG+=qtquickcompiler" ) && E:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile cd usb\ && ( if not exist Makefile E:\Qt\5.14.2\msvc2017_64\bin\qmake.exe -o Makefile D:\Projects\Libraries\QtUsb\src\usb\usb.pro -spec win32-msvc "CONFIG+=qtquickcompiler" ) && E:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile E:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Release all Error: dependent 'D:\Projects\Libraries\QtUsb\src\usb\..\..\libusb\libusb\os\poll_windows.c' does not exist. jom: D:\Projects\Libraries\build-QtUsb-Desktop_Qt_5_14_2_MSVC2017_64bit-Release\src\usb\Makefile [release-all] Error 2 E:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug all Error: dependent 'D:\Projects\Libraries\QtUsb\src\usb\..\..\libusb\libusb\os\poll_windows.c' does not exist. jom: D:\Projects\Libraries\build-QtUsb-Desktop_Qt_5_14_2_MSVC2017_64bit-Release\src\usb\Makefile [debug-all] Error 2 jom: D:\Projects\Libraries\build-QtUsb-Desktop_Qt_5_14_2_MSVC2017_64bit-Release\src\Makefile [sub-usb-make_first] Error 2 jom: D:\Projects\Libraries\build-QtUsb-Desktop_Qt_5_14_2_MSVC2017_64bit-Release\Makefile [sub-src-make_first] Error 2 10:01:29: The process "E:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2. Error while building/deploying project QtUsb (kit: Desktop Qt 5.14.2 MSVC2017 64bit) When executing step "Make" 10:01:29: Elapsed time: 00:00.

PLatform:

  • OS: Windows
  • Version Qt 5.14.2 - W10 19042 - vs2017

To Reproduce
Steps to reproduce the behavior:

  1. Attempt to build in QtCreator or via script.

Notes
Latest windows release binaries only contain docs.

[Packages] .deb packages are missing headers

Currently the .deb packages are generated without their headers when using sbuild (or when built on launchpad)
This is not reproducible when building with debuild or manually.

Seems like this comes from qmake, we can see the headers are missing from the "install_targ_headers" Makefile target.

Map SerialPort::portName to QUsbDevice::Id::port for devices that use serial communication (like arduino)

Hey Fabien!

First off, thank you so much for this library - it's really well written and useful. I'd love a feature for this library. I'll just use an example to explain my feature request:

Say I have a USB hub with four identical devices connected to it:

|_
| port 1 | <-> COM3
| port 2 | <-> COM14
| port 3 | <-> COM15
| port 4 | <-> COM12
|________|

(These COM numbers will change depending on the order in which they're connected)

It would be awesome to know which SerialPort::portName corresponds to which QUsbDevice::Id::port.

As far as I can tell, this is non-trivial on Windows. On windows, Qt uses these registry entries to extract serial port names.

image

#include install issue when using downloaded zip

I don't know if this is an issue with QtUsb code or not, but when the master branch is downloaded as a zip, the headers fail to be be installed correctly.

The zip calls the dir QtUsb-master.zip, which on OSX extracts to QtUsb-master/
Then when compiling a dependent project the #includes for the QtUsb classes fail.

When using git clone to clone the repo on the same machine and a sibling directory, everything "just works".

Register QUsbDevice::DeviceStatus

Hello,
I think it will be rather better if QUsbDevice class registers QUsbDevice::DeviceStatus enum, using qRegisterMetaType() instead of having to do it at the application level when trying to connect statusChanged signal to handle a USB error.

qRegisterMetaType<QUsbDevice::DeviceStatus>("QUsbDevice::DeviceStatus"); // Needed so that the following connection does not fail at run time.
connect(m_usb_dev,&QUsbDevice::statusChanged,this,[](QUsbDevice::DeviceStatus status) {
    qDebug () << "USB ERROR: " << qint32(status) << " deal with it";
});

USB port and bus can be 0

if (id.bus == 0 && id.port == 0) // Ignore bus/port if both == 0

USB desc :port class subclass can be 0,so can not use that code :
//////////////////////////////////////////////////////////////////
if (id.bus == 0 && id.port == 0) // Ignore bus/port if both == 0
return i;
if ((id.bus && d->bus == id.bus) && (id.port && d->port == id.port)) // Take bus/port into account for filtering when set
return i;
///////////////////////////////////////////////////////////////////////////
to judge the device is the same to other device

it seems reverse between vid and pid

QUsbDevice::Id usb_id;
usb_id.pid = 0xABAB;
usb_id.vid = 0xCDCD;

m_usb_manager.addDevice(usb_id);

QUsbDevice::IdList list = m_usb_manager.getPresentDevices();

for(int i = 0 ; i < list.size() ; i++)
{
     qInfo("V:%04x:P:%04x", list.at(i).vid, list.at(i).pid);

// qDebug()<<"vid:"<<list.at(i).vid<<"pid:"<<list.at(i).pid;
}

//////////////////////////////////////////
usb_id.pid = 0xABAB;
usb_id.vid = 0xCDCD;

is correct pid and vid,but the code run can‘t find the usb device,but if

usb_id.pid = 0xCDCD;
usb_id.vid = 0xABAB;

that can get present deevcices

V0.2 not work on mac

Hello,

Thanks for your lib.

But the new version with qiousb contain a lot of errors and not work.

It s normal ?

How to use libusb in my project

Describe the bug

I saw on github that the QtUSB you made was developed based on libusb. I encountered some problems when using libusb to develop myself. I want to use libusb first and then use your QtUSB library. Could you please advise?

PLatform:

  • OS: windows 10 x64
  • Version QT 5.15

Doxygen -> Qdoc

Because it's much nicer to be able to use documentation from within QtCreator.

Packet loss

Hello, have you ever experienced the problem that the packet received is not covered by the next packet in time, resulting in packet loss

Android build

Hi,
will QtUsb work on Android to read generic HID USB device?

Are there any instruction how to build this library for crosscompiling on Windows host for Android armv7 device, Qt 5.11.2?

How to use on MacOS?

I was able to compile it by adding:

export CPLUS_INCLUDE_PATH=/usr/local/Cellar/libusb/1.0.23/include

Which is the location where Homebrew is installing libusb-1.0.

Then running the notifier example, inserting a iPhone 8 it says:

Starting...
Press CTRL+C to close.
hotplugCallback
Could not open new USB device: -4

This however works for s USB/Serial adapter that I have:

Starting...
Press CTRL+C to close.
hotplugCallback
devices inserted
V0403:P6001

But libusb can see it:

***[ void QUsbInfo::checkDevices() ]***
[ 6.056919] [00000307] libusb: debug [libusb_get_next_timeout] no URBs, no timeout!
[ 6.056930] [00000307] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 6.056936] [00000307] libusb: debug [handle_events] poll() 1 fds with timeout in 0ms
[ 6.056951] [00000307] libusb: debug [handle_events] poll() returned 0
[ 6.091505] [00002107] libusb: debug [darwin_get_cached_device] finding cached device for sessionID 0xaf9ad4d868ca
[ 6.091887] [00002107] libusb: debug [darwin_get_cached_device] parent sessionID: 0x12929ff34e64
[ 6.091896] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x1292d67c542e/0x14623200
[ 6.091900] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x1292acdb4fac/0x14624100
[ 6.091904] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x12929ff34e64/0x14623000
[ 6.091907] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x12929cdc224c/0x14624000
[ 6.091910] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x129299c751d9/0x14622000
[ 6.091914] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x129296ac88f6/0x14621000
[ 6.091917] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x12925cd603e2/0x14620000
[ 6.091920] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0xab7b75a8/0x14613000
[ 6.091924] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x9c3ad1ad/0x14640000
[ 6.091927] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x9aee0842/0x1212000
[ 6.091931] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x89ebe5d6/0x14610000
[ 6.091934] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x88eac505/0x1211000
[ 6.091937] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x7505644e/0x1210000
[ 6.091940] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x74352d40/0x14600000
[ 6.091943] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x6a20b1bd/0x14400000
[ 6.091946] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x653a4ce5/0x14300000
[ 6.091949] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x5ce5b7d6/0x200000
[ 6.091952] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x5523e666/0x1200000
[ 6.091955] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ad4d868ca/0x14623100 against cached device with sessionID/locationID 0x0/0x1000000
[ 6.091958] [00002107] libusb: debug [darwin_get_cached_device] caching new device with sessionID 0xaf9ad4d868ca
[ 6.092911] [00002107] libusb: debug [darwin_cache_device_descriptor] cached device descriptor:
[ 6.092920] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDescriptorType:    0x01
[ 6.092925] [00002107] libusb: debug [darwin_cache_device_descriptor]   bcdUSB:             0x0200
[ 6.092928] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDeviceClass:       0x00
[ 6.092930] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDeviceSubClass:    0x00
[ 6.092933] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDeviceProtocol:    0x00
[ 6.092935] [00002107] libusb: debug [darwin_cache_device_descriptor]   bMaxPacketSize0:    0x40
[ 6.092938] [00002107] libusb: debug [darwin_cache_device_descriptor]   idVendor:           0x05ac
[ 6.092941] [00002107] libusb: debug [darwin_cache_device_descriptor]   idProduct:          0x12a8
[ 6.092944] [00002107] libusb: debug [darwin_cache_device_descriptor]   bcdDevice:          0x1002
[ 6.092946] [00002107] libusb: debug [darwin_cache_device_descriptor]   iManufacturer:      0x01
[ 6.092948] [00002107] libusb: debug [darwin_cache_device_descriptor]   iProduct:           0x02
[ 6.092951] [00002107] libusb: debug [darwin_cache_device_descriptor]   iSerialNumber:      0x03
[ 6.092953] [00002107] libusb: debug [darwin_cache_device_descriptor]   bNumConfigurations: 0x04
***[ void QUsbInfo::checkDevices() ]***
[ 6.309304] [00000307] libusb: debug [libusb_get_next_timeout] no URBs, no timeout!
[ 6.309317] [00000307] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 6.309323] [00000307] libusb: debug [handle_events] poll() 1 fds with timeout in 0ms
[ 6.309339] [00000307] libusb: debug [handle_events] poll() returned 0
[ 6.348891] [00002107] libusb: debug [darwin_check_configuration] active config: 0, first config: 1
[ 6.348916] [00002107] libusb: debug [process_new_device] allocating new device in context 0x7fc262d05140 for with session 0xaf9ad4d868ca
[ 6.348930] [00002107] libusb: debug [process_new_device] found device with address 39 port = 1 parent = 0x7fc262c05930 at 0x7fc262f0db5a
[ 6.349057] [00002107] libusb: debug [darwin_devices_detached] notifying context 0x7fc262d05140 of device disconnect
[ 6.353405] [00002107] libusb: debug [darwin_get_cached_device] finding cached device for sessionID 0xaf9ae460629d
[ 6.353474] [00002107] libusb: debug [darwin_get_cached_device] parent sessionID: 0x12929ff34e64
[ 6.353479] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0xaf9ad4d868ca/0x14623100
[ 6.353482] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x1292d67c542e/0x14623200
[ 6.353485] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x1292acdb4fac/0x14624100
[ 6.353489] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x12929ff34e64/0x14623000
[ 6.353492] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x12929cdc224c/0x14624000
[ 6.353494] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x129299c751d9/0x14622000
[ 6.353497] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x129296ac88f6/0x14621000
[ 6.353499] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x12925cd603e2/0x14620000
[ 6.353502] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0xab7b75a8/0x14613000
[ 6.353504] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x9c3ad1ad/0x14640000
[ 6.353507] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x9aee0842/0x1212000
[ 6.353510] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x89ebe5d6/0x14610000
[ 6.353512] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x88eac505/0x1211000
[ 6.353515] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x7505644e/0x1210000
[ 6.353518] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x74352d40/0x14600000
[ 6.353520] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x6a20b1bd/0x14400000
[ 6.353523] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x653a4ce5/0x14300000
[ 6.353526] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x5ce5b7d6/0x200000
[ 6.353528] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x5523e666/0x1200000
[ 6.353531] [00002107] libusb: debug [darwin_get_cached_device] matching sessionID/locationID 0xaf9ae460629d/0x14623100 against cached device with sessionID/locationID 0x0/0x1000000
[ 6.353533] [00002107] libusb: debug [darwin_get_cached_device] caching new device with sessionID 0xaf9ae460629d
[ 6.354885] [00002107] libusb: debug [darwin_cache_device_descriptor] cached deçvice descriptor:
[ 6.354892] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDescriptorType:    0x01
[ 6.354895] [00002107] libusb: debug [darwin_cache_device_descriptor]   bcdUSB:             0x0200
[ 6.354896] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDeviceClass:       0x00
[ 6.354898] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDeviceSubClass:    0x00
[ 6.354900] [00002107] libusb: debug [darwin_cache_device_descriptor]   bDeviceProtocol:    0x00
[ 6.354901] [00002107] libusb: debug [darwin_cache_device_descriptor]   bMaxPacketSize0:    0x40
[ 6.354903] [00002107] libusb: debug [darwin_cache_device_descriptor]   idVendor:           0x05ac
[ 6.354904] [00002107] libusb: debug [darwin_cache_device_descriptor]   idProduct:          0x12a8
[ 6.354906] [00002107] libusb: debug [darwin_cache_device_descriptor]   bcdDevice:          0x1002
[ 6.354907] [00002107] libusb: debug [darwin_cache_device_descriptor]   iManufacturer:      0x01
[ 6.354909] [00002107] libusb: debug [darwin_cache_device_descriptor]   iProduct:           0x02
[ 6.354910] [00002107] libusb: debug [darwin_cache_device_descriptor]   iSerialNumber:      0x03
[ 6.354912] [00002107] libusb: debug [darwin_cache_device_descriptor]   bNumConfigurations: 0x05

Curiously, it seems that once it gets an error, it doesn't get any more events from any devices. So if I unplug my iPhone, then unplug my serial adapter, I don't see the serial adapter leave notification.

How to read or write file?

I want to read or write a text file with usb device.
The bluk example, I don't understand where is it send data to.

Or how to get a QFile from UsbDevice?

Linux crash: assertion failed in ~QUsbDevice()

Describe the bug
When a QUsbDevice is destroyed, a locked mutex remains behind which causes assertion failure that leads to a fatal crash.

Platform:

  • OS: Arch Linux x86_64
  • Version 5.12.3-arch1-1, latest QtUsb, libusb 1.0.24-2

To Reproduce

  1. Compile any example (e.g. SimpleBulkTransfer).
  2. Run the compiled binary on a Linux OS with pthread-enabled libusb (with an actual USB device attached).
  3. Observe a fatal crash due to assertion failure in usbi_mutex_destroy.

Expected behavior
The example's binary should terminate without error.

Additional context
I believe that this has been happening all along on Linux and any other POSIX platforms. According to this mailing list, version 1.0.24 of libusb (particularly this commit) introduced additional assertions which only revealed this behavior. In the same thread, the author claims to have solved the issue, providing the following explanation:

The issue is in my teardown code, which, by preventing usage of the libusb context during its teardown, is accidentally preventing the event thread from freeing the event lock.

With that in mind, I tried recompiling QtUsb with this line commented out, hoping that this would allow the internal event thread to finish handling all in-flight events before libusb_exit is called. While this modification indeed caused the thread in question to exit on its own (specifically here, it unfortunately had no effect on the bug.

Here is a log of the crash that was taken with QUsb::logDebugAll: crash.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.