|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.ntb.usb.Device
public class Device
This class represents an USB device.
To get an instance of an USB device use USB.getDevice(...)
.
Constructor Summary | |
---|---|
protected |
Device(short idVendor,
short idProduct)
|
protected |
Device(short idVendor,
short idProduct,
java.lang.String filename)
|
Method Summary | |
---|---|
void |
close()
Release the claimed interface and close the opened device. |
int |
controlMsg(int requestType,
int request,
int value,
int index,
byte[] data,
int size,
int timeout,
boolean reopenOnTimeout)
Performs a control request to the default control pipe on a device. The parameters mirror the types of the same name in the USB specification. |
int |
getAltinterface()
Returns the alternative interface. This value is only valid after opening the device. |
Usb_Config_Descriptor[] |
getConfigDescriptors()
Returns the configuration descriptors associated with this device. The descriptors are updated by calling updateDescriptors() or
open(int, int, int) . |
int |
getConfiguration()
Returns the current configuration used. This value is only valid after opening the device. |
Usb_Device |
getDevice()
Returns the Usb_Device instance associated with this device. |
Usb_Device_Descriptor |
getDeviceDescriptor()
Returns the device descriptor associated with this device. The descriptor is updated by calling updateDescriptors() or
open(int, int, int) . |
protected java.lang.String |
getFilename()
Returns the optional filename which is set when there are multiple devices with the same vendor and product id. |
int |
getIdProduct()
Returns the product ID of the device. |
int |
getIdVendor()
Returns the vendor ID of the device. |
int |
getInterface()
Returns the current interface. This value is only valid after opening the device. |
int |
getMaxPacketSize()
Returns the maximum packet size in bytes which is allowed to be transmitted at once. The value is determined by reading the endpoint descriptor(s) when opening the device. |
boolean |
isOpen()
Check if the device is open. This checks only for a valid device handle. |
void |
open(int configuration,
int interface_,
int altinterface)
Opens the device and claims the specified configuration, interface and altinterface. First the bus is enumerated. |
int |
readBulk(int in_ep_address,
byte[] data,
int size,
int timeout,
boolean reopenOnTimeout)
Read data from the device using a bulk transfer. |
int |
readInterrupt(int in_ep_address,
byte[] data,
int size,
int timeout,
boolean reopenOnTimeout)
Read data from the device using a interrupt transfer. |
void |
reset()
Sends an USB reset to the device. |
void |
setResetOnFirstOpen(boolean enable,
int timeout)
If enabled, the device is reset when first opened. |
void |
updateDescriptors()
Updates the device and descriptor information from the bus. The descriptors can be read with getDeviceDescriptor() and
getConfigDescriptors() . |
int |
writeBulk(int out_ep_address,
byte[] data,
int size,
int timeout,
boolean reopenOnTimeout)
Write data to the device using a bulk transfer. |
int |
writeInterrupt(int out_ep_address,
byte[] data,
int size,
int timeout,
boolean reopenOnTimeout)
Write data to the device using a interrupt transfer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Device(short idVendor, short idProduct)
protected Device(short idVendor, short idProduct, java.lang.String filename)
Method Detail |
---|
public void updateDescriptors() throws USBException
getDeviceDescriptor()
and
getConfigDescriptors()
.
USBException
public Usb_Device_Descriptor getDeviceDescriptor()
updateDescriptors()
or
open(int, int, int)
.
null
public Usb_Config_Descriptor[] getConfigDescriptors()
updateDescriptors()
or
open(int, int, int)
.
null
public void open(int configuration, int interface_, int altinterface) throws USBException
maxPacketSize
value is updated. If no
endpoints are found in the descriptors an exception is thrown.
configuration
- the configuration, see
Usb_Config_Descriptor.getBConfigurationValue()
interface_
- the interface, see
Usb_Interface_Descriptor.getBInterfaceNumber()
altinterface
- the alternate interface, see
Usb_Interface_Descriptor.getBAlternateSetting()
. If
no alternate interface must be set -1 can be used.
USBException
public void close() throws USBException
USBException
public void reset() throws USBException
open(int, int, int)
must be
called.
USBException
public int writeBulk(int out_ep_address, byte[] data, int size, int timeout, boolean reopenOnTimeout) throws USBException
out_ep_address
- endpoint address to write todata
- data to write to this endpointsize
- size of the datatimeout
- amount of time in ms the device will try to send the data
until a timeout exception is thrownreopenOnTimeout
- if set to true, the device will try to open the connection and
send the data again before a timeout exception is thrown
USBException
public int readBulk(int in_ep_address, byte[] data, int size, int timeout, boolean reopenOnTimeout) throws USBException
in_ep_address
- endpoint address to read fromdata
- data buffer for the data to be readsize
- the maximum requested data sizetimeout
- amount of time in ms the device will try to receive data until
a timeout exception is thrownreopenOnTimeout
- if set to true, the device will try to open the connection and
receive the data again before a timeout exception is thrown
USBException
public int writeInterrupt(int out_ep_address, byte[] data, int size, int timeout, boolean reopenOnTimeout) throws USBException
out_ep_address
- endpoint address to write todata
- data to write to this endpointsize
- size of the datatimeout
- amount of time in ms the device will try to send the data
until a timeout exception is thrownreopenOnTimeout
- if set to true, the device will try to open the connection and
send the data again before a timeout exception is thrown
USBException
public int readInterrupt(int in_ep_address, byte[] data, int size, int timeout, boolean reopenOnTimeout) throws USBException
in_ep_address
- endpoint address to read fromdata
- data buffer for the data to be readsize
- the maximum requested data sizetimeout
- amount of time in ms the device will try to receive data until
a timeout exception is thrownreopenOnTimeout
- if set to true, the device will try to open the connection and
receive the data again before a timeout exception is thrown
USBException
public int controlMsg(int requestType, int request, int value, int index, byte[] data, int size, int timeout, boolean reopenOnTimeout) throws USBException
requestType
- USB device request type (USB specification 9.3,
bmRequestType). Use constants from USB
(REQ_TYPE_xxx).request
- specific request (USB specification 9.4, bRequest). Use
constants from USB
(REQ_xxx).value
- field that varies according to request (USB specification 9.4,
wValue)index
- field that varies according to request (USB specification 9.4,
wIndex)data
- the send/receive buffersize
- the buffer size. 0 is a valid value, but there must still be a
dummy data buffer provided.timeout
- amount of time in ms the device will try to send/receive data
until a timeout exception is thrownreopenOnTimeout
- if set to true, the device will try to open the connection and
send/receive the data again before a timeout exception is
thrown
USBException
public int getIdProduct()
public int getIdVendor()
public int getAltinterface()
public int getConfiguration()
public int getInterface()
public int getMaxPacketSize()
public boolean isOpen()
public void setResetOnFirstOpen(boolean enable, int timeout)
USBTimeoutException
.
enable
- true if the device should be reset when first openedtimeout
- the timeout between the reset and the reopeningprotected java.lang.String getFilename()
USB.getDevice(short, short, String)
. Use
Usb_Device.getFilename()
to read the filename of a device.
public Usb_Device getDevice()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |