本文整理汇总了Java中org.usb4java.LibUsb类的典型用法代码示例。如果您正苦于以下问题:Java LibUsb类的具体用法?Java LibUsb怎么用?Java LibUsb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LibUsb类属于org.usb4java包,在下文中一共展示了LibUsb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSerialNumber
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* Writes the serial number string to the device EEPROM
*
* @param name
* the string. This string has very limited length, e.g. 4 bytes.
* @throws net.sf.jaer.hardwareinterface.HardwareInterfaceException
*/
public void setSerialNumber(final String name) throws HardwareInterfaceException {
if (!isOpen()) {
open();
}
final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
final ByteBuffer buffer = BufferUtils.allocateByteBuffer(name.length());
encoder.encode(CharBuffer.wrap(name), buffer, true);
encoder.flush(buffer);
// sendVendorRequest(CypressFX3.VR_SET_DEVICE_NAME, (short) 0, (short)
// 0, buffer);
stringDescriptor3 = LibUsb.getStringDescriptor(deviceHandle, (byte) 3);
if (stringDescriptor3 == null) {
CypressFX3.log.warning("Could not get new device name!");
}
else {
CypressFX3.log.info("New Devicename set, close and reopen the device to see the change");
}
}
示例2: startThread
import org.usb4java.LibUsb; //导入依赖的package包/类
public void startThread() {
if (!isOpen()) {
try {
open();
}
catch (final HardwareInterfaceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
CypressFX2.log.info("Starting AsyncStatusThread");
usbTransfer = new USBTransferThread(monitor.deviceHandle, CypressFX2.STATUS_ENDPOINT_ADDRESS,
LibUsb.TRANSFER_TYPE_BULK, new ProcessStatusMessages(), 2, 128);
usbTransfer.setName("AsyncStatusThread");
usbTransfer.start();
}
示例3: 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);
}
}
示例4: refreshCompatibleDevicesList
import org.usb4java.LibUsb; //导入依赖的package包/类
private void refreshCompatibleDevicesList() {
// Temporary storage to allow modification.
final List<Device> tmpDrain = new ArrayList<>(buildCompatibleDevicesList());
// Replace with new data in a non-destructive way, by not touching
// values that were already present.
final List<Device> removals = new ArrayList<>();
for (final Device element : compatibleDevicesList) {
if (tmpDrain.contains(element)) {
tmpDrain.remove(element);
}
else {
removals.add(element);
LibUsb.unrefDevice(element);
}
}
// Remove all items that need to be deleted and add all the new ones in
// only one call each.
compatibleDevicesList.removeAll(removals);
compatibleDevicesList.addAll(tmpDrain);
// Consume newContent fully.
tmpDrain.clear();
}
示例5: acquireDevice
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* acquire a device for exclusive use, other processes can't open the device
* anymore used for example for continuous sequencing in matlab
*/
public void acquireDevice() throws HardwareInterfaceException {
SiLabsC8051F320_LibUsb.log.log(Level.INFO, "{0} acquiring device for exclusive access", this);
final int status = LibUsb.claimInterface(retinahandle, 0);
if (status != LibUsb.SUCCESS) {
if (status == LibUsb.ERROR_BUSY) {
try {
sleep(3000);
} catch (InterruptedException ex) {
}
}
throw new HardwareInterfaceException("Unable to acquire device for exclusive use: "
+ LibUsb.errorName(status));
}
}
示例6: detach
import org.usb4java.LibUsb; //导入依赖的package包/类
boolean detach() {
if (m_isAttached == false) {
return false;
}
int r;
r = LibUsb.releaseInterface(dev_handle, 1);
if (r != 0) {
return false;
}
if (m_isKernellDetached == true) {
LibUsb.attachKernelDriver(dev_handle, 1);
m_isKernellDetached = false;
}
LibUsb.close(dev_handle);
dev_handle = null;
LibUsb.exit(ctx);
ctx = null;
m_isAttached = false;
return true;
}
示例7: 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;
}
示例8: 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);
}
}
示例9: disconnect
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* Disconnect from the USB device.
*/
public void disconnect ()
{
if (this.handle == null)
return;
// Prevent further sending
final DeviceHandle h = this.handle;
this.handle = null;
final int result = LibUsb.releaseInterface (h, INTERFACE_NUMBER);
if (result != LibUsb.SUCCESS)
throw new LibUsbException ("Unable to release interface", result);
LibUsb.close (h);
LibUsb.exit (null);
}
示例10: release
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* Releases the USB interface
*/
public void release()
{
try
{
if(mUSBTransferProcessor != null)
{
mUSBTransferProcessor.removeAllListeners();
TunerManager.LIBUSB_TRANSFER_PROCESSOR.unregisterTransferProcessor(mUSBTransferProcessor);
}
LibUsb.releaseInterface(mDeviceHandle, USB_INTERFACE);
}
catch(Exception e)
{
mLog.error("attempt to release USB interface failed", e);
}
}
示例11: init
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* Initializes the controller by opening the USB device and claiming the
* HID interface.
*
* Invoke this method after constructing this class to setup the
* controller.
*
* @throws SourceException if cannot open and claim the USB device
*/
public void init() throws SourceException
{
mDeviceHandle = new DeviceHandle();
int result = LibUsb.open(mDevice, mDeviceHandle);
if(result != LibUsb.SUCCESS)
{
mDeviceHandle = null;
throw new SourceException("libusb couldn't open funcube usb device [" + LibUsb.errorName(result) + "]");
}
claimInterface();
}
示例12: dispose
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* Disposes of resources. Closes the USB device and interface.
*/
public void dispose()
{
if(mDeviceHandle != null)
{
try
{
LibUsb.close(mDeviceHandle);
}
catch(Exception e)
{
mLog.error("error while closing device handle", e);
}
mDeviceHandle = null;
}
mDeviceDescriptor = null;
mDevice = null;
}
示例13: getUSBAddress
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* USB address (bus/port)
*/
public String getUSBAddress()
{
if(mDevice != null)
{
StringBuilder sb = new StringBuilder();
sb.append("Bus:");
int bus = LibUsb.getBusNumber(mDevice);
sb.append(bus);
sb.append(" Port:");
int port = LibUsb.getPortNumber(mDevice);
sb.append(port);
return sb.toString();
}
return "UNKNOWN";
}
示例14: getUSBSpeed
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* USB Port Speed. Should be 2.0 for both types of funcube dongles
*/
public String getUSBSpeed()
{
if(mDevice != null)
{
int speed = LibUsb.getDeviceSpeed(mDevice);
switch(speed)
{
case 0:
return "1.1 LOW";
case 1:
return "1.1 FULL";
case 2:
return "2.0 HIGH";
case 3:
return "3.0 SUPER";
default:
}
}
return "UNKNOWN";
}
示例15: write
import org.usb4java.LibUsb; //导入依赖的package包/类
/**
* 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);
}
}