From 538a5279ac5f73cdbc65baabd40d507dbc6ceaa3 Mon Sep 17 00:00:00 2001 From: schlaepfer Date: Wed, 10 May 2006 14:43:34 +0000 Subject: [PATCH] - retrieve string descriptors git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@151 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c --- java/src/ch/ntb/usb/usbView/UsbTreeModel.java | 67 +++++++++++++++++++ java/src/ch/ntb/usb/usbView/UsbView.java | 2 - 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/java/src/ch/ntb/usb/usbView/UsbTreeModel.java b/java/src/ch/ntb/usb/usbView/UsbTreeModel.java index a9b5295..09372f8 100644 --- a/java/src/ch/ntb/usb/usbView/UsbTreeModel.java +++ b/java/src/ch/ntb/usb/usbView/UsbTreeModel.java @@ -267,6 +267,37 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener { sb.append("\textralen: 0x" + Integer.toHexString(confDesc.extralen) + "\n"); sb.append("\textra: " + confDesc.extra + "\n"); + // get device handle to retrieve string descriptors + Usb_Bus bus = rootBus; + while (bus != null) { + Usb_Device dev = bus.devices; + while (dev != null) { + Usb_Config_Descriptor[] tmpConfDesc = dev.config; + for (int i = 0; i < tmpConfDesc.length; i++) { + if ((tmpConfDesc.equals(confDesc)) + && (confDesc.iConfiguration > 0)) { + int handle = LibusbWin.usb_open(dev); + sb.append("\nString descriptors\n"); + if (handle <= 0) { + sb.append("\terror opening the device\n"); + break; + } + String configuration = LibusbWin + .usb_get_string_simple(handle, + confDesc.iConfiguration); + if (configuration == null) + configuration = "unable to fetch configuration string"; + sb.append("\tiConfiguration: " + configuration + + "\n"); + + LibusbWin.usb_close(handle); + + } + } + dev = dev.next; + } + bus = bus.next; + } textArea.setText(sb.toString()); } else if (component instanceof Usb_Interface) { Usb_Interface int_ = (Usb_Interface) component; @@ -302,6 +333,42 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener { sb.append("\textralen: 0x" + Integer.toHexString(intDesc.extralen) + "\n"); sb.append("\textra: " + intDesc.extra + "\n"); + // get device handle to retrieve string descriptors + Usb_Bus bus = rootBus; + while (bus != null) { + Usb_Device dev = bus.devices; + while (dev != null) { + Usb_Config_Descriptor[] confDescs = dev.config; + for (int i = 0; i < confDescs.length; i++) { + Usb_Interface[] ints = confDescs[i].interface_; + for (int j = 0; j < ints.length; j++) { + Usb_Interface_Descriptor[] tmpIntDescs = ints[j].altsetting; + for (int k = 0; k < ints.length; k++) { + if (tmpIntDescs[i].equals(intDesc) + && (intDesc.iInterface > 0)) { + int handle = LibusbWin.usb_open(dev); + sb.append("\nString descriptors\n"); + if (handle <= 0) { + sb + .append("\terror opening the device\n"); + break; + } + String interface_ = LibusbWin + .usb_get_string_simple(handle, + intDesc.iInterface); + if (interface_ == null) + interface_ = "unable to fetch interface string"; + sb.append("\tiInterface: " + interface_ + + "\n"); + LibusbWin.usb_close(handle); + } + } + } + } + dev = dev.next; + } + bus = bus.next; + } textArea.setText(sb.toString()); } else if (component instanceof Usb_Endpoint_Descriptor) { Usb_Endpoint_Descriptor epDesc = (Usb_Endpoint_Descriptor) component; diff --git a/java/src/ch/ntb/usb/usbView/UsbView.java b/java/src/ch/ntb/usb/usbView/UsbView.java index f9db0b6..4ccce90 100644 --- a/java/src/ch/ntb/usb/usbView/UsbView.java +++ b/java/src/ch/ntb/usb/usbView/UsbView.java @@ -1,7 +1,6 @@ package ch.ntb.usb.usbView; import java.awt.BorderLayout; -import java.awt.Event; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; @@ -21,7 +20,6 @@ import ch.ntb.usb.Usb_Bus; public class UsbView extends JFrame { - private static final int NOF_COLUMS = 20; private static final int APP_WIDTH = 600, APP_HIGHT = 800; private JPanel jContentPane = null;