Navigation

Skip Navigation Links
Home
Contact
ElectronicsExpand Electronics
SoftwareExpand Software

 Login

USB HID Template for Visual Basic 2005

Introduction

With the decline of serial and parallel ports from modern computers, electronics hobbyists are turning more to utilizing USB (or stick with old computers for their legacy ports). Unfortunately, unlike serial and parallel ports, USB is far from simple and so it can be daunting to try to develop hardware and software for it. However, there are many hardware and software solutions that make developing USB device much simpler.

 

Some PIC microcontrollers now come with a USB Serial Interface Engine (SIE) that handles the very low level parts of the interface. However, writing firmware to work with the SIE can still be a difficult task. Luckily, many PIC compilers come with USB libraries that work out of the box and are dead easy to use. The code generated by these compilers tends to produce a USB Human Interface Device (HID) as these devices do not require custom drivers to be written because Windows has them preinstalled. However, you still need to write your own PC software to read and write data from your USB device. This article shows you how to do this.

Visual Basic Template

The Visual Basic template, which you can download at the bottom of the page, generates the basic code framework that is needed to interface with your USB device. All you need to do is set the VID, PID and buffer sizes going into and out from the PC. After that you’re ready to read and write data.

 

To give credit where credit is due, I did not write the code that is in the template – the code is based on the code generated by the EasyHID application from Mecanique and modified for Visual Basic 2005 by Steve Monfette. I modified his code a little, wrote some documentation and packaged it into a VB template.

Installing

Installing the template is simple. Download and extract the archive and you will find two files: USBTemplate.zip and mcHID.dll. Copy mcHID.dll to your windows\system32 folder and copy USBTemplate.zip (copy the actual zip file – do not extract it) to your My Documents\Visual Studio 2005\Templates\ProjectTemplates.

Using the Template

After installation, load up Visual Basic 2005 and create a new project. When the New Project dialog opens, you should see the USBTemplate option at the bottom.

 

Select it, give your project a name and then click on OK. Visual Basic creates the basic code framework for you.

 

The following files are created and can be found in the Solution Explorer:

 

1-    frmUSB: This is the main form where USB communication takes place.

2-    mcHIDInterface: Contains the underlying code.

3-    HOW TO USE: Contains instructions on how to use the template.

The only file which you need to modify is frmUSB.

Download

The template and the DLL file can be downloaded below:

USB HID Template for Visual Basic 2005 

© 2006 Amr Bekhit