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