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


Java LibUsb.init方法代码示例

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


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

示例1: DeviceManager

import org.usb4java.LibUsb; //导入方法依赖的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: init

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public void init(int log_level){
  if(context != null){
    return;
  }

  int result = LibUsb.init(context);
  if (result != LibUsb.SUCCESS) {
    throw new LibUsbException("Unable to initialize libusb.", result);
  }
  
  LibUsb.setDebug(context, log_level);
}
 
开发者ID:diwi,项目名称:PS3Eye,代码行数:13,代码来源:USB.java

示例3: LibUsbHardwareInterfaceFactory

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private LibUsbHardwareInterfaceFactory() {
	// Build a mapping of VID/PID pairs and corresponding
	// HardwareInterfaces.
	// addDeviceToMap(CypressFX2.VID, CypressFX2.PID_USB2AERmapper,
	// CypressFX2Mapper.class);
	addDeviceToMap(CypressFX2.VID, CypressFX2.PID_DVS128_REV0, CypressFX2DVS128HardwareInterface.class);
	addDeviceToMap(CypressFX2.VID, CypressFX2.PID_TMPDIFF128_RETINA, CypressFX2TmpdiffRetinaHardwareInterface.class);
	addDeviceToMap(CypressFX2.VID, CypressFX2.PID_COCHLEAAMS, CochleaAMS1cHardwareInterface.class);

	// Linux Drivers for PAER retina.
	if (System.getProperty("os.name").startsWith("Linux")) {
		addDeviceToMap(CypressFX2.VID, SiLabsC8051F320_LibUsb_PAER.PID_PAER, SiLabsC8051F320_LibUsb_PAER.class);
	}

	// Add blank device for flashing.
	addDeviceToMap(CypressFX2.VID_BLANK, CypressFX2.PID_BLANK, CypressFX2.class);

	// Initialize LibUsb.
               try { 
	LibUsb.init(null);
               } catch(UnsatisfiedLinkError ule) {
                   UnsatisfiedLinkError u = new UnsatisfiedLinkError("Failed to initialize libusb4java! Do you have noexec on your /tmp ? See jAERViewer1.5_linux.sh for a workaround.\n"+
                           ule.getLocalizedMessage());
                   u.setStackTrace(ule.getStackTrace());
                   throw u;
               }

	// Build up first list of compatible devices.
	refreshCompatibleDevicesList();
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:31,代码来源:LibUsbHardwareInterfaceFactory.java

示例4: LibUsb3HardwareInterfaceFactory

import org.usb4java.LibUsb; //导入方法依赖的package包/类
private LibUsb3HardwareInterfaceFactory() {
	// Build a mapping of VID/PID pairs and corresponding
	// HardwareInterfaces.
	addDeviceToMap(CypressFX3.VID, DAViSFX3HardwareInterface.PID_FX3, DAViSFX3HardwareInterface.class);

	addDeviceToMap(CypressFX3.VID, DAViSFX3HardwareInterface.PID_FX2, DAViSFX3HardwareInterface.class);

	addDeviceToMap(CypressFX3.VID, CochleaFX3HardwareInterface.PID_FX3, CochleaFX3HardwareInterface.class);

	// Initialize LibUsb.
	LibUsb.init(null);

	// Build up first list of compatible devices.
	refreshCompatibleDevicesList();
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:16,代码来源:LibUsb3HardwareInterfaceFactory.java

示例5: connect

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Connect to the USB port and claim the display interface.
 */
public void connect ()
{
    int result = LibUsb.init (null);
    if (result != LibUsb.SUCCESS)
        throw new LibUsbException ("Unable to initialize libusb.", result);

    this.handle = openDeviceWithVidPid (VENDOR_ID, PRODUCT_ID);
    if (this.handle == null)
        throw new LibUsbException ("Device not found.", LibUsb.ERROR_NO_DEVICE);

    result = LibUsb.claimInterface (this.handle, INTERFACE_NUMBER);
    if (result != LibUsb.SUCCESS)
        throw new LibUsbException ("Unable to claim interface.", result);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:18,代码来源:USBDisplay.java

示例6: init

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public int init() throws LibUsbException {
    int result = LibUsb.init(context);
    if (result < 0) {
        throw new LibUsbException("Unable to initialize libusb", result);
    }
    return result;
}
 
开发者ID:kairyu,项目名称:flop,代码行数:8,代码来源:Dfu.java

示例7: 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);
}
 
开发者ID:pierre-muth,项目名称:selfpi,代码行数:33,代码来源:TMT20low.java

示例8: initContext

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * initialize the WinUSb Context. According to usb4java documentation, it
 * initialise the C++ WinUSB Struct
 * 
 */
private void initContext() {
	this.context = new Context();
	int result = LibUsb.init(context);
	if (result != LibUsb.SUCCESS)
		throw new LibUsbException("Unable to initialize libusb.", result);
}
 
开发者ID:Plug-up,项目名称:daplug-java,代码行数:12,代码来源:DaplugDongleWinusb.java

示例9: 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);
    }

    // Open test device (Samsung Galaxy Nexus)
    DeviceHandle handle = LibUsb.openDeviceWithVidPid(null, VENDOR_ID,
        PRODUCT_ID);
    if (handle == null)
    {
        System.err.println("Test device not found.");
        System.exit(1);
    }

    // Claim the ADB interface
    result = LibUsb.claimInterface(handle, INTERFACE);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to claim interface", result);
    }

    // Send ADB CONNECT message
    write(handle, CONNECT_HEADER);
    write(handle, CONNECT_BODY);

    // Receive the header of the ADB answer (Most likely an AUTH message)
    ByteBuffer header = read(handle, 24);
    header.position(12);
    int dataSize = header.asIntBuffer().get();

    // Receive the body of the ADB answer
    @SuppressWarnings("unused")
    ByteBuffer data = read(handle, dataSize);

    // Release the ADB interface
    result = LibUsb.releaseInterface(handle, INTERFACE);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to release interface", result);
    }

    // Close the device
    LibUsb.close(handle);

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

