本文整理汇总了Java中org.usb4java.LibUsb.bulkTransfer方法的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.bulkTransfer方法的具体用法?Java LibUsb.bulkTransfer怎么用?Java LibUsb.bulkTransfer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.usb4java.LibUsb
的用法示例。
在下文中一共展示了LibUsb.bulkTransfer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transferBulk
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Transfers bulk data from or to the device.
*
* @param handle
* The device handle.
* @param address
* The endpoint address.
* @param in
* If bulk-in transfer.
* @param buffer
* The data buffer.
* @return The number of transferred bytes.
* @throws UsbException
* When data transfer fails.
*/
private int transferBulk(final DeviceHandle handle, final byte address,
final boolean in, final ByteBuffer buffer) throws UsbException
{
final IntBuffer transferred = IntBuffer.allocate(1);
int result;
do
{
result = LibUsb.bulkTransfer(handle, address, buffer,
transferred, getConfig().getTimeout());
if (result == LibUsb.ERROR_TIMEOUT && isAborting())
throw new UsbAbortException();
}
while (in && result == LibUsb.ERROR_TIMEOUT);
if (result < 0)
{
throw ExceptionUtils.createPlatformException(
"Transfer error on bulk endpoint", result);
}
return transferred.get(0);
}
示例2: read
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Reads some data from the device.
*
* @param handle
* The device handle.
* @param size
* The number of bytes to read from the device.
* @return The read data.
*/
public static ByteBuffer read(DeviceHandle handle, int size)
{
ByteBuffer buffer = BufferUtils.allocateByteBuffer(size).order(
ByteOrder.LITTLE_ENDIAN);
IntBuffer transferred = BufferUtils.allocateIntBuffer();
int result = LibUsb.bulkTransfer(handle, IN_ENDPOINT, buffer,
transferred, TIMEOUT);
if (result != LibUsb.SUCCESS)
{
throw new LibUsbException("Unable to read data", result);
}
System.out.println(transferred.get() + " bytes read from device");
return buffer;
}
示例3: sendVendorRequest
import org.usb4java.LibUsb; //导入方法依赖的package包/类
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);
//}
}
示例4: sendCommand
import org.usb4java.LibUsb; //导入方法依赖的package包/类
private void sendCommand(final byte cmd, final byte data, final boolean spiEnable) {
System.out.println(String.format("Sending command - cmd: %X, data: %X", cmd, data));
// Check for presence of ready device.
if (devHandle == null) {
return;
}
// Prepare message.
final ByteBuffer dataBuffer = BufferUtils.allocateByteBuffer(PACKET_LENGTH);
dataBuffer.put(0, (byte) 'A');
dataBuffer.put(1, (byte) 'T');
dataBuffer.put(2, (byte) 'C');
dataBuffer.put(3, (byte) 0x01); // Command always 1 for SPI upload.
dataBuffer.put(4, (byte) 0x01); // Data length always 1 for 1 byte.
dataBuffer.put(5, (byte) 0x00);
dataBuffer.put(6, (byte) 0x00);
dataBuffer.put(7, (byte) 0x00);
dataBuffer.put(8, cmd); // Send actual SPI command (address usually).
dataBuffer.put(9, (byte) ((spiEnable) ? (0x00) : (0x01)));
// Enable or disable SPI communication.
// Send bulk transfer request on given endpoint.
final IntBuffer transferred = BufferUtils.allocateIntBuffer();
LibUsb.bulkTransfer(devHandle, ENDPOINT, dataBuffer, transferred, 0);
if (transferred.get(0) != PACKET_LENGTH) {
System.out.println("Failed to transfer whole packet.");
}
// Put content in a second packet.
dataBuffer.put(0, data);
// Send second bulk transfer request on given endpoint.
LibUsb.bulkTransfer(devHandle, ENDPOINT, dataBuffer, transferred, 0);
if (transferred.get(0) != PACKET_LENGTH) {
System.out.println("Failed to transfer whole packet.");
}
}
示例5: send
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Send the image to the screen.
*
* @param image An image of size 960 x 160 pixel
*/
public void send (final Image image)
{
if (this.handle == null)
return;
final ByteBuffer header = ByteBuffer.allocateDirect (HDR_SZ);
final ByteBuffer buffer = ByteBuffer.allocateDirect (DATA_SZ);
final IntBuffer transfered = IntBuffer.allocate (1);
header.put (DISPLAY_HEADER);
final PixelReader reader = image.getPixelReader ();
for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
final Color color = reader.getColor (x, y);
// 3b(low) green - 5b red / 5b blue - 3b (high) green, e.g. gggRRRRR BBBBBGGG
final int red = (int) Math.round (color.getRed () * 31);
final int green = (int) Math.round (color.getGreen () * 63);
final int blue = (int) Math.round (color.getBlue () * 31);
buffer.put ((byte) ((green & 0x07) << 5 | red & 0x1F));
buffer.put ((byte) ((blue & 0x1F) << 3 | (green & 0x38) >> 3));
}
for (int x = 0; x < 128; x++)
buffer.put ((byte) 0x00);
}
LibUsb.bulkTransfer (this.handle, (byte) 0x01, header, transfered, 1000L);
LibUsb.bulkTransfer (this.handle, (byte) 0x01, buffer, transfered, 1000L);
}
示例6: sendWithPipe
import org.usb4java.LibUsb; //导入方法依赖的package包/类
public void sendWithPipe(byte[] data) {
ByteBuffer buffer = ByteBuffer.allocateDirect(8);
buffer.put(data);
IntBuffer transfered = IntBuffer.allocate(1);
int result = LibUsb.bulkTransfer(handle, (byte) 0x01, buffer, transfered, (long)10000 );
if (result != LibUsb.SUCCESS) throw new LibUsbException("Control transfer failed", result);
System.out.println(transfered.get() + " bytes sent");
}
示例7: write
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Writes some data to the device.
*
* @param handle
* The device handle.
* @param data
* The data to send to the device.
*/
public static void write(DeviceHandle handle, byte[] data)
{
ByteBuffer buffer = BufferUtils.allocateByteBuffer(data.length);
buffer.put(data);
IntBuffer transferred = BufferUtils.allocateIntBuffer();
int result = LibUsb.bulkTransfer(handle, OUT_ENDPOINT, buffer,
transferred, TIMEOUT);
if (result != LibUsb.SUCCESS)
{
throw new LibUsbException("Unable to send data", result);
}
System.out.println(transferred.get() + " bytes sent to device");
}