public class Device
extends java.lang.Object
Constructor and Description |
---|
Device(Context ctx,
java.nio.ByteBuffer nativeDevice) |
Modifier and Type | Method and Description |
---|---|
boolean |
allocTransfer(int isoPackets)
Allocates a libusb transfer
|
int |
bulkTransfer(int endpoint,
byte[] data,
int length,
int timeout)
initiates a bulk transfer
|
void |
claimInterface(int interfaceNumber)
claim the interface specified by its number
|
void |
close()
close this device
|
int |
controlTransfer(byte requestType,
StandardRequest request,
short value,
short index,
byte[] data,
int length,
int timeout) |
java.lang.String |
errorName(int errorCode) |
void |
fillBulkStreamTransfer(int endpoint,
int streamID,
byte[] data,
int length,
java.lang.String callbackFunctionName,
java.lang.Object userData,
int timeout,
java.lang.String fullQualifiedClassName)
Fills the allocated transfer with bulk stream data
|
void |
fillBulkTransfer(int endpoint,
byte[] data,
int length,
java.lang.String callbackFunctionName,
java.lang.Object userData,
int timeout,
java.lang.String fullQualifiedClassName)
Fills the allocated transfer with bulk data
|
void |
fillControlTransfer(int endpoint,
byte[] data,
int length,
java.lang.String callbackFunctionName,
java.lang.Object userData,
int timeout,
java.lang.String fullQualifiedClassName)
Fills the allocated transfer with control data
|
void |
fillInterruptTransfer(int endpoint,
byte[] data,
int length,
java.lang.String callbackFunctionName,
java.lang.Object userData,
int timeout,
java.lang.String fullQualifiedClassName)
Fills the transfer with interrupt data
|
void |
fillIsoTransfer(int endpoint,
byte[] data,
int length,
int numIsoPackets,
java.lang.String callbackFunctionName,
java.lang.Object userData,
int timeout,
java.lang.String fullQualifiedClassName)
Fills the allocated transfer with isochronous data
|
static void |
freeList(Context ctx,
boolean unrefDev)
free the device list
|
void |
freeTransfer()
Frees the allocated transfer
|
int |
getBusNumber()
gives bus number where device is attached
|
Context |
getContext()
get the context this device is using
|
int |
getDeviceAddress()
get address of Device
|
DeviceDescriptor |
getDeviceDescriptor()
get device descriptor of this device
|
Speed |
getDeviceSpeed()
get negotiated device speed
|
static Device |
getDuplicate(Context ctx,
int vid,
int pid,
int nofDuplicate) |
java.nio.ByteBuffer |
getNativeDevice()
get native device pointer, can't be used directly, must be wrapped through jni, so no real use for user
|
static int |
getNofDevices()
get the number of created devices
|
static int |
getNofDuplicates() |
Device |
getParent()
get parent Device, only valid as long as device list is not freed in native code with libusb_free_device_list!
|
int |
getPortNumber()
gives port number where device is attached
|
int |
getPortNumbers(int[] portNumbers)
gives all port numbers from device to root
|
java.lang.String |
getStringDescriptor(int descriptorIndex,
int langId)
get the string descriptor of this device
|
java.lang.String |
getStringDescriptorAscii(int descriptorIndex)
get the string descriptor of this device
|
int |
handleEvents(Context context)
Eventhandler for asychnronous transfers
|
int |
interruptTransfer(int endpoint,
byte[] data,
int length,
int timeout)
read/write data to endpoint with an interrupt transfer
|
boolean |
isOpen()
check if this device is opened
|
void |
open()
open this device
|
void |
open(ConfigurationDescriptor cfgDesc,
Interface iface,
InterfaceDescriptor altSetting) |
static Device |
open(Context ctx,
int vid,
int pid)
open device with following parameters
|
void |
open(int cfgValue,
int ifaceNum,
int altSetting)
open this device with following parameters
|
int |
readBulk(int endpoint,
byte[] data,
int length,
int timeout)
read data from device with a bulk transfer
|
int |
readBulk(int endpoint,
byte[] data,
int length,
int timeout,
boolean reOpenOnTimeout)
read data from device with a bulk transfer, with option to reopen device on timeout and try again
|
int |
readInterrupt(int endpoint,
byte[] data,
int length,
int timeout) |
void |
releaseInterface(int interfaceNumber)
release the interface specified by its number
|
void |
reset()
reset this device
|
static Device |
search(Context ctx,
int vid,
int pid)
search a desired device, this has limitations, if you have more
than one device with the same vid, pid you get just the first in the list
|
void |
setIsoPacketLength(int isoPacketLength)
Sets the isoPacketLength of the transfer
|
int |
submitTransfer()
Submits the allocated and filled transfer
|
int |
writeBulk(int endpoint,
byte[] data,
int length,
int timeout)
write data to device with a bulk transfer
|
int |
writeBulk(int endpoint,
byte[] data,
int length,
int timeout,
boolean reOpenOnTimeout)
write data to device with a bulk transfer, with option to reopen device on timeout and try again
|
int |
writeInterrupt(int endpoint,
byte[] data,
int length,
int timeout) |
public Device(Context ctx, java.nio.ByteBuffer nativeDevice)
public static Device search(Context ctx, int vid, int pid) throws ch.ntb.inf.libusb.exceptions.LibusbException
ctx
- context for search, if null, standard context will be usedvid
- desired vidpid
- desired pidch.ntb.inf.libusb.exceptions.LibusbException
public static int getNofDuplicates()
public static Device getDuplicate(Context ctx, int vid, int pid, int nofDuplicate) throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public static void freeList(Context ctx, boolean unrefDev) throws ch.ntb.inf.libusb.exceptions.LibusbException
ctx
- unrefDev
- ch.ntb.inf.libusb.exceptions.LibusbException
public int getBusNumber()
public int getPortNumber()
public int getPortNumbers(int[] portNumbers) throws ch.ntb.inf.libusb.exceptions.LibusbException
portNumbers
- array for portNumbersch.ntb.inf.libusb.exceptions.LibusbException
public Device getParent() throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public int getDeviceAddress()
public Speed getDeviceSpeed()
public void open() throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
- on failurepublic static Device open(Context ctx, int vid, int pid) throws ch.ntb.inf.libusb.exceptions.LibusbException
ctx
- context for search, if null, standard context will be usedvid
- desired vidpid
- desired pidch.ntb.inf.libusb.exceptions.LibusbException
- on failure or device not foundpublic void open(ConfigurationDescriptor cfgDesc, Interface iface, InterfaceDescriptor altSetting) throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public void open(int cfgValue, int ifaceNum, int altSetting) throws ch.ntb.inf.libusb.exceptions.LibusbException
cfgValue
- desired configuration descriptorifaceNum
- desired interface numberaltSetting
- desired alternate settingch.ntb.inf.libusb.exceptions.LibusbException
- on failurepublic void close() throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public boolean isOpen()
public DeviceDescriptor getDeviceDescriptor() throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public void reset() throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public int controlTransfer(byte requestType, StandardRequest request, short value, short index, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
requestType
- request
- value
- index
- data
- length
- timeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int bulkTransfer(int endpoint, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- timeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int readBulk(int endpoint, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- timeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int readBulk(int endpoint, byte[] data, int length, int timeout, boolean reOpenOnTimeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- timeout
- reOpenOnTimeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int writeBulk(int endpoint, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- timeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int writeBulk(int endpoint, byte[] data, int length, int timeout, boolean reOpenOnTimeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- timeout
- reOpenOnTimeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int interruptTransfer(int endpoint, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- timeout
- ch.ntb.inf.libusb.exceptions.LibusbException
public int writeInterrupt(int endpoint, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public int readInterrupt(int endpoint, byte[] data, int length, int timeout) throws ch.ntb.inf.libusb.exceptions.LibusbException
ch.ntb.inf.libusb.exceptions.LibusbException
public static int getNofDevices()
public Context getContext()
public java.nio.ByteBuffer getNativeDevice()
public void claimInterface(int interfaceNumber) throws ch.ntb.inf.libusb.exceptions.LibusbException
interfaceNumber
- ch.ntb.inf.libusb.exceptions.LibusbException
public void releaseInterface(int interfaceNumber) throws ch.ntb.inf.libusb.exceptions.LibusbException
interfaceNumber
- ch.ntb.inf.libusb.exceptions.LibusbException
public java.lang.String getStringDescriptor(int descriptorIndex, int langId) throws ch.ntb.inf.libusb.exceptions.LibusbException
descriptorIndex
- langId
- ch.ntb.inf.libusb.exceptions.LibusbException
public java.lang.String getStringDescriptorAscii(int descriptorIndex) throws ch.ntb.inf.libusb.exceptions.LibusbException
descriptorIndex
- ch.ntb.inf.libusb.exceptions.LibusbException
public boolean allocTransfer(int isoPackets) throws ch.ntb.inf.libusb.exceptions.LibusbException
isoPackets
- number of iso packetsch.ntb.inf.libusb.exceptions.LibusbException
public void fillIsoTransfer(int endpoint, byte[] data, int length, int numIsoPackets, java.lang.String callbackFunctionName, java.lang.Object userData, int timeout, java.lang.String fullQualifiedClassName) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- numIsoPackets
- callbackFunctionName
- userData
- timeout
- fullQualifiedClassName
- ch.ntb.inf.libusb.exceptions.LibusbException
public void fillInterruptTransfer(int endpoint, byte[] data, int length, java.lang.String callbackFunctionName, java.lang.Object userData, int timeout, java.lang.String fullQualifiedClassName) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- callbackFunctionName
- userData
- timeout
- fullQualifiedClassName
- ch.ntb.inf.libusb.exceptions.LibusbException
public void fillBulkTransfer(int endpoint, byte[] data, int length, java.lang.String callbackFunctionName, java.lang.Object userData, int timeout, java.lang.String fullQualifiedClassName) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- callbackFunctionName
- userData
- timeout
- fullQualifiedClassName
- ch.ntb.inf.libusb.exceptions.LibusbException
public void fillControlTransfer(int endpoint, byte[] data, int length, java.lang.String callbackFunctionName, java.lang.Object userData, int timeout, java.lang.String fullQualifiedClassName) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- data
- length
- callbackFunctionName
- userData
- timeout
- fullQualifiedClassName
- ch.ntb.inf.libusb.exceptions.LibusbException
public void fillBulkStreamTransfer(int endpoint, int streamID, byte[] data, int length, java.lang.String callbackFunctionName, java.lang.Object userData, int timeout, java.lang.String fullQualifiedClassName) throws ch.ntb.inf.libusb.exceptions.LibusbException
endpoint
- streamID
- data
- length
- callbackFunctionName
- userData
- timeout
- fullQualifiedClassName
- ch.ntb.inf.libusb.exceptions.LibusbException
public int submitTransfer()
public int handleEvents(Context context)
context
- public void freeTransfer()
public java.lang.String errorName(int errorCode)
errorCode
- public void setIsoPacketLength(int isoPacketLength)
isoPacketLength
-