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


Java Context类代码示例

本文整理汇总了Java中org.usb4java.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DeviceManager

import org.usb4java.Context; //导入依赖的package包/类
/**
 * Constructs a new device manager.
 * 
 * @param rootHub
 *            The root hub. Must not be null.
 * @param scanInterval
 *            The scan interval in milliseconds.
 * @throws UsbException
 *             When USB initialization fails.
 */
DeviceManager(final RootHub rootHub, final int scanInterval)
    throws UsbException
{
    if (rootHub == null)
        throw new IllegalArgumentException("rootHub must be set");
    this.scanInterval = scanInterval;
    this.rootHub = rootHub;
    this.context = new Context();
    final int result = LibUsb.init(this.context);
    if (result != 0)
    {
        throw ExceptionUtils.createPlatformException(
            "Unable to initialize libusb", result);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:26,代码来源:DeviceManager.java

示例2: TMT20low

import org.usb4java.Context; //导入依赖的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);
}
 
开发者ID:pierre-muth,项目名称:selfpi,代码行数:33,代码来源:TMT20low.java

示例3: processEvent

import org.usb4java.Context; //导入依赖的package包/类
@Override
public int processEvent(Context context, Device device, int event,
    Object userData)
{
    DeviceDescriptor descriptor = new DeviceDescriptor();
    int result = LibUsb.getDeviceDescriptor(device, descriptor);
    if (result != LibUsb.SUCCESS)
        throw new LibUsbException("Unable to read device descriptor",
            result);
    System.out.format("%s: %04x:%04x%n",
        event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED ? "Connected" :
            "Disconnected",
        descriptor.idVendor(), descriptor.idProduct());
    return 0;
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:16,代码来源:HotPlug.java

示例4: main

import org.usb4java.Context; //导入依赖的package包/类
/**
 * Main method.
 * 
 * @param args
 *            Command-line arguments (Ignored)
 */
public static void main(final String[] args)
{
    // Create the libusb context
    final Context context = new Context();

    // Initialize the libusb context
    int result = LibUsb.init(context);
    if (result < 0)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    // Read the USB device list
    final DeviceList list = new DeviceList();
    result = LibUsb.getDeviceList(context, list);
    if (result < 0)
    {
        throw new LibUsbException("Unable to get device list", result);
    }

    try
    {
        // Iterate over all devices and dump them
        for (Device device: list)
        {
            dumpDevice(device);
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }
    
    // Deinitialize the libusb context
    LibUsb.exit(context);
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:44,代码来源:DumpDevices.java

示例5: processEvent

import org.usb4java.Context; //导入依赖的package包/类
@Override
public int processEvent(Context context, Device device, int event,
        Object userData) {
    DeviceDescriptor descriptor = new DeviceDescriptor();
    int result = LibUsb.getDeviceDescriptor(device, descriptor);
    if (result != LibUsb.SUCCESS) {
        throw new LibUsbException("Unable to read device descriptor",
                result);
    }
    Keyboard.KeyboardModel[] keyboardModel = Keyboard.getKeyboardModel();
    if ((keyboardModel.length > 1) || (keyboardModel[0] != Keyboard.KeyboardModel.NoLogiKeyboard)) { //check if there is any keyboard connected
        if ((event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED) && (descriptor.idVendor() == 0x046d)
                && Arrays.asList(keyboardsProductNumbers).contains(String.format("%04x", descriptor.idProduct()))) {
            System.out.format("%s: %04x:%04x%n",
                    event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED
                            ? "Connected" : "Disconnected",
                    descriptor.idVendor(), descriptor.idProduct());
            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 0;
            }
            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 ((event == LibUsb.HOTPLUG_EVENT_DEVICE_LEFT) && (keyboardModel.length == 1) && (keyboardModel[0] == Keyboard.KeyboardModel.NoLogiKeyboard)) {
        usbCurrently = "unplugged";
        stopGKeyboardEffects();

    } else if ((keyboardModel.length == 1) && (keyboardModel[0] == Keyboard.KeyboardModel.NoLogiKeyboard)) {
        usbCurrently = "unplugged";
        System.out.println("No connected Keyboard");
        stopGKeyboardEffects();
    }
    return 0;
}
 
开发者ID:MohamadSaada,项目名称:LogiGSK,代码行数:59,代码来源:LogiGSKService.java

示例6: main

import org.usb4java.Context; //导入依赖的package包/类
/**
 * Main method.
 * 
 * @param args
 *            Command-line arguments (Ignored)
 */
public static void main(String[] args)
{
    // Create the libusb context
    Context context = new Context();

    // Initialize the libusb context
    int result = LibUsb.init(context);
    if (result < 0)
    {
        throw new LibUsbException("Unable to initialize libusb", result);
    }

    // Read the USB device list
    DeviceList list = new DeviceList();
    result = LibUsb.getDeviceList(context, list);
    if (result < 0)
    {
        throw new LibUsbException("Unable to get device list", result);
    }

    try
    {
        // Iterate over all devices and list them
        for (Device device: list)
        {
            int address = LibUsb.getDeviceAddress(device);
            int busNumber = LibUsb.getBusNumber(device);
            DeviceDescriptor descriptor = new DeviceDescriptor();
            result = LibUsb.getDeviceDescriptor(device, descriptor);
            if (result < 0)
            {
                throw new LibUsbException(
                    "Unable to read device descriptor", result);
            }
            System.out.format(
                "Bus %03d, Device %03d: Vendor %04x, Product %04x%n",
                busNumber, address, descriptor.idVendor(),
                descriptor.idProduct());
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }

    // Deinitialize the libusb context
    LibUsb.exit(context);
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:56,代码来源:ListDevices.java


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