Java libusb/libusb-win32 package Overview
Java libusb package is the Jave encapsulation of libsub and libusb-win32 USB library.
Libusb is designed to create a platform-independent, application-oriented class library for accessing USB devices. Based on the Implementation of C/C ++, third-party interfaces can be easily extended to different operating systems. As an open-source class library, you can obtain relevant information from http://libusb.sourceforge.net/. currently, Linux, FreeBSD, NetBSD, OpenBSD, Darwin, MacOS X, and so on.
Libusb-win32 is the implementation of libusb on Windows operating system. This version of the class library allows users in the Windows environment to not need to be in the kernel mode (with the help of DDK and SDK, and can generate framework development through third-party development tools such as DriverStudio, the core code is developed in Visual C ++ 6.0.) a general solution that allows applications to access USB devices by writing a driver is available at http://libusb-win32.sourceforge.net.
Known Java libusb packages can be used on Linux and Windows, while libusb and Java (both of which have advantages in cross-platform) can be promoted to any operating system.
Implementation
Java libusb package is based on Java Native Interface (Java Local interface, namely JNI) technology by calling the Shared Library (Windows dynamic link library, DLL) and Java class file access libusb/libusb-win32. Class Ch. NTB. USB. libusbjava loads the shared library and provides a local interface to access libusb.
In libusb, the bus structure (including device, configuration, interface, and endpoints) are organized in C Language struct. instantiate a Java object (named usb_xxx) for each struct and save the corresponding information to the Java object. this process is implemented by calling libusbjava. usb_get_busses. After that, information about bus and ancillary devices can be obtained from a Java object in a tree structure.
A simple Class Object device can display a USB device and easily perform read/write operations. errors (errors) and timeouts will throw an exception.
Note that the current class library is a beta version! It has been applied in two of our programs: programming and debugging interface (cypress fx2), lab Board (Experimental Board (AVR at90usb1287 )), both applications use bulk transfers and interrupt transfers and work properly on the test peripherals.
Demonstrate USB View
USB view provides a tree structure view for the existing USB bus. It shows different descriptor parameters, including character descriptors. Based on Swing, usbview only relies on Java basic class libraries (standard Java libraries ).
When you right-click an interface descriptor, you can open another application called "USB testapp", which will display the property value of the device descriptor.
USB testapp
This simple USB test program allows block read/write and interrupt read/write data to the device. It can useOr its own main
Method call.
Instance
The first example (logbus) uses the USB shared library to initialize libusb directly, obtain the object tree representing the related device and descriptor, and print it to the standard output.
The second example (readwrite) demonstrates how to obtain a device instance and useCh. NTB. USB. DeviceClass read/write device. This class hides the libusb method and implements exception handling when an error occurs.
API
The online Java API documentation can be obtained here.
Install Windows manually
Install the libusb-win32 and useTestlibusb-win.exeTest your installation. You must install a custom Device Driver file (INF-file) so that the libusb-win32 can detect your device (see "device installation").
Download the jar and DLL files in "" binaries and source.
Inf usb library Installer (automatic installation)
Another installation method is to run the provided installer to install the USB library for your own device (view "download and installation"). It already contains libusb-win32 files, DLL files in the Java package, and three device drivers we will use.
The installation process follows the steps below:
Install libusb-win32 (CVS build 20060920)
Install the Java wrapper DLL
Install three drivers (. inf-files) for our USB device)
Create an uninstall program and a drive folder containing INF and DLL files.
The installer will ask if you want to change the installation directory at the beginning.
Device Installation)
To use the libusb-win32 as described above, you must first install the device driver (INF file) for your device ). The following two methods (corresponding to the above manual installation and automatic installation) can create such a file.
During manual installation, the name isInf-wizard.exePrograms can be found under the libusb-win32/bin folder. It will generate a device driver file (INF and CAT files) using the device information you provide ). When Windows asks the driver of the device you have inserted, locate the corresponding INF and CAT files. It will install all the files required for the device to work properly on libusb. However,Libusbjava. dllYou need to copy it to Windows/system32/(see the next section ).
You can also modify<Installdir>/driver/The existing INF file under the folder, which is generated by the inf usb library installer. You need[Devices]Modify the manufacturer and product serial number. For example"My devicename" = libusb_dev, USB/vid_1234 & pid_6789The manufacturer serial number is 0x1234, and the product serial number is 0x6789. Automatically install libusb files andLibusbjava. dllInstalledWindows/system32Directory.
To verify that the installation is successful, you can runTestlibusb-win.exe or run USB ViewProgram, you can also find the installed device in the Windows Device Manager.
Linux
Libusb must be installed and run. Make sure that you have sufficient permissions to access the device (view this post ).Build. xmlYou need to install ant first.
Obtain the Linux version source code of libusb and run it (View "binaries and source").
# ant linux
Run in the libusbjava directory. This will create the name libusbjava. so. x. x. X shared library, where X. x. X is the current version, and an identifier is created to link to the database:
# ln -s libusbJava.so.x.x.x libusbJava.so
Note that the library file must be inJava. Library. Path(View JNI-howto for more information ).
Binaries and source (binary and source code files)
You can obtain the Java JAR file here. You can download the Shared Library (Windows DLL) here.
Source files for Java and C ++ can be anonymously retrieved from subversion repository for https://svn.ntb.ch/svninf/ch.ntb.usb.
License)
The Java libusb-win32 package is based on GNU lesser General Public License (lgpl. You can view license information related to libusb-win32 their page on their page.
Feedback and support (feedback and Support)
Please mail Simon pertschy any feedback and support.
Links)
Libusb-win32, supported platforms: win98se, winme, Win2k, WINXP
Libusb, supported platforms: Linux, FreeBSD, NetBSD, OpenBSD, Darwin, MacOS X
Refence: http://inf.ntb.ch/infoportal/help/index.jsp? Topic =/CH. NTB. infoportal/projects_usbinterface.html
Http://libusbjava.sourceforge.net/wp
As well as the original text of the previous article, there are two unread and concurrent articles in the same series.
Translator's note: I have been searching for a long time on the Internet and have been searching for Java USB generic device driver APIs in windows. I have previously found jusb and jsr80 (javax. USB) However, these two available versions only provide implementation in Linux. If you want to return to DDK and Win32 API, you have no idea about device-driven programming and Win32 programming, I can only use OOP to compile a few simple small programs, so I stared at C #. I thought it was all about M $. You should always take care of it, however, there is always only one open-source implementation # libusb (sharplibusb ). In fact, no matter which method, the essence is to call DLL to achieve dynamic call method. Therefore, when Visual Studio 2005 is ready and Java is ready to be put aside for the moment, I want to learn more about libusb. I don't know what solution it provides, I want to search for libusb extensions in Java. I'm also angry. I used Baidu before, but Google couldn't find it. I lost libusb Java, I came up with an article that uses Java to implement the usb api in windows. After reading it, I suddenly realized that there was still this stuff. A sigh cannot be done without entering the door!
It turned out to be an English version. After a whim, I translated it. I was so excited when I first started my translation work, so it was inevitable that I had something hard and inappropriate, I also have a simple understanding of this aspect. If you do not understand the installation, please read the original article. If something goes wrong, please point out that I will continue to modify it.
As for the Java libusb-win32, the original installation method most people have a headache, I simply repeat it, in fact, have made an independent installation program, the next to install on the line, the subsequent steps are also easy. In order to understand the principles and facilitate development, I have benefited a lot from the manual installation.
Finally, all three are required. decompress the package and install only the items in the bin folder. Copy libusb0.dll to Windows/system32 /, copy libusb0.sys to Windows/system32/Drivers/. x64uses the x64packages of these two files, and the inf-wizard.exe file is useful. Pay attention to it. In this example, libusb-win32is installed. You can use testlibusb-win.exe to test the installation. Some information is displayed;
Next install Java on the libusb-win32 package, in fact, to install only a DLL file, let the JNI call function only, copy libusbjava. DLL to Windows/system32/, so it is good.
So how to use it next? The license file. If it cannot be identified by you, you must enter the vendor serial number and product serial number. Step by step, you will get the INF and CAT files. This is the driver of your device, after you install the hardware driver as prompted by windows, direct it to these files, or install the driver of the device from the Device Manager, the driver of your USB device has been installed. You can view it in the Device Manager. This is the manual installation process. If it is automatically installed, there will be a simpler step, and there will also be a way to generate DLL and CAT, which is not considered for the moment.
Then, run the ch. NTB. USB. USB view. usbview, which uses the main method to obtain the display information in the display, and then right-click the descriptor to start usbtestapp. The readers will study the following operations on their own, we recommend that you provide the svn source code and check its online API Doc.
Later I will talk about some development experiences. I am currently trying to develop a Java Desktop Application, so I will learn to use relevant APIs, including printing, serial communication, USB communication, Waveform Drawing, i/O reading and writing, and I/O reading and writing have benefited a lot, but it is also very difficult. Java is not strong in desktop development, although there are some simple things more than 6.0, such as the taskbar icon, to start loading images, Java wants to share a piece of cake on the desktop. As mentioned in an article, it is necessary to enrich the core class library so that developers can use JNI as little as possible, the absorption and guiding role of open-source communities is also dependent on the formulation of the standard APIs. The IDE used in desktop development is mainly netbeans. I use M10 of 5.5 and 6 at the same time. I feel that 6 is greatly improved, and I have been working together with eclipse, integration and componentization are two different trends. Aside from the Intelligence used in basic compilation and debugging (netbeans 6 provides a lot of amazing functions), the two trends cannot succeed even when they reach the extreme, learning from each other and finding the correct balance between each other is what ide needs to work on.
Although the libusb API has been found, whether it can be successfully applied to the project, the parameters to be adjusted for the special hardware chip and the read/write rate to be adapted are still very low, I will not give up the possibility of using WDM to develop a USB driver by myself (although my strength will be impossible mission). Similarly, it is not included in the javax of the standard class library. it is still unknown whether comm is applicable to the actual serial communication product (rxtx was recently found), even in Java. net and other technologies can stand out from the crowd, which is widely used and established as OOP language No. 1. It is still very unclear: I am tired of learning software, A few days ago, I got started with Ruby. I don't know when to get started with Ajax. You can say it's better to learn C ++, but I like Java...
Libusb-win32 temporary uninstall method (in order to use other older versions of the driver, need to uninstall, and later found in the Task Manager uninstall and then immediately install enough, the following method is not always valid .)
Enter the system as a system administrator
Detach a device driver from the Device Manager
Delete
C:/Windows/system32/libusb0.dll
C:/Windows/system32/Drivers/libusb0.sys
Delete an entry in the Registry
HKEY_LOCAL_MACHINE/system/controlset001/control/class/{EB781AAF-9C70-4523-A5DF-642A87ECA567}
HKEY_LOCAL_MACHINE/system/controlset001/services/libusb0
HKEY_LOCAL_MACHINE/system/controlset002/control/class/{EB781AAF-9C70-4523-A5DF-642A87ECA567}
HKEY_LOCAL_MACHINE/system/controlset002/Enum/USB/vid_5345 & pid_1234
The previous item may not be easy to delete. Change the permission and try again.
HKEY_LOCAL_MACHINE/system/controlset002/services/libusb0
HKEY_LOCAL_MACHINE/system/CurrentControlSet/control/class/{EB781AAF-9C70-4523-A5DF-642A87ECA567}
HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/libusb0
Device Drivers for installing new software on Trojan Horse
Restart to identify the driver of the new device.