本文整理汇总了Java中org.usb4java.LibUsb.RECIPIENT_DEVICE属性的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.RECIPIENT_DEVICE属性的具体用法?Java LibUsb.RECIPIENT_DEVICE怎么用?Java LibUsb.RECIPIENT_DEVICE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.usb4java.LibUsb
的用法示例。
在下文中一共展示了LibUsb.RECIPIENT_DEVICE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendVendorRequest
/**
* Sends a vendor request with data (including special bits). This is a
* blocking method.
*
* @param requestType
* the vendor requestType byte (used for special cases, usually
* 0)
* @param request
* the vendor request byte, identifies the request on the device
* @param value
* the value of the request (bValue USB field)
* @param index
* the "index" of the request (bIndex USB field)
* @param dataBuffer
* the data which is to be transmitted to the device (null means
* no data)
*/
synchronized public void sendVendorRequest(final byte request, final short value, final short index,
ByteBuffer dataBuffer) throws HardwareInterfaceException {
if (!isOpen()) {
open();
}
if (dataBuffer == null) {
dataBuffer = BufferUtils.allocateByteBuffer(0);
}
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.controlTransfer(deviceHandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new HardwareInterfaceException("Unable to send vendor OUT request " + String.format("0x%x", request)
+ ": " + LibUsb.errorName(status));
}
if (status != dataBuffer.capacity()) {
throw new HardwareInterfaceException("Wrong number of bytes transferred, wanted: " + dataBuffer.capacity()
+ ", got: " + status);
}
}
示例2: sendVendorRequest
/**
* Sends a vendor request with data (including special bits). This is a
* blocking method.
*
* @param request
* the vendor request byte, identifies the request on the device
* @param value
* the value of the request (bValue USB field)
* @param index
* the "index" of the request (bIndex USB field)
* @param dataBuffer
* the data which is to be transmitted to the device (null means
* no data)
*
* @throws Exception
* on any exception
*/
public synchronized void sendVendorRequest(final byte request, final short value, final short index,
final ByteBuffer buf) throws IOException {
if (devHandle == null) {
throw new IllegalStateException("Device is not open, cannot send vendor request.");
}
ByteBuffer dataBuffer = buf;
if (dataBuffer == null) {
dataBuffer = BufferUtils.allocateByteBuffer(0);
}
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.controlTransfer(devHandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new IOException("Unable to send vendor OUT request " + String.format("0x%x", request) + ": "
+ LibUsb.errorName(status));
}
if (status != dataBuffer.capacity()) {
throw new IOException(
"Wrong number of bytes transferred, wanted: " + dataBuffer.capacity() + ", got: " + status);
}
}
示例3: sendVendorRequestIN
/**
* Sends a vendor request to receive (IN direction) data. This is a blocking
* method.
*
* @param request
* the vendor request byte, identifies the request on the device
* @param value
* the value of the request (bValue USB field)
* @param index
* the "index" of the request (bIndex USB field)
* @param dataLength
* amount of data to receive, determines size of returned buffer
* (must be greater than 0)
* @return a buffer containing the data requested from the device
*/
synchronized public ByteBuffer sendVendorRequestIN(final byte request, final short value, final short index,
final int dataLength) throws HardwareInterfaceException {
if (dataLength == 0) {
throw new HardwareInterfaceException("Unable to send vendor IN request with dataLength of zero!");
}
if (!isOpen()) {
open();
}
final ByteBuffer dataBuffer = BufferUtils.allocateByteBuffer(dataLength);
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_IN | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.controlTransfer(deviceHandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new HardwareInterfaceException("Unable to send vendor IN request " + String.format("0x%x", request)
+ ": " + LibUsb.errorName(status));
}
if (status != dataLength) {
throw new HardwareInterfaceException("Wrong number of bytes transferred, wanted: " + dataLength + ", got: "
+ status);
}
// Update ByteBuffer internal limit to show how much was successfully
// read.
// usb4java never touches the ByteBuffer's internals by design, so we do
// it here.
dataBuffer.limit(dataLength);
return (dataBuffer);
}
示例4: sendVendorRequest
/**
* Sends a vendor request with data (including special bits). This is a
* blocking method.
*
* @param requestType
* the vendor requestType byte (used for special cases, usually
* 0)
* @param request
* the vendor request byte, identifies the request on the device
* @param value
* the value of the request (bValue USB field)
* @param index
* the "index" of the request (bIndex USB field)
* @param dataBuffer
* the data which is to be transmitted to the device (null means
* no data)
*/
synchronized public void sendVendorRequest(final byte request, final short value, final short index, ByteBuffer dataBuffer)
throws HardwareInterfaceException {
if (!isOpen()) {
open();
}
if (dataBuffer == null) {
dataBuffer = BufferUtils.allocateByteBuffer(0);
}
// System.out.println(String.format("Sent VR %X, wValue %X, wIndex %X, wLength %d.\n", request, value, index,
// dataBuffer.limit()));
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.controlTransfer(deviceHandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new HardwareInterfaceException(
"Unable to send vendor OUT request " + String.format("0x%x", request) + ": " + LibUsb.errorName(status));
}
if (status != dataBuffer.capacity()) {
throw new HardwareInterfaceException(
"Wrong number of bytes transferred, wanted: " + dataBuffer.capacity() + ", got: " + status);
}
}
示例5: sendVendorRequestIN
/**
* Sends a vendor request to receive (IN direction) data. This is a blocking
* method.
*
* @param request
* the vendor request byte, identifies the request on the device
* @param value
* the value of the request (bValue USB field)
* @param index
* the "index" of the request (bIndex USB field)
* @param dataLength
* amount of data to receive, determines size of returned buffer
* (must be greater than 0)
* @return a buffer containing the data requested from the device
*/
synchronized public ByteBuffer sendVendorRequestIN(final byte request, final short value, final short index, final int dataLength)
throws HardwareInterfaceException {
if (dataLength == 0) {
throw new HardwareInterfaceException("Unable to send vendor IN request with dataLength of zero!");
}
if (!isOpen()) {
open();
}
final ByteBuffer dataBuffer = BufferUtils.allocateByteBuffer(dataLength);
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_IN | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.controlTransfer(deviceHandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new HardwareInterfaceException(
"Unable to send vendor IN request " + String.format("0x%x", request) + ": " + LibUsb.errorName(status));
}
if (status != dataLength) {
throw new HardwareInterfaceException("Wrong number of bytes transferred, wanted: " + dataLength + ", got: " + status);
}
// Update ByteBuffer internal limit to show how much was successfully
// read.
// usb4java never touches the ByteBuffer's internals by design, so we do
// it here.
dataBuffer.limit(dataLength);
return (dataBuffer);
}
示例6: sendVendorRequest
synchronized public void sendVendorRequest(final byte request, final Byte value,
ByteBuffer dataBuffer, IntBuffer intBuffer) throws HardwareInterfaceException {
if (!isOpen()) {
open();
}
if (dataBuffer == null) {
dataBuffer = BufferUtils.allocateByteBuffer(2);
dataBuffer.put(request);
dataBuffer.put(value);
}
if (intBuffer == null) {
intBuffer = BufferUtils.allocateIntBuffer();
}
Byte endpoint = 0x02;
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.bulkTransfer(retinahandle, endpoint, dataBuffer, intBuffer, 0);
//controlTransfer(retinahandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new HardwareInterfaceException("Unable to send vendor OUT request " + String.format("0x%x", request)
+ ": " + LibUsb.errorName(status));
}
//if (status != dataBuffer.capacity()) {
// throw new HardwareInterfaceException("Wrong number of bytes transferred, wanted: " + dataBuffer.capacity()
// + ", got: " + status);
//}
}
示例7: sendVendorRequestIN
/**
* Sends a vendor request to receive (IN direction) data. This is a blocking
* method.
*
* @param request
* the vendor request byte, identifies the request on the device
* @param value
* the value of the request (bValue USB field)
* @param index
* the "index" of the request (bIndex USB field)
* @param dataLength
* amount of data to receive, determines size of returned buffer
* (must be greater than 0)
*
* @return a buffer containing the data requested from the device
*
* @throws Exception
* on any exception
*/
public synchronized ByteBuffer sendVendorRequestIN(final byte request, final short value, final short index,
final int dataLength) throws IOException {
if (devHandle == null) {
throw new IllegalStateException("Device is not open, cannot send vendor request.");
}
if (dataLength == 0) {
throw new IllegalArgumentException("Unable to send vendor IN request with dataLength of zero!");
}
final ByteBuffer dataBuffer = BufferUtils.allocateByteBuffer(dataLength);
final byte bmRequestType = (byte) (LibUsb.ENDPOINT_IN | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE);
final int status = LibUsb.controlTransfer(devHandle, bmRequestType, request, value, index, dataBuffer, 0);
if (status < LibUsb.SUCCESS) {
throw new IOException(
"Unable to send vendor IN request " + String.format("0x%x", request) + ": " + LibUsb.errorName(status));
}
if (status != dataLength) {
throw new IOException("Wrong number of bytes transferred, wanted: " + dataLength + ", got: " + status);
}
// Update ByteBuffer internal limit to show how much was successfully
// read. usb4java never touches the ByteBuffer's internals by design,
// so we do it here.
dataBuffer.limit(dataLength);
return (dataBuffer);
}