当前位置: 首页>>代码示例>>Java>>正文


Java LibUsb.controlTransfer方法代码示例

本文整理汇总了Java中org.usb4java.LibUsb.controlTransfer方法的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.controlTransfer方法的具体用法?Java LibUsb.controlTransfer怎么用?Java LibUsb.controlTransfer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.usb4java.LibUsb的用法示例。


在下文中一共展示了LibUsb.controlTransfer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendVendorRequest

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:41,代码来源:CypressFX2.java

示例2: sendDataInternal

import org.usb4java.LibUsb; //导入方法依赖的package包/类
boolean sendDataInternal(ByteBuffer data, int data_size) {
    if (m_isAttached == false) {
        return false;
    }
    int r;
    if (data_size > 20) {
        r = LibUsb.controlTransfer(dev_handle, (byte) 0x21, (byte) 0x09, (short) 0x0212, (short) 1, data, 2000);
    } else {
        r = LibUsb.controlTransfer(dev_handle, (byte) 0x21, (byte) 0x09, (short) 0x0211, (short) 1, data, 2000);
    }
    try {
        // to sleep 0.001 of a second
        Thread.sleep(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return false;
    }
    if (r < 0) {
        return false;
    }
    ByteBuffer buffer = ByteBuffer.allocateDirect(64);
    r = LibUsb.interruptTransfer(dev_handle, (byte) 0x82, buffer, BufferUtils.allocateIntBuffer(), 1);
    return true;
}
 
开发者ID:MohamadSaada,项目名称:LogiGSK,代码行数:25,代码来源:Keyboard.java

示例3: sendVendorRequest

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:42,代码来源:UsbDevice.java

示例4: raw_write

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Sends a message to the yubikey.
 * 
 * @param handle
 *            The USB device handle.
 * @param message
 *            The message to send.
 */
public static int raw_write(DeviceHandle handle, byte[] message)
{
    ByteBuffer buffer = ByteBuffer.allocateDirect(message.length);
    buffer.put(message);
    buffer.rewind();
    int transfered = LibUsb.controlTransfer(handle,
        (byte) (LibUsb.REQUEST_TYPE_CLASS | LibUsb.RECIPIENT_INTERFACE | _USB_ENDPOINT_OUT),
        _HID_SET_REPORT,
        (short)(_REPORT_TYPE_FEATURE << 8),//(short) 2,
        (short) 1, buffer, _USB_TIMEOUT_MS);
    
    if (transfered < 0)
        throw new LibUsbException("Control transfer failed", transfered);
    if (transfered != message.length)
        throw new RuntimeException("Not all data was sent to device");
    
    debug("Data sent to device: "+YubikeyUtil.toHexString(message));
    return transfered;
}
 
开发者ID:Toporin,项目名称:yubikey4java,代码行数:28,代码来源:YubikeyConnector.java

示例5: read

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public static byte[] read(DeviceHandle handle)
{
    ByteBuffer buffer = ByteBuffer.allocateDirect(_FEATURE_RPT_SIZE);
    buffer.rewind();
    int transfered = LibUsb.controlTransfer(handle,
        (byte) (LibUsb.REQUEST_TYPE_CLASS | LibUsb.RECIPIENT_INTERFACE | _USB_ENDPOINT_IN),
        _HID_GET_REPORT,
        (short)(_REPORT_TYPE_FEATURE << 8),//(short) 2,
        (short) 1, buffer, _USB_TIMEOUT_MS);
    
    if (transfered < 0)
        throw new LibUsbException("Control transfer failed", transfered);
    if (transfered != _FEATURE_RPT_SIZE)
        throw new RuntimeException("Not all data was received from device:"+transfered);
    
    byte[] data= new byte[_FEATURE_RPT_SIZE];
    buffer.rewind();
    for (int i=0; i<_FEATURE_RPT_SIZE; i++){
        data[i]= buffer.get();
    }
    debug("Data received from device: "+YubikeyUtil.toHexString(data));
    return data;
    
}
 
开发者ID:Toporin,项目名称:yubikey4java,代码行数:25,代码来源:YubikeyConnector.java

示例6: processControlIrp

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Processes the control IRP.
 * 
 * @param irp
 *            The IRP to process.
 * @throws UsbException
 *             When processing the IRP fails.
 */
protected final void processControlIrp(final UsbControlIrp irp)
    throws UsbException
{
    final ByteBuffer buffer =
        ByteBuffer.allocateDirect(irp.getLength());
    buffer.put(irp.getData(), irp.getOffset(), irp.getLength());
    buffer.rewind();
    final DeviceHandle handle = getDevice().open();
    final int result = LibUsb.controlTransfer(handle, irp.bmRequestType(),
        irp.bRequest(), irp.wValue(), irp.wIndex(), buffer,
        getConfig().getTimeout());
    if (result < 0)
    {
        throw ExceptionUtils.createPlatformException(
            "Unable to submit control message", result);
    }
    buffer.rewind();
    buffer.get(irp.getData(), irp.getOffset(), result);
    irp.setActualLength(result);
    if (irp.getActualLength() != irp.getLength()
        && !irp.getAcceptShortPacket())
    {
        throw new UsbShortPacketException();
    }
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:34,代码来源:AbstractIrpQueue.java

示例7: ov534_reg_write

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private void ov534_reg_write(int reg, int val){
  ByteBuffer buffer = ByteBuffer.allocateDirect(1);
  buffer.put(0, (byte) (val & 0xFF));
 
  int transfered = LibUsb.controlTransfer(usb_device_handle, 
      (byte)(LibUsb.ENDPOINT_OUT | LibUsb.REQUEST_TYPE_VENDOR | LibUsb.RECIPIENT_DEVICE), 
      (byte) 0x01, (byte) 0x00, (short) reg, buffer, 500L);
 
  if (transfered < 0){
    throw new LibUsbException("error ov534_reg_write, LibUsb.controlTransfer", transfered);
  }
}
 
开发者ID:diwi,项目名称:PS3Eye,代码行数:13,代码来源:PS3Eye.java

示例8: ov534_reg_read

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private int ov534_reg_read(int reg){
  ByteBuffer buffer = ByteBuffer.allocateDirect(1);

  int transfered = LibUsb.controlTransfer(usb_device_handle,
      (byte) (LibUsb.ENDPOINT_IN | LibUsb.REQUEST_TYPE_VENDOR| LibUsb.RECIPIENT_DEVICE), 
      (byte) 0x01, (byte) 0x00, (short) reg,
      buffer, 500);

  if (transfered < 0){
    throw new LibUsbException("error ov534_reg_read, LibUsb.controlTransfer", transfered);
  }
  
  return buffer.get() & 0xFF;
}
 
开发者ID:diwi,项目名称:PS3Eye,代码行数:15,代码来源:PS3Eye.java

示例9: sendVendorRequestIN

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:49,代码来源:CypressFX2.java

示例10: sendVendorRequest

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:44,代码来源:CypressFX3.java

示例11: sendVendorRequestIN

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:48,代码来源:CypressFX3.java

示例12: sendVendorRequestIN

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:51,代码来源:UsbDevice.java

示例13: write

import org.usb4java.LibUsb; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:34,代码来源:RTL2832TunerController.java

示例14: read

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:36,代码来源:RTL2832TunerController.java

示例15: readByte

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:48,代码来源:AirspyTunerController.java


注:本文中的org.usb4java.LibUsb.controlTransfer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。