Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing USB from an applet on Linux (javax.usb)
    text
    copied!<p>I am trying to get access to a USB device from an applet on Linux. I used sample code from javax.usb to enumerate all devices. The code works when I launch it from Eclipse (in the applet viewer), but only shows one USB hub and 0 devices when used in the browser.</p> <p>I had a similar result with this code before I used it in an applet (1 hub, 0 devices), when permissions on <code>/dev/bus/usb/*</code> were not set properly, so I gave read/write permissions to all (in <code>/etc/udev/rules.d/</code>) just to be sure, but it still doesn't change anything to the results. (<strong>Edit</strong>: To clarify, it made the application work, but it didn't change the results for the applet)</p> <pre><code>SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE:="0666", GROUP:="usbusers" SUBSYSTEM=="usb_device", MODE:="0666", GROUP:="usbusers" </code></pre> <p>The applet is signed (and the <code>jsr80.jar</code>, <code>jsr80_ri.jar</code> and <code>jsr80_linux.jar</code> also), there is a .java.policy granting all permissions to my applet in my home folder, and all required libraries are found. The code executes, it just doesn't seem to see any USB devices (only when run from the browser, the same code works when launched from Eclipse)</p> <p>In the html file:</p> <pre><code>&lt;applet code="apples.TheApplet" archive="SignedApplet.jar,jsr80.jar,jsr80_linux.jar,jsr80_ri.jar" width=600 Height=400&gt; </code></pre> <p>and the Java code:</p> <pre><code>public class TheApplet extends Applet { public void init() { System.setSecurityManager(null); try { // Access the system USB services, and access to // the root // hub. Then traverse through the root hub. System.out.println( "********\nGoing to try to getUsbServices()"); UsbServices services = UsbHostManager .getUsbServices(); System.out.println( "********\nSuccess?"); System.out.println( "********\nTry getRootUsbHub()"); UsbHub rootHub = services.getRootUsbHub(); System.out.println( "********\nSuccess?!"); System.out.println( "********\nTry traverse(rootHub)"); traverse(rootHub); System.out.println( "********\nSuccess."); } catch (Exception e1) { System.out.println( "********\n" + e1.getMessage()); } } public static void traverse(UsbDevice device) { if (device.isUsbHub()) { System.out.println( "********\nFound USB Hub, traversing..."); // This is a USB Hub, traverse through the hub. List attachedDevices = ((UsbHub) device).getAttachedUsbDevices(); System.out.println( "\t"+attachedDevices.size()+" attached devices"); for (int i = 0; i &lt; attachedDevices.size(); i++) { traverse((UsbDevice) attachedDevices.get(i)); } } else { try { System.out.println( "********\n" + "Device:\n\tManufacturerString:\t" + device.getManufacturerString()); device.getManufacturerString(); } catch (Exception e) { e.printStackTrace(); System.out.println( "********\n" + e.getMessage()); } } } } </code></pre> <p>Does anyone have an idea how to make it work?</p> <p><strong>Edit</strong> I am adding an example of the output when the applet is run from Eclipse:</p> <pre><code>...Scan3... ******** Hello! ******** Going to try to getUsbServices() ******** Success? ******** Try getRootUsbHub() ******** Success?! ******** Try traverse(rootHub) ******** Found USB Hub, traversing... 5 attached devices ******** Found USB Hub, traversing... 2 attached devices ******** Found USB Hub, traversing... 1 attached devices ******** Device: ManufacturerString: HHP ******** Device: ManufacturerString: Qualcomm Incorporated ******** Found USB Hub, traversing... 1 attached devices ******** Device: ManufacturerString: Logitech Inc. ******** Found USB Hub, traversing... 0 attached devices ******** Found USB Hub, traversing... 0 attached devices ******** Found USB Hub, traversing... 0 attached devices ******** Success. </code></pre> <p>And the same exact code, from the browser:</p> <pre><code>...Scan3... ******** Hello! ******** Going to try to getUsbServices() ******** Success? ******** Try getRootUsbHub() ******** Success?! ******** Try traverse(rootHub) ******** Found USB Hub, traversing... 0 attached devices ******** Success. </code></pre> <p>As you can see, from the browser it shows 1 USB hub and 0 devices.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload