From afb7aaf374a309b808d39ffe825ac23fce91eccf Mon Sep 17 00:00:00 2001 From: edouard Date: Sun, 13 Mar 2011 13:03:11 +0000 Subject: [PATCH] OP-334 : reverted opening method in RawHID plugin, as the new pjrc_rawhid class does not play nice with the USBMonitor system in case several devices with the same PID/VID are present on the system (such as two PipX for example) git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3031 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/rawhid/rawhid.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/rawhid/rawhid.cpp b/ground/openpilotgcs/src/plugins/rawhid/rawhid.cpp index 44d1694b6..ce9c0c125 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/rawhid.cpp +++ b/ground/openpilotgcs/src/plugins/rawhid/rawhid.cpp @@ -299,27 +299,39 @@ RawHID::RawHID(const QString &deviceName) m_writeThread(NULL), m_mutex(NULL) { - int opened = 0; + m_mutex = new QMutex(QMutex::Recursive); // detect if the USB device is unplugged QObject::connect(&dev, SIGNAL(deviceUnplugged(int)), this, SLOT(onDeviceUnplugged(int))); - QList devices = USBMonitor::instance()->availableDevices(USBMonitor::idVendor_OpenPilot,-1,-1,USBMonitor::Running); + + int opened = dev.open(USB_MAX_DEVICES, USBMonitor::idVendor_OpenPilot, -1, USB_USAGE_PAGE, USB_USAGE); + for (int i =0; i< opened; i++) { + if (deviceName == dev.getserial(i)) + m_deviceNo = i; + else + dev.close(i); + } + + /* + // TODO: NOT WORKING FOR MULTIPLE DEVICES with the same PID! + QList devices = USBMonitor::instance()->availableDevices(USBMonitor::idVendor_OpenPilot,-1,-1,USBMonitor::Running); foreach( USBPortInfo device, devices) { if (deviceName == device.serialNumber) { opened = dev.open(1,device.vendorID, device.productID,USB_USAGE_PAGE,USB_USAGE); break; } } + */ //didn't find the device we are trying to open (shouldnt happen) - if (opened == 0) + if (opened < 0) { qDebug() << "Error: cannot open device " << deviceName; return; } - m_deviceNo = 0; + //m_deviceNo = 0; m_readThread = new RawHIDReadThread(this); m_writeThread = new RawHIDWriteThread(this);