本文整理汇总了Java中org.usb4java.LibUsb.ERROR_NO_DEVICE属性的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.ERROR_NO_DEVICE属性的具体用法?Java LibUsb.ERROR_NO_DEVICE怎么用?Java LibUsb.ERROR_NO_DEVICE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.usb4java.LibUsb
的用法示例。
在下文中一共展示了LibUsb.ERROR_NO_DEVICE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
/**
* Performs an interrupt write to the OUT endpoint.
*
* @param buffer - direct allocated buffer. Must be 64 bytes in length.
* @throws LibUsbException on error
*/
private void write(ByteBuffer buffer) throws LibUsbException
{
if(mDeviceHandle != null)
{
IntBuffer transferred = IntBuffer.allocate(1);
int result = LibUsb.interruptTransfer(mDeviceHandle, FCD_ENDPOINT_OUT, buffer, transferred, 500l);
if(result != LibUsb.SUCCESS)
{
throw new LibUsbException("error writing byte buffer", result);
}
}
else
{
throw new LibUsbException("device handle is null", LibUsb.ERROR_NO_DEVICE);
}
}
示例2: connect
/**
* Connect to the USB port and claim the display interface.
*/
public void connect ()
{
int result = LibUsb.init (null);
if (result != LibUsb.SUCCESS)
throw new LibUsbException ("Unable to initialize libusb.", result);
this.handle = openDeviceWithVidPid (VENDOR_ID, PRODUCT_ID);
if (this.handle == null)
throw new LibUsbException ("Device not found.", LibUsb.ERROR_NO_DEVICE);
result = LibUsb.claimInterface (this.handle, INTERFACE_NUMBER);
if (result != LibUsb.SUCCESS)
throw new LibUsbException ("Unable to claim interface.", result);
}
示例3: write
protected static void write(DeviceHandle handle,
short value,
short index,
ByteBuffer buffer) throws LibUsbException
{
if(handle != null)
{
int transferred = LibUsb.controlTransfer(handle,
CONTROL_ENDPOINT_OUT,
REQUEST_ZERO,
value,
index,
buffer,
TIMEOUT_US);
if(transferred < 0)
{
throw new LibUsbException("error writing byte buffer",
transferred);
}
else if(transferred != buffer.capacity())
{
throw new LibUsbException("transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred);
}
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例4: read
/**
* Performs a control type read
*/
protected static void read(DeviceHandle handle,
short address,
short index,
ByteBuffer buffer) throws LibUsbException
{
if(handle != null)
{
int transferred = LibUsb.controlTransfer(handle,
CONTROL_ENDPOINT_IN,
REQUEST_ZERO,
address,
index,
buffer,
TIMEOUT_US);
if(transferred < 0)
{
throw new LibUsbException("read error", transferred);
}
else if(transferred != buffer.capacity())
{
throw new LibUsbException("transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred);
}
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例5: read
/**
* Performs an interrupt read against the endpoint
*
* @return buffer read from FCD
* @throws LibUsbException on error
*/
private ByteBuffer read() throws LibUsbException
{
if(mDeviceHandle != null)
{
ByteBuffer buffer = ByteBuffer.allocateDirect(64);
IntBuffer transferred = IntBuffer.allocate(1);
int result = LibUsb.interruptTransfer(mDeviceHandle, FCD_ENDPOINT_IN, buffer, transferred, 500l);
if(result != LibUsb.SUCCESS)
{
throw new LibUsbException("error reading byte buffer", result);
}
else if(transferred.get(0) != buffer.capacity())
{
throw new LibUsbException("received bytes [" + transferred.get(0) +
"] didn't match expected length [" + buffer.capacity() + "]", result);
}
return buffer;
}
throw new LibUsbException("device handle is null", LibUsb.ERROR_NO_DEVICE);
}
示例6: readByte
/**
* Reads a single byte value from the device.
*
* @param command - airspy command
* @param value - value field for usb setup packet
* @param index - index field for usb setup packet
* @return - byte value as an integer
* @throws LibUsbException if the operation is unsuccesful
* @throws UsbException on any usb errors
*/
private int readByte(Command command, int value, int index, boolean signed)
throws LibUsbException, UsbException
{
if(mDeviceHandle != null)
{
ByteBuffer buffer = ByteBuffer.allocateDirect(1);
int transferred = LibUsb.controlTransfer(mDeviceHandle,
USB_REQUEST_IN,
command.getValue(),
(short) value,
(short) index,
buffer,
USB_TIMEOUT_MS);
if(transferred < 0)
{
throw new LibUsbException("read error", transferred);
}
byte result = buffer.get(0);
if(signed)
{
return (result & 0xFF);
}
else
{
return result;
}
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例7: readArray
/**
* Reads a multi-byte value from the device
*
* @param command - airspy command
* @param value - usb packet value
* @param index - usb packet index
* @param length - number of bytes to read
* @return - bytes read from the device
* @throws LibUsbException if quantity of bytes read doesn't equal the
* requested number of bytes
* @throws UsbException on error communicating with the device
*/
private byte[] readArray(Command command, int value, int index, int length)
throws LibUsbException, UsbException
{
if(mDeviceHandle != null)
{
ByteBuffer buffer = ByteBuffer.allocateDirect(length);
int transferred = LibUsb.controlTransfer(mDeviceHandle,
USB_REQUEST_IN,
command.getValue(),
(short) value,
(short) index,
buffer,
USB_TIMEOUT_MS);
if(transferred < 0)
{
throw new LibUsbException("read error", transferred);
}
byte[] results = new byte[transferred];
buffer.get(results);
return results;
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例8: write
/**
* Writes the buffer contents to the device
*
* @param command - airspy command
* @param value - usb packet value
* @param index - usb packet index
* @param buffer - data to write to the device
* @throws UsbException on error
*/
public void write(Command command, int value, int index, ByteBuffer buffer)
throws UsbException
{
if(mDeviceHandle != null)
{
int transferred = LibUsb.controlTransfer(mDeviceHandle,
USB_REQUEST_OUT,
command.getValue(),
(short) value,
(short) index,
buffer,
USB_TIMEOUT_MS);
if(transferred < 0)
{
throw new LibUsbException("error writing byte buffer",
transferred);
}
else if(transferred != buffer.capacity())
{
throw new LibUsbException("transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred);
}
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例9: readArray
public ByteBuffer readArray(Request request,
int value,
int index,
int length) throws UsbException
{
if(mDeviceHandle != null)
{
ByteBuffer buffer = ByteBuffer.allocateDirect(length);
int transferred = LibUsb.controlTransfer(mDeviceHandle,
REQUEST_TYPE_IN,
request.getRequestNumber(),
(short)value,
(short)index,
buffer,
USB_TIMEOUT_US);
if(transferred < 0)
{
throw new LibUsbException("read error", transferred);
}
return buffer;
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例10: write
public void write(Request request,
int value,
int index,
ByteBuffer buffer) throws UsbException
{
if(mDeviceHandle != null)
{
int transferred = LibUsb.controlTransfer(mDeviceHandle,
REQUEST_TYPE_OUT,
request.getRequestNumber(),
(short)value,
(short)index,
buffer,
USB_TIMEOUT_US);
if(transferred < 0)
{
throw new LibUsbException("error writing byte buffer",
transferred);
}
else if(transferred != buffer.capacity())
{
throw new LibUsbException("transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred);
}
}
else
{
throw new LibUsbException("device handle is null",
LibUsb.ERROR_NO_DEVICE);
}
}
示例11: write
protected static void write( DeviceHandle handle,
short value,
short index,
ByteBuffer buffer ) throws LibUsbException
{
if( handle != null )
{
int transferred = LibUsb.controlTransfer( handle,
CONTROL_ENDPOINT_OUT,
REQUEST_ZERO,
value,
index,
buffer,
TIMEOUT_US );
if( transferred < 0 )
{
throw new LibUsbException( "error writing byte buffer",
transferred );
}
else if( transferred != buffer.capacity() )
{
throw new LibUsbException( "transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred );
}
}
else
{
throw new LibUsbException( "device handle is null",
LibUsb.ERROR_NO_DEVICE );
}
}
示例12: read
/**
* Performs a control type read
*/
protected static void read( DeviceHandle handle,
short address,
short index,
ByteBuffer buffer ) throws LibUsbException
{
if( handle != null )
{
int transferred = LibUsb.controlTransfer( handle,
CONTROL_ENDPOINT_IN,
REQUEST_ZERO,
address,
index,
buffer,
TIMEOUT_US );
if( transferred < 0 )
{
throw new LibUsbException( "read error", transferred );
}
else if( transferred != buffer.capacity() )
{
throw new LibUsbException( "transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred );
}
}
else
{
throw new LibUsbException( "device handle is null",
LibUsb.ERROR_NO_DEVICE );
}
}
示例13: readByte
/**
* Reads a single byte value from the device.
*
* @param command - airspy command
*
* @param value - value field for usb setup packet
* @param index - index field for usb setup packet
*
* @return - byte value as an integer
*
* @throws LibUsbException if the operation is unsuccesful
* @throws DeviceException on any usb errors
*/
private int readByte( Command command, int value, int index, boolean signed )
throws LibUsbException, DeviceException
{
if( mDeviceHandle != null )
{
ByteBuffer buffer = ByteBuffer.allocateDirect( 1 );
int transferred = LibUsb.controlTransfer( mDeviceHandle,
USB_REQUEST_IN,
command.getValue(),
(short)value,
(short)index,
buffer,
USB_TIMEOUT_MS );
if( transferred < 0 )
{
throw new LibUsbException( "read error", transferred );
}
byte result = buffer.get( 0 );
if( signed )
{
return ( result & 0xFF );
}
else
{
return result;
}
}
else
{
throw new LibUsbException( "device handle is null",
LibUsb.ERROR_NO_DEVICE );
}
}
示例14: readArray
/**
* Reads a multi-byte value from the device
*
* @param command - airspy command
* @param value - usb packet value
* @param index - usb packet index
* @param length - number of bytes to read
* @return - bytes read from the device
*
* @throws LibUsbException if quantity of bytes read doesn't equal the
* requested number of bytes
* @throws DeviceException on error communicating with the device
*/
private byte[] readArray( Command command, int value, int index, int length )
throws LibUsbException, DeviceException
{
if( mDeviceHandle != null )
{
ByteBuffer buffer = ByteBuffer.allocateDirect( length );
int transferred = LibUsb.controlTransfer( mDeviceHandle,
USB_REQUEST_IN,
command.getValue(),
(short)value,
(short)index,
buffer,
USB_TIMEOUT_MS );
if( transferred < 0 )
{
throw new LibUsbException( "read error", transferred );
}
byte[] results = new byte[ transferred ];
buffer.get( results );
return results;
}
else
{
throw new LibUsbException( "device handle is null",
LibUsb.ERROR_NO_DEVICE );
}
}
示例15: write
/**
* Writes the buffer contents to the device
*
* @param command - airspy command
* @param value - usb packet value
* @param index - usb packet index
* @param buffer - data to write to the device
* @throws DeviceException on error
*/
public void write( Command command, int value, int index, ByteBuffer buffer )
throws DeviceException
{
if( mDeviceHandle != null )
{
int transferred = LibUsb.controlTransfer( mDeviceHandle,
USB_REQUEST_OUT,
command.getValue(),
(short)value,
(short)index,
buffer,
USB_TIMEOUT_MS );
if( transferred < 0 )
{
throw new LibUsbException( "error writing byte buffer",
transferred );
}
else if( transferred != buffer.capacity() )
{
throw new LibUsbException( "transferred bytes [" +
transferred + "] is not what was expected [" +
buffer.capacity() + "]", transferred );
}
}
else
{
throw new LibUsbException( "device handle is null",
LibUsb.ERROR_NO_DEVICE );
}
}