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


Java LibUsb.REQUEST_TYPE_VENDOR属性代码示例

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


在下文中一共展示了LibUsb.REQUEST_TYPE_VENDOR属性的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);
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:40,代码来源:CypressFX2.java

示例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);
	}
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:41,代码来源:UsbDevice.java

示例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);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:48,代码来源:CypressFX2.java

示例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);
	}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:43,代码来源:CypressFX3.java

示例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);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:47,代码来源:CypressFX3.java

示例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);
    //}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:29,代码来源:SiLabsC8051F320_LibUsb.java

示例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);
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:50,代码来源:UsbDevice.java


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