示例10: main

import org.usb4java.LibUsb; //导入方法依赖的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

示例11: 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);
            }
        }));
    }
}
 
开发者ID:MohamadSaada,项目名称:LogiGSK,代码行数:81,代码来源:LogiGSKService.java

示例12: start

import org.usb4java.LibUsb; //导入方法依赖的package包/类
@Override
public void start(final Stage primaryStage) {
	if (GUISupport.checkJavaVersion(primaryStage)) {
		final MenuBar menuBar = new MenuBar();

		final Menu menuHelp = new Menu("Help");
		menuBar.getMenus().add(menuHelp);

		final MenuItem helpMenuItem = new MenuItem("Flashy help page");
		menuHelp.getItems().add(helpMenuItem);

		// Open Flashy help website on menu item click.
		helpMenuItem.setOnAction((e) -> getHostServices().showDocument(Flashy.FLASHY_HELP_URL));

		// Initialize libusb default context on program start.
		LibUsb.init(null);

		final VBox gui = new VBox(20);
		gui.getChildren().add(menuBar);
		gui.getChildren().add(usbDeviceSelectGUI());

		final TabPane tabLayout = new TabPane();
		gui.getChildren().add(tabLayout);

		GUISupport.addTab(tabLayout, usbInfoGUI(), "Info");

		GUISupport.addTab(tabLayout, usbCommandGUI(), "Vendor Requests");

		GUISupport.addTab(tabLayout, supplementalGUI, "Device Specific");

		GUISupport.addTab(tabLayout, supplementalGUIInfo, "Device Info");

		GUISupport.startGUI(primaryStage, gui, "Flashy - Firmware/Logic Flashing Utility",
			new EventHandler<WindowEvent>() {
				@Override
				public void handle(@SuppressWarnings("unused") final WindowEvent evt) {
					deviceClose(selectedUsbDevice.getValue());

					// Close libusb default context on program exit.
					LibUsb.exit(null);
				}
			});
	}
}
 
开发者ID:inilabs,项目名称:flashy,代码行数:45,代码来源:Flashy.java

