diff --git a/openhantek/ChangeLog b/openhantek/ChangeLog index 795e9ee..9958d71 100644 --- a/openhantek/ChangeLog +++ b/openhantek/ChangeLog @@ -27,4 +27,9 @@ 2010-08-06 Oliver Haag * Bugfix: Mode shown below scope instead of coupling for the math channel -* Documentation updated \ No newline at end of file +* Documentation updated + +2010-08-16 Oliver Haag +* Completed libusb 0.1 downwards compatibility mode (env LIBUSB_VERSION=0) +* Bugfix: Grid of scopes drawn even if there aren't any graphs available +* Implemented basics of the XY-mode \ No newline at end of file diff --git a/openhantek/OpenHantek.pro b/openhantek/OpenHantek.pro index 9dc873a..2c1fc83 100644 --- a/openhantek/OpenHantek.pro +++ b/openhantek/OpenHantek.pro @@ -80,7 +80,7 @@ UI_DIR = build/ui MOC_DIR = build/moc # Include directory -QMAKE_CXXFLAGS += "-iquote src" +QMAKE_CXXFLAGS += "-iquote $${IN_PWD}/src" # libusb version LIBUSB_VERSION = $$(LIBUSB_VERSION) @@ -88,7 +88,6 @@ contains(LIBUSB_VERSION, 0):LIBS += -lusb else { LIBUSB_VERSION = 1 LIBS += -lusb-1.0 - DEFINES += LIBUSB_VERSION=1 } DEFINES += LIBUSB_VERSION=$${LIBUSB_VERSION} @@ -141,4 +140,4 @@ doxygen.commands = rm \ doxygen.depends = $${SOURCES} \ $${HEADERS} \ $${DOXYFILES} -QMAKE_EXTRA_UNIX_TARGETS += doxygen +QMAKE_EXTRA_TARGETS += doxygen diff --git a/openhantek/src/glgenerator.cpp b/openhantek/src/glgenerator.cpp index 737f37b..82fc292 100644 --- a/openhantek/src/glgenerator.cpp +++ b/openhantek/src/glgenerator.cpp @@ -59,9 +59,8 @@ void GlArray::setSize(unsigned long int size) { if(this->size == size) return; - if(this->data) { + if(this->data) delete[] this->data; - } if(size) this->data = new GLfloat[size]; else @@ -140,7 +139,7 @@ void GlGenerator::generateGraphs() { case Dso::GRAPHFORMAT_TY: // Add graphs for channels for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { - for(int channel = 0 ; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { // Check if this channel is used and available at the data analyzer if(((mode == Dso::CHANNELMODE_VOLTAGE) ? this->settings->scope.voltage[channel].used : this->settings->scope.spectrum[channel].used) && this->dataAnalyzer->data(channel)->samples.voltage.sample) { // Check if the sample count has changed @@ -188,6 +187,41 @@ void GlGenerator::generateGraphs() { break; case Dso::GRAPHFORMAT_XY: + for(int channel = 0; channel < this->settings->scope.voltage.count(); channel ++) { + // For even channel numbers check if this channel is used and this and the following channel are available at the data analyzer + if(channel % 2 == 0 && channel + 1 < this->settings->scope.voltage.count() && this->settings->scope.voltage[channel].used && this->dataAnalyzer->data(channel)->samples.voltage.sample && this->dataAnalyzer->data(channel + 1)->samples.voltage.sample) { + // Check if the sample count has changed + unsigned int neededSize = qMin(this->dataAnalyzer->data(channel)->samples.voltage.count, this->dataAnalyzer->data(channel + 1)->samples.voltage.count) * 2; + for(int index = 0; index < this->digitalPhosphorDepth; index++) { + if(this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->getSize() != neededSize) + this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->setSize(0); + } + + // Check if the array is allocated + if(!this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel].first()->data) + this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel].first()->setSize(neededSize); + + GLfloat *vaNewChannel = this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel].first()->data; + + // Fill vector array + unsigned int arrayPosition = 0; + unsigned int xChannel = channel; + unsigned int yChannel = channel + 1; + for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++) { + vaNewChannel[arrayPosition++] = this->dataAnalyzer->data(xChannel)->samples.voltage.sample[position] / this->settings->scope.voltage[xChannel].gain + this->settings->scope.voltage[xChannel].offset; + vaNewChannel[arrayPosition++] = this->dataAnalyzer->data(yChannel)->samples.voltage.sample[position] / this->settings->scope.voltage[yChannel].gain + this->settings->scope.voltage[yChannel].offset; + } + } + else { + // Delete all vector arrays + for(int index = 0; index < this->digitalPhosphorDepth; index++) + this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->setSize(0); + } + + // Delete all spectrum graphs + for(int index = 0; index < this->digitalPhosphorDepth; index++) + this->vaChannel[Dso::CHANNELMODE_SPECTRUM][channel][index]->setSize(0); + } break; } diff --git a/openhantek/src/glscope.cpp b/openhantek/src/glscope.cpp index 5f12855..da6799b 100644 --- a/openhantek/src/glscope.cpp +++ b/openhantek/src/glscope.cpp @@ -70,68 +70,84 @@ void GlScope::initializeGL() { /// \brief Draw the graphs and the grid. void GlScope::paintGL() { - if(!this->generator || !this->isVisible()) + if(!this->isVisible()) return; // Clear OpenGL buffer and configure settings glClear(GL_COLOR_BUFFER_BIT); glLineWidth(1); - if(this->settings->view.antialiasing) { - glEnable(GL_POINT_SMOOTH); - glEnable(GL_LINE_SMOOTH); - glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - } - - // Apply zoom settings via matrix transformation - if(this->zoomed) { - glPushMatrix(); - glScalef(DIVS_TIME / fabs(this->settings->scope.horizontal.marker[1] - this->settings->scope.horizontal.marker[0]), 1.0, 1.0); - glTranslatef(-(this->settings->scope.horizontal.marker[0] + this->settings->scope.horizontal.marker[1]) / 2, 0.0, 0.0); - } - // Values we need for the fading of the digital phosphor - double *fadingFactor = new double[this->generator->digitalPhosphorDepth]; - fadingFactor[0] = 100; - double fadingRatio = pow(10.0, 2.0 / this->generator->digitalPhosphorDepth); - for(int index = 1; index < this->generator->digitalPhosphorDepth; index++) - fadingFactor[index] = fadingFactor[index - 1] * fadingRatio; - - switch(this->settings->scope.horizontal.format) { - case Dso::GRAPHFORMAT_TY: { - // Real and virtual channels - for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { - if((mode == Dso::CHANNELMODE_VOLTAGE) ? this->settings->scope.voltage[channel].used : this->settings->scope.spectrum[channel].used) { + // Draw the graphs + if(this->generator && this->generator->digitalPhosphorDepth > 0) { + if(this->settings->view.antialiasing) { + glEnable(GL_POINT_SMOOTH); + glEnable(GL_LINE_SMOOTH); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + } + + // Apply zoom settings via matrix transformation + if(this->zoomed) { + glPushMatrix(); + glScalef(DIVS_TIME / fabs(this->settings->scope.horizontal.marker[1] - this->settings->scope.horizontal.marker[0]), 1.0, 1.0); + glTranslatef(-(this->settings->scope.horizontal.marker[0] + this->settings->scope.horizontal.marker[1]) / 2, 0.0, 0.0); + } + + // Values we need for the fading of the digital phosphor + double *fadingFactor = new double[this->generator->digitalPhosphorDepth]; + fadingFactor[0] = 100; + double fadingRatio = pow(10.0, 2.0 / this->generator->digitalPhosphorDepth); + for(int index = 1; index < this->generator->digitalPhosphorDepth; index++) + fadingFactor[index] = fadingFactor[index - 1] * fadingRatio; + + switch(this->settings->scope.horizontal.format) { + case Dso::GRAPHFORMAT_TY: + // Real and virtual channels + for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + if((mode == Dso::CHANNELMODE_VOLTAGE) ? this->settings->scope.voltage[channel].used : this->settings->scope.spectrum[channel].used) { + // Draw graph for all available depths + for(int index = this->generator->digitalPhosphorDepth - 1; index >= 0; index--) { + if(this->generator->vaChannel[mode][channel][index]->data) { + if(mode == Dso::CHANNELMODE_VOLTAGE) + this->qglColor(this->settings->view.color.screen.voltage[channel].darker(fadingFactor[index])); + else + this->qglColor(this->settings->view.color.screen.spectrum[channel].darker(fadingFactor[index])); + glVertexPointer(2, GL_FLOAT, 0, this->generator->vaChannel[mode][channel][index]->data); + glDrawArrays((this->settings->view.interpolation == INTERPOLATION_OFF) ? GL_POINTS : GL_LINE_STRIP, 0, this->generator->vaChannel[mode][channel][index]->getSize() / 2); + } + } + } + } + } + break; + + case Dso::GRAPHFORMAT_XY: + // Real and virtual channels + for(int channel = 0; channel < this->settings->scope.voltage.count() - 1; channel += 2) { + if(this->settings->scope.voltage[channel].used) { // Draw graph for all available depths for(int index = this->generator->digitalPhosphorDepth - 1; index >= 0; index--) { - if(this->generator->vaChannel[mode][channel][index]->data) { - if(mode == Dso::CHANNELMODE_VOLTAGE) - this->qglColor(this->settings->view.color.screen.voltage[channel].darker(fadingFactor[index])); - else - this->qglColor(this->settings->view.color.screen.spectrum[channel].darker(fadingFactor[index])); - glVertexPointer(2, GL_FLOAT, 0, this->generator->vaChannel[mode][channel][index]->data); - glDrawArrays((this->settings->view.interpolation == INTERPOLATION_OFF) ? GL_POINTS : GL_LINE_STRIP, 0, this->generator->vaChannel[mode][channel][index]->getSize() / 2); + if(this->generator->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->data) { + this->qglColor(this->settings->view.color.screen.voltage[channel].darker(fadingFactor[index])); + glVertexPointer(2, GL_FLOAT, 0, this->generator->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->data); + glDrawArrays((this->settings->view.interpolation == INTERPOLATION_OFF) ? GL_POINTS : GL_LINE_STRIP, 0, this->generator->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->getSize() / 2); } } } } - } - - delete[] fadingFactor; - - break; + break; } - case Dso::GRAPHFORMAT_XY: - break; + delete[] fadingFactor; + + glDisable(GL_POINT_SMOOTH); + glDisable(GL_LINE_SMOOTH); + + if(this->zoomed) + glPopMatrix(); } - glDisable(GL_POINT_SMOOTH); - glDisable(GL_LINE_SMOOTH); - - if(this->zoomed) - glPopMatrix(); - else { + if(!this->zoomed) { // Draw vertical lines at marker positions glEnable(GL_LINE_STIPPLE); this->qglColor(this->settings->view.color.screen.markers); diff --git a/openhantek/src/hantek/device.cpp b/openhantek/src/hantek/device.cpp index ca2c99f..ffe92f3 100644 --- a/openhantek/src/hantek/device.cpp +++ b/openhantek/src/hantek/device.cpp @@ -49,7 +49,13 @@ namespace Hantek { this->handle = 0; this->interface = -1; + +#if LIBUSB_VERSION == 0 + usb_init(); + this->error = LIBUSB_SUCCESS; +#else this->error = libusb_init(&(this->context)); +#endif } /// \brief Disconnects the device. @@ -61,120 +67,98 @@ namespace Hantek { /// \return A string with the result of the search. QString Device::search() { if(this->error) - return tr("Can't search for Hantek oscilloscopes: ").arg(Helper::libUsbErrorString(this->error)); + return tr("Can't search for Hantek oscilloscopes: %1").arg(Helper::libUsbErrorString(this->error)); + QString message; + QString deviceAddress; + int errorCode = LIBUSB_SUCCESS; #if LIBUSB_VERSION == 0 - usb_init(); - usb_find_busses(); - usb_find_devices(); - - struct usb_device *usbDSO = NULL; - for (struct usb_bus *usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) - { - for (struct usb_device *dev = usb_bus->devices; dev; dev = dev->next) - { - if (dev->descriptor.idVendor == deviceVendor) - { - for (int i = 0; deviceModelsList[i] != DSO_LAST; i++) - { - if (dev->descriptor.idProduct == deviceModelsList[i]) - { - usbDSO = dev; - deviceModel = dev->descriptor.idProduct; - qDebug("Hantek DSO model %4X found", deviceModel); - break; - } - } + errorCode = usb_find_busses(); + if(errorCode >= 0) + errorCode = usb_find_devices(); + if(errorCode < 0) + return tr("Failed to get device list: %3").arg(Helper::libUsbErrorString(errorCode)); + + struct usb_device *device = NULL; + + // Iterate through all usb devices + for(struct usb_bus *bus = usb_busses; bus; bus = bus->next) { + for(device = bus->devices; device; device = device->next) { + // Check VID and PID + if(device->descriptor.idVendor == HANTEK_VENDOR_ID) { + this->model = (Model) this->modelIds.indexOf(device->descriptor.idProduct); + if(this->model >= 0) + break; // Found a compatible device, ignore others } } + if(this->model >= 0) { + deviceAddress = QString("%1:%2").arg(bus->dirname).arg(device->filename); + break; // Found a compatible device, ignore other busses + } } - - if (usbDSO == NULL) - { - dsoIOMutex.unlock(); - qDebug("Hantek DSO not found"); - return -1; - } - - if ((deviceModel == DSO_5200) || (deviceModel == DSO_5200A)) + + /// \todo Use 9 bit data model of DSO-5200(A) + /* if ((deviceModel == DSO_5200) || (deviceModel == DSO_5200A)) { extraBitsData = true; qDebug("Using a 9-bita data model"); - } - - usbDSOHandle = ::usb_open(usbDSO); - if (usbDSOHandle == NULL) - { - dsoIOMutex.unlock(); - qDebug("Can't open USB device"); - return -2; - } + }*/ - struct usb_config_descriptor *usbConfig = usbDSO->config; - for (int i = 0; i < usbConfig->bNumInterfaces; i++) - { - struct usb_interface *usbInterface = &usbConfig->interface[i]; - if (usbInterface->num_altsetting < 1) - continue; - - struct usb_interface_descriptor *usbInterfaceDescr = &usbInterface->altsetting[0]; - if (usbInterfaceDescr->bInterfaceClass == USB_CLASS_VENDOR_SPEC - && usbInterfaceDescr->bInterfaceSubClass == 0 - && usbInterfaceDescr->bInterfaceProtocol == 0 - && usbInterfaceDescr->bNumEndpoints == 2) - { - if (::usb_claim_interface(usbDSOHandle, usbInterfaceDescr->bInterfaceNumber)) - { - if (::usb_close(usbDSOHandle)) - { - qDebug("Can't close USB handle"); - } - - dsoIOMutex.unlock(); - qDebug("Not able to claim USB interface"); - return -3; - } - - interfaceNumber = usbInterfaceDescr->bInterfaceNumber; - interfaceIsClaimed = true; - - for (int i = 0; i < usbInterfaceDescr->bNumEndpoints; i++) - { - usb_endpoint_descriptor *usbEndpointDescr = &usbInterfaceDescr->endpoint[i]; - switch (usbEndpointDescr->bEndpointAddress) - { - case 0x02: // EP OUT - epOutMaxPacketLen = usbEndpointDescr->wMaxPacketSize; - qDebug("EP OUT MaxPacketLen = %i", epOutMaxPacketLen); - break; - case 0x86: // EP IN - epInMaxPacketLen = usbEndpointDescr->wMaxPacketSize; - qDebug("EP IN MaxPacketLen = %i", epInMaxPacketLen); - break; - default: - qDebug("Unknown endpoint #%02X", usbEndpointDescr->bEndpointAddress); + if(this->model >= 0) { + // Open device + deviceAddress = QString("%1:%2").arg(device->bus->location, 3, 10, QLatin1Char('0')).arg(device->devnum, 3, 10, QLatin1Char('0')); + this->handle = usb_open(device); + if(this->handle) { + struct usb_config_descriptor *configDescriptor = device->config; + struct usb_interface *interface; + struct usb_interface_descriptor *interfaceDescriptor; + for(int interfaceIndex = 0; interfaceIndex < configDescriptor->bNumInterfaces; interfaceIndex++) { + interface = &configDescriptor->interface[interfaceIndex]; + if(interface->num_altsetting < 1) + continue; + + interfaceDescriptor = &interface->altsetting[0]; + if(interfaceDescriptor->bInterfaceClass == USB_CLASS_VENDOR_SPEC && interfaceDescriptor->bInterfaceSubClass == 0 && interfaceDescriptor->bInterfaceProtocol == 0 && interfaceDescriptor->bNumEndpoints == 2) { + // That's the interface we need, claim it + errorCode = usb_claim_interface(this->handle, interfaceDescriptor->bInterfaceNumber); + if(errorCode < 0) { + usb_close(this->handle); + this->handle = 0; + message = tr("Failed to claim interface %1 of device %2: %3").arg(QString::number(interfaceDescriptor->bInterfaceNumber), deviceAddress, Helper::libUsbErrorString(errorCode)); + } + else { + this->interface = interfaceDescriptor->bInterfaceNumber; + + // Check the maximum endpoint packet size + usb_endpoint_descriptor *endpointDescriptor; + this->outPacketLength = 0; + this->inPacketLength = 0; + for (int endpoint = 0; endpoint < interfaceDescriptor->bNumEndpoints; endpoint++) { + endpointDescriptor = &interfaceDescriptor->endpoint[endpoint]; + switch(endpointDescriptor->bEndpointAddress) { + case HANTEK_EP_OUT: + this->outPacketLength = endpointDescriptor->wMaxPacketSize; + break; + case HANTEK_EP_IN: + this->inPacketLength = endpointDescriptor->wMaxPacketSize; + break; + } + } + message = tr("Device found: Hantek %1 (%2)").arg(this->modelStrings[this->model], deviceAddress); + emit connected(); + } } } - - break; } + else + message = tr("Couldn't open device %1").arg(deviceAddress); } - - if (!interfaceIsClaimed) - { - qDebug("Can't find USB interface (Class:0xFF, SubClass:0, Protocol:0) with two endpoints"); - return -4; - } - - dsoIOMutex.unlock(); - - return 0; + else + message = tr("No Hantek oscilloscope found"); #else libusb_device **deviceList; libusb_device *device; - int errorCode = LIBUSB_SUCCESS; - QString deviceAddress; if(this->handle) libusb_close(this->handle); @@ -258,9 +242,9 @@ namespace Hantek { message = tr("No Hantek oscilloscope found"); libusb_free_device_list(deviceList, true); +#endif return message; -#endif } /// \brief Disconnect the device. @@ -269,11 +253,19 @@ namespace Hantek { return; // Release claimed interface +#if LIBUSB_VERSION == 0 + usb_release_interface(this->handle, this->interface); +#else libusb_release_interface(this->handle, this->interface); +#endif this->interface = -1; // Close device handle +#if LIBUSB_VERSION == 0 + usb_close(this->handle); +#else libusb_close(this->handle); +#endif this->handle = 0; emit disconnected(); @@ -324,20 +316,14 @@ namespace Hantek { return errorCode; #if LIBUSB_VERSION == 0 - int i, rv = -ETIMEDOUT; - for(i = 0; (rv == -ETIMEDOUT) && (i < attempts); i++) - { - rv = ::usb_bulk_write(usbDSOHandle, EP_BULK_OUT | USB_ENDPOINT_OUT, (char*)data, length, timeout); - } + errorCode = LIBUSB_ERROR_TIMEOUT; + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + errorCode = usb_bulk_write(this->handle, HANTEK_EP_OUT, (char *) data, length, HANTEK_TIMEOUT); - if (rv < 0) - { - qDebug("Usb write bulk returns error %i", rv); - qDebug("Error: %s", ::usb_strerror()); - return rv; - } + if(errorCode == LIBUSB_ERROR_NO_DEVICE) + this->disconnect(); - return 0; + return errorCode; #else return this->bulkTransfer(HANTEK_EP_OUT, data, length, attempts); #endif @@ -357,20 +343,14 @@ namespace Hantek { return errorCode; #if LIBUSB_VERSION == 0 - int i, rv = -ETIMEDOUT; - for(i = 0; (rv == -ETIMEDOUT) && (i < attempts); i++) - { - rv = ::usb_bulk_read(usbDSOHandle, EP_BULK_IN | USB_ENDPOINT_IN, (char*)data, length, timeout); - } + errorCode = LIBUSB_ERROR_TIMEOUT; + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + errorCode = usb_bulk_read(this->handle, HANTEK_EP_IN, (char *) data, length, HANTEK_TIMEOUT); - if (rv < 0) - { - qDebug("Usb read bulk returns error %i", rv); - qDebug("Error: %s", ::usb_strerror()); - return rv; - } + if(errorCode == LIBUSB_ERROR_NO_DEVICE) + this->disconnect(); - return 0; + return errorCode; #else return this->bulkTransfer(HANTEK_EP_IN, data, length, attempts); #endif @@ -412,8 +392,15 @@ namespace Hantek { errorCode = this->inPacketLength; int packet; - for(packet = 0; packet < packetCount && errorCode == this->inPacketLength; packet++) + for(packet = 0; packet < packetCount && errorCode == this->inPacketLength; packet++) { +#if LIBUSB_VERSION == 0 + errorCode = LIBUSB_ERROR_TIMEOUT; + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + errorCode = usb_bulk_read(this->handle, HANTEK_EP_IN, (char *) data + packet * this->inPacketLength, this->inPacketLength, HANTEK_TIMEOUT); +#else errorCode = this->bulkTransfer(HANTEK_EP_IN, data + packet * this->inPacketLength, this->inPacketLength, attempts); +#endif + } if(errorCode < 0) return errorCode; @@ -421,7 +408,6 @@ namespace Hantek { return (packet - 1) * this->inPacketLength + errorCode; } -#if LIBUSB_VERSION != 0 /// \brief Control transfer to the oscilloscope. /// \param type The request type, also sets the direction of the transfer. /// \param request The request field of the packet. @@ -437,13 +423,16 @@ namespace Hantek { int errorCode = LIBUSB_ERROR_TIMEOUT; for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) +#if LIBUSB_VERSION == 0 + errorCode = usb_control_msg(this->handle, type, request, value, index, (char *) data, length, HANTEK_TIMEOUT); +#else errorCode = libusb_control_transfer(this->handle, type, request, value, index, data, length, HANTEK_TIMEOUT); +#endif if(errorCode == LIBUSB_ERROR_NO_DEVICE) this->disconnect(); return errorCode; } -#endif /// \brief Control write to the oscilloscope. /// \param request The request field of the packet. @@ -457,25 +446,7 @@ namespace Hantek { if(!this->handle) return LIBUSB_ERROR_NO_DEVICE; -#if LIBUSB_VERSION == 0 - int i, rv = -ETIMEDOUT; - for(i = 0; (rv == -ETIMEDOUT) && (i < attempts); i++) - { - rv = ::usb_control_msg(usbDSOHandle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR, - request, value, index, (char*)data, length, timeout); - } - - if (rv < 0) - { - qDebug("Usb write control message %02X returns error %i", request, rv); - qDebug("Error: %s", ::usb_strerror()); - return rv; - } - - return 0; -#else return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, request, data, length, value, index,attempts); -#endif } /// \brief Control read to the oscilloscope. @@ -490,25 +461,7 @@ namespace Hantek { if(!this->handle) return LIBUSB_ERROR_NO_DEVICE; -#if LIBUSB_VERSION == 0 - int i, rv = -ETIMEDOUT; - for(i = 0; (rv == -ETIMEDOUT) && (i < attempts); i++) - { - rv = ::usb_control_msg(usbDSOHandle, USB_ENDPOINT_IN | USB_TYPE_VENDOR, - request, value, index, (char*)data, length, timeout); - } - - if (rv < 0) - { - qDebug("Usb read control message %02X returns error %i", request, rv); - qDebug("Error: %s", ::usb_strerror()); - return rv; - } - - return 0; -#else return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, request, data, length, value, index, attempts); -#endif } /// \brief Gets the speed of the connection. diff --git a/openhantek/src/hantek/device.h b/openhantek/src/hantek/device.h index 75181cd..2533879 100644 --- a/openhantek/src/hantek/device.h +++ b/openhantek/src/hantek/device.h @@ -70,9 +70,7 @@ namespace Hantek { int bulkCommand(Helper::DataArray *command, int attempts = HANTEK_ATTEMPTS_DEFAULT); int bulkReadMulti(unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS_DEFAULT); -#if LIBUSB_VERSION != 0 int controlTransfer(unsigned char type, unsigned char request, unsigned char *data, unsigned int length, int value, int index, int attempts = HANTEK_ATTEMPTS_DEFAULT); -#endif int controlWrite(unsigned char request, unsigned char *data, unsigned int length, int value = 0, int index = 0, int attempts = HANTEK_ATTEMPTS_DEFAULT); int controlRead(unsigned char request, unsigned char *data, unsigned int length, int value = 0, int index = 0, int attempts = HANTEK_ATTEMPTS_DEFAULT); @@ -91,8 +89,13 @@ namespace Hantek { libusb_context *context; ///< The usb context used for this device #endif Model model; ///< The model of the connected oscilloscope +#if LIBUSB_VERSION == 0 + usb_dev_handle *handle; ///< The USB handle for the oscilloscope + usb_device_descriptor descriptor; ///< The device descriptor of the oscilloscope +#else libusb_device_handle *handle; ///< The USB handle for the oscilloscope libusb_device_descriptor descriptor; ///< The device descriptor of the oscilloscope +#endif int interface; ///< The number of the claimed interface int error; ///< The libusb error, that happened on initialization int outPacketLength; ///< Packet length for the OUT endpoint diff --git a/openhantek/src/helper.h b/openhantek/src/helper.h index a97b219..e3197e1 100644 --- a/openhantek/src/helper.h +++ b/openhantek/src/helper.h @@ -27,9 +27,32 @@ #define HELPER_H +#include + #include +#if LIBUSB_VERSION == 0 +#define LIBUSB_SUCCESS 0 +#define LIBUSB_ERROR_IO -EIO +#define LIBUSB_ERROR_INVALID_PARAM -EINVAL +#define LIBUSB_ERROR_ACCESS -EACCES +#define LIBUSB_ERROR_NO_DEVICE -ENXIO +#define LIBUSB_ERROR_NOT_FOUND -ENOENT +#define LIBUSB_ERROR_BUSY -EBUSY +#define LIBUSB_ERROR_TIMEOUT -ETIMEDOUT +#define LIBUSB_ERROR_OVERFLOW -EFBIG +#define LIBUSB_ERROR_PIPE -EPIPE +#define LIBUSB_ERROR_INTERRUPTED -EINTR +#define LIBUSB_ERROR_NO_MEM -ENOMEM +#define LIBUSB_ERROR_NOT_SUPPORTED -ENOSYS + +#define LIBUSB_ENDPOINT_IN USB_ENDPOINT_IN +#define LIBUSB_ENDPOINT_OUT USB_ENDPOINT_OUT +#define LIBUSB_REQUEST_TYPE_VENDOR USB_TYPE_VENDOR +#endif + + namespace Helper { ////////////////////////////////////////////////////////////////////////////// /// \enum Unit helper.h