This demo uses the selected hardware platform as a Libusb class USB device. Libusb-Win32 is a USB Library for the Windows operating systems. The library allows user space applications to access any USB device on Windows in a generic way without writing any line of kernel driver code. This driver allows users to have access to interrupt, bulk, and control transfers directly.
The SimpleLibUSBDemo.exe program and the associated firmware demonstrate how to use the Libusb device drivers for basic general purpose USB data transfer. To make the PC source code as easy to understand as possible, the demo has deliberately been made simple, and only sends/receives small amounts of data.
Before you can run the SimpleLibUSBDemo.exe executable, you will need to have the Microsoft® .NET Framework Version 3.5 Redistributable Package (later versions probably okay, but not tested) installed on your computer. Programs which were built in the Visual Studio® .NET languages require the .NET redistributable package in order to run. The redistributable package can be freely downloaded from Microsoft’s website. Users of Windows Vista® operating systems will not need to install the .NET framework, as it comes pre-installed as part of the operating system.
The source code for SimpleLibUSBDemo.exe file was created in Microsoft Visual C++® 2008 Express Edition. The source code can be found in the “<Install Directory>\ USB Device - Libusb - Generic Driver Demo\ Libusb Simple Demo - Windows Application\Libusb Simple Demo - PC Application - MS VC++ 2008 Express” directory. Microsoft currently distributes Visual C++ 2008 Express Edition for free, and can be downloaded from Microsoft’s website.
To launch the application, simply double click on the executable “SimpleLIbusbDemo.exe” in the “<Install Directory>\USB Device - Libusb - Generic Driver Demo\Windows Application” directory. A window like that shown below should appear:
If instead of this window, an error message pops up while trying to launch the application, it is likely the Microsoft .NET Framework Version 3.5 Redistributable Package has not yet been installed. Please install it and try again.
In order to begin sending/receiving packets to the device, you must first find and “connect” to the device. As configured by default, the application is looking for USB devices with VID = 0x04D8 and PID = 0x0204. The device descriptor in the firmware project meant to be used with this demo uses the same VID/PID. To run the demo program the USB device with the correct precompiled .hex file. If you are connecting the device for the first time, Windows pops up a window asking you to install the driver for the device. When asked for the driver point it to the inf file provided along with the demo. Windows takes while to install the driver for the USB device that is just plugged in. Open the Device manager and ensure that the USB device is listed under the ‘Libusb Demo Devices’. Once the driver is installed hit the “Connect” button, the other pushbuttons should become enabled. If hitting the connect button has no effect, it is likely the USB device is either not connected, or has not been programmed with the correct firmware.
If a different VID/PID combination from the default is desired, then the descriptors in the firmware must be changed as well as the inf file. The easiest way to change the inf file is to use the utility provided with the LibUSB download for windows on the LibUSB website. This utility can create a new inf file based on a connected device. So make sure to change the VID/PID combination first in the firmware, connect the device, and then run the inf file creator utility. After completing the utility, a new signed driver with inf file is created.
Once the driver is installed hit the “Connect” button, the other pushbuttons should become enabled. If hitting the connect button has no effect, it is likely the USB device is either not connected, or has not been programmed with the correct firmware.
Hitting the Toggle LED(s) should send a single packet of general purpose generic data to the Custom class USB peripheral device. The data will arrive on the Bulk OUT endpoint. The firmware has been configured to receive this generic data packet, parse the packet looking for the “Toggle LED(s)” command, and should respond appropriately by controlling the LED(s) on the demo board.
The “Get Pushbutton State” button will send one packet of data over the USB to the peripheral device (to the Bulk OUT endpoint) requesting the current pushbutton state. The firmware will process the received Get Pushbutton State command, and will prepare an appropriate response packet depending upon the pushbutton state.
The PC then requests a packet of data from the device (which will be taken from the Bulk IN endpoint). Once the PC application receives the response packet, it will update the pushbutton state label.
Try experimenting with the application by holding down the appropriate pushbutton on the demo board, and then simultaneously clicking on the “Get Pushbutton State” button. Then try to repeat the process, but this time without holding down the pushbutton on the demo board.
To make for a more fluid and gratifying end user experience, a real USB application would probably want to launch a separate thread to periodically poll the pushbutton state, so as to get updates regularly. This is not done in this simple demo, so as to avoid cluttering the PC application project with source code that is not related to USB communication.
In order to build the application, copy the file <libusb-win32 unzipped folder>\ libusb-win32-device-bin-0.1.12.1\lib\msvc\libusb.lib and paste to ‘lib’ folder of the VC++. Also copy the file
<libusb-win32 unzipped folder>\ libusb-win32-device-bin-0.1.12.1\ include\usb.h and paste to the “<Install Directory>\USB Device - Libusb - Generic Driver Demo\Windows Application\Microsoft VC++ 2008 Express\SimpleLibusbDemo’ folder.
MLA - USB Library Help Version : 2.16
![]() |