示例13: makeDevice

import org.usb4java.LibUsb; //导入方法依赖的package包/类
public static AirspyDevice makeDevice() throws UsbException {
	DeviceList deviceList = new DeviceList();
	AirspyDevice dev = null;

	int result = LibUsb.init( null );

	if( result != LibUsb.SUCCESS ) {
		Log.errorDialog("ERROR", "unable to initialize libusb [" + 
				LibUsb.errorName( result ) + "]" );
	}
	else
	{
		Log.println( "LibUSB API Version: " + LibUsb.getApiVersion() );
		Log.println( "LibUSB Version: " + LibUsb.getVersion() );

		result = LibUsb.getDeviceList( null, deviceList );

		if( result < 0 )
		{
			Log.errorDialog( "ERROR","unable to get device list from libusb [" + result + " / " + 
					LibUsb.errorName( result ) + "]" );
		}
		else
		{
			Log.println( "discovered [" + result + "] attached USB devices" );
		}
	}

	for( Device device: deviceList )
	{
		DeviceDescriptor descriptor = new DeviceDescriptor();

		result = LibUsb.getDeviceDescriptor( device, descriptor );

		if( result != LibUsb.SUCCESS )
		{
			Log.errorDialog("ERROR", "unable to read device descriptor [" + 
					LibUsb.errorName( result ) + "]" );
		}
		else
		{
			if( device != null && descriptor != null )
			{
				TunerClass tunerClass = TunerClass.valueOf( descriptor.idVendor(), 
						descriptor.idProduct() );
				switch( tunerClass )
				{
				case AIRSPY:
					return initAirspyTuner( device, descriptor );
				default:
					break;
				}
				//	TunerInitStatus status = initTuner( device, descriptor );
				
			}
		}
	}

	LibUsb.freeDeviceList( deviceList, true );
	return dev;
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:62,代码来源:AirspyDevice.java

示例14: makeDeviceList

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
     * Loads all USB tuners and USB/Mixer tuner devices
     * @throws UsbException 
     */
    public <String>ArrayList makeDeviceList() throws UsbException	{
    	deviceNames = new ArrayList();
    	tunerControllerList = new ArrayList<TunerController>();
    	DeviceList deviceList = new DeviceList();
    	int result = LibUsb.init( null );
    	if( result != LibUsb.SUCCESS ){
    		Log.println( "unable to initialize libusb [" + 
    				LibUsb.errorName( result ) + "]" );
    	} else {
    		Log.println( "LibUSB API Version: " + LibUsb.getApiVersion() );
    		Log.println( "LibUSB Version: " + LibUsb.getVersion() );

    		result = LibUsb.getDeviceList( null, deviceList );

    		if( result < 0 ) {
    			Log.println( "unable to get device list from libusb [" + result + " / " + 
    					LibUsb.errorName( result ) + "]" );
    		} else {
    			Log.println( "discovered [" + result + "] attached USB devices" );
    		}
    	}

    	for( Device device: deviceList ) {
    		DeviceDescriptor descriptor = new DeviceDescriptor();
    		result = LibUsb.getDeviceDescriptor( device, descriptor );
    		if( result != LibUsb.SUCCESS ) {
    			Log.println( "unable to read device descriptor [" + 
    					LibUsb.errorName( result ) + "]" );
    		} else {
    			TunerController dev = initTuner( device, descriptor );
    			if (dev !=null) {
    				deviceNames.add((java.lang.String) dev.name);
    				tunerControllerList.add(dev);
    				StringBuilder sb = new StringBuilder();

    				sb.append( "usb device [" );
    				sb.append( descriptor.idVendor() );
//    				sb.append( String.format( "%04X", descriptor.idVendor() ) );
    				sb.append( ":" );
 //   				sb.append( String.format( "%04X", descriptor.idProduct() ) );
    				sb.append( descriptor.idProduct() );

    				Log.println( sb.toString() );
    			}
    		}
    	}

    	LibUsb.freeDeviceList( deviceList, true );
    	return deviceNames;
    }
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:55,代码来源:TunerManager.java

示例15: main

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