本文整理汇总了Java中org.usb4java.LibUsb.hasCapability方法的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.hasCapability方法的具体用法?Java LibUsb.hasCapability怎么用?Java LibUsb.hasCapability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.usb4java.LibUsb
的用法示例。
在下文中一共展示了LibUsb.hasCapability方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TMT20low
import org.usb4java.LibUsb; //导入方法依赖的package包/类
public TMT20low() throws SecurityException, UsbException {
// Search for epson TM-T20
context = new Context();
int result = LibUsb.init(context);
if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to initialize libusb.", result);
device = findDevice(VENDOR_ID, PRODUCT_ID);
if (device == null) {
System.err.println("not found.");
System.exit(1);
return;
}
handle = new DeviceHandle();
result = LibUsb.open(device, handle);
if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to open USB device", result);
// Check if kernel driver must be detached
boolean detach = LibUsb.hasCapability(LibUsb.CAP_SUPPORTS_DETACH_KERNEL_DRIVER) && (LibUsb.kernelDriverActive(handle, 0) > 0);
System.out.println("hasCapability: "+LibUsb.hasCapability(LibUsb.CAP_SUPPORTS_DETACH_KERNEL_DRIVER)+
", kernelDriverActive: "+LibUsb.kernelDriverActive(handle, 0));
// Detach the kernel driver
if (detach) {
result = LibUsb.detachKernelDriver(handle, 0);
if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to detach kernel driver", result);
}
result = LibUsb.claimInterface(handle, 0);
if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to claim interface", result);
}
示例2: run
import org.usb4java.LibUsb; //导入方法依赖的package包/类
@Override
public void run() {
// Initialize the libusb context
int result = LibUsb.init(null);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to initialize libusb", result);
}
// Check if hotplug is available
if (!LibUsb.hasCapability(LibUsb.CAP_HAS_HOTPLUG)) {
System.err.println("libusb doesn't support hotplug on this system");
//System.exit(1);
Keyboard.KeyboardModel[] keyboardModel = Keyboard.getKeyboardModel();
if ((keyboardModel.length > 1) || (keyboardModel[0] != Keyboard.KeyboardModel.NoLogiKeyboard)) { //check if there is any keyboard connected
System.out.println("Device loaded.");
if (keyboardModel.length > 1) {
//display dialog msg to indicate that program only supports one keyboard connected at a time
System.err.println("Only one keyboard is allowed at a time.");
return;
}
if (usbCurrently.equals("unplugged")) {
usbCurrently = "plugged";
if (status.equals("Running")) {
switch (keyboardModel[0]) {
case Logi910Spectrum:
case Logi910Spark:
case Logi810Spectrum:
case Logi610Orion:
case Logi410AtlasSpectrum:
LogiGSKService.gKeyboard = new GKeyboard(keyboardModel[0]);
LogiGSKService.gKeyboard = IOOperations.loadCurrentKeyboardObjectFromFile(keyboardModel[0]);
if (LogiGSKService.gKeyboard.getEffect() != null) {
resetEffect();
} else {
loadColoursToPhysicalKeyboard(gKeyboard.getKeyColourMap());
}
break;
case NoLogiKeyboard:
break;
default:
break;
}
}
}
} else if ((keyboardModel.length == 1) && (keyboardModel[0] == Keyboard.KeyboardModel.NoLogiKeyboard)) {
usbCurrently = "unplugged";
stopGKeyboardEffects();
}
} else {
// Start the event handling thread
thread = new LogiGSKService.EventHandlingThread();
thread.start();
// Register the hotplug callback
HotplugCallbackHandle callbackHandle = new HotplugCallbackHandle();
result = LibUsb.hotplugRegisterCallback(null,
LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED
| LibUsb.HOTPLUG_EVENT_DEVICE_LEFT,
LibUsb.HOTPLUG_ENUMERATE,
LibUsb.HOTPLUG_MATCH_ANY,
LibUsb.HOTPLUG_MATCH_ANY,
LibUsb.HOTPLUG_MATCH_ANY,
new LogiGSKService.Callback(), null, callbackHandle);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to register hotplug callback",
result);
}
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
thread.abort();
LibUsb.hotplugDeregisterCallback(null, callbackHandle);
// Deinitialize the libusb context
LibUsb.exit(null);
}
}));
}
}
示例3: main
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Main method.
*
* @param args
* Command-line arguments (Ignored)
* @throws Exception
* When something goes wrong.
*/
public static void main(String[] args) throws Exception
{
// Initialize the libusb context
int result = LibUsb.init(null);
if (result != LibUsb.SUCCESS)
{
throw new LibUsbException("Unable to initialize libusb", result);
}
// Check if hotplug is available
if (!LibUsb.hasCapability(LibUsb.CAP_HAS_HOTPLUG))
{
System.err.println("libusb doesn't support hotplug on this system");
System.exit(1);
}
// Start the event handling thread
EventHandlingThread thread = new EventHandlingThread();
thread.start();
// Register the hotplug callback
HotplugCallbackHandle callbackHandle = new HotplugCallbackHandle();
result = LibUsb.hotplugRegisterCallback(null,
LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED
| LibUsb.HOTPLUG_EVENT_DEVICE_LEFT,
LibUsb.HOTPLUG_ENUMERATE,
LibUsb.HOTPLUG_MATCH_ANY,
LibUsb.HOTPLUG_MATCH_ANY,
LibUsb.HOTPLUG_MATCH_ANY,
new Callback(), null, callbackHandle);
if (result != LibUsb.SUCCESS)
{
throw new LibUsbException("Unable to register hotplug callback",
result);
}
// Our faked application. Hit enter key to exit the application.
System.out.println("Hit enter to exit the demo");
System.in.read();
// Unregister the hotplug callback and stop the event handling thread
thread.abort();
LibUsb.hotplugDeregisterCallback(null, callbackHandle);
thread.join();
// Deinitialize the libusb context
LibUsb.exit(null);
}