Cannot claim a USB device - USB error 3

1,382 views
Skip to first unread message

John Svazic

unread,
Nov 2, 2013, 8:53:00 PM11/2/13
to usb4...@googlegroups.com
Hi,

I'm running on Ubuntu 13.04 on a Lenovo X1 trying to connect to a Star TSP100 Eco receipt printer.  I need to send a small packet to trigger a cash box to open.  Whenever I try to claim a UsbInterface (as per the code in Java I/O 2nd Edition) I am getting a USB error 3 as follows:

[error] (run-main) de.ailis.usb4java.libusb.LibUsbException: USB error 3: Can't open device Bus 003 Device 003: ID 0519:0003: LIBUSB_ERROR_ACCESS
de.ailis.usb4java.libusb.LibUsbException: USB error 3: Can't open device Bus 003 Device 003: ID 0519:0003: LIBUSB_ERROR_ACCESS
at de.ailis.usb4java.AbstractDevice.open(AbstractDevice.java:223)
at de.ailis.usb4java.AbstractDevice.claimInterface(AbstractDevice.java:403)
at de.ailis.usb4java.Interface.claim(Interface.java:102)
at com.arm.torte.util.Usb$delayedInit$body.apply(Usb.scala:60)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at com.arm.torte.util.Usb$.main(Usb.scala:12)
at com.arm.torte.util.Usb.main(Usb.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

If I do not try to claim the interface, then when I try to open up a pipe to the inbound endpoint, I get the following NPE:

[error] (run-main) java.lang.NullPointerException
java.lang.NullPointerException
at com.arm.torte.util.Usb$delayedInit$body.apply(Usb.scala:83)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at com.arm.torte.util.Usb$.main(Usb.scala:12)
at com.arm.torte.util.Usb.main(Usb.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

Now I'm using Scala for the app, but here is the relevant code.  It should be fairly self-explanatory, but I can explain as necessary.

  val services = UsbHostManager.getUsbServices
  val rootHub = services.getRootUsbHub
  dump(rootHub)
  
  // Look for the Star printer device
  val STAR_VEND_ID = 0x519
  val STAR_PROD_ID = 0x3
  
  // Helper method to find the device, returns an Option[UsbDevice] 
  val device = findDevice(rootHub, STAR_VEND_ID, STAR_PROD_ID) match {
    case Some(x) => x
    case None => throw new RuntimeException("Did not find the receipt printer.")
  }
  
  val config = device.getActiveUsbConfiguration
  val interface = config.getUsbInterface(0.toByte)
  
  // Causes the USB error 3 exception
  interface.claim(new UsbInterfacePolicy() {
    override def forceClaim(usbInterface: UsbInterface): Boolean = true
  })
  
  // Get the inbound endpoint and it's pipe
  // Causes an NPE if the port is not claimed first.
  val inboundEndpoint = interface.getUsbEndpoint(1.toByte)
  val pipe = inboundEndpoint.getUsbPipe

Any help would be greatly appreciated.  Thanks.

-- John

dryggs

unread,
Nov 4, 2013, 4:51:13 AM11/4/13
to usb4...@googlegroups.com
Hello John,

Have you tried running with root permissions?

I have the same error "LIBUSB_ERROR_ACCESS" when I run my app in Ubuntu without it.

Try exporting your app to a runnable jar and run in Terminal using: "sudo java -jar YourApp.jar"

I hope it helps...

Best regards,
dryggs

John Svazic

unread,
Nov 4, 2013, 1:53:27 PM11/4/13
to usb4...@googlegroups.com
Thanks!  That solved my problem.  Now I'm getting a different issue when I try to send a payload down a pipe to an inbound endpoint, but I'll check the other posts to see if a similar problem has been experienced by someone else.  If not, I'll post the details of that in a separate thread.  Thanks again!
Reply all
Reply to author
Forward
0 new messages