• AVR Freaks

Hot!HID Host Code in VB .Net

Author
evzone
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2007/04/06 00:01:06
  • Location: Greece
  • Status: offline
2009/04/19 23:58:22 (permalink)
0

HID Host Code in VB .Net

Hi,

I am developing an HID device with the 18f2550 microcontroller and I really found it hard to even turn on and off some leds using USB communication. After a lot of search in this forum and in Internet, after reading Jan Axelson's great book USB Complete and after a lot of testing I found an HID .Net library. It has been developed by Mike O'Brien a .Net experienced programmer. Thanks to him it really simplifies the host application code to communicate with an HID device through USB. The link to his site (and the HID library) is http://labs.mike-obrien.net/Document.aspx?id=hidlibrary

I thought it would be very usefull to write a host application in VB .Net that does the same as Microchip's "Generic HID - Simple Demo - PC Software". The system I did all the tests is:
- Windows XP SP3
- Visual Basic 2008 Express
- .Net Framework 3.5 (installed with VB 2008)
- Microchip USB Framework v2.4
- Custom board with PIC18F2550
- PIC firmware: Microchip's Generic HID

I would like to share the host application so everyone wishing to develop an HID device finds a simple starting point. Below is the source code attached.

Just to mention that Jan Axelson has made a great job and offers for free a complete HID solution (both host and firmware code). However USB host code is quite complicated in itself. By putting Mike O'Brien's HID library you can hide all the details for API calling and the code becomes much simpler and easier to understand.

Feel free to send any comments
#1

13 Replies Related Threads

    jarin
    Super Member
    • Total Posts : 845
    • Reward points : 0
    • Joined: 2005/05/23 13:50:02
    • Status: online
    RE: HID Host Code in VB .Net 2009/04/20 01:16:19 (permalink)
    0
    Thank you for your work,

    I didn't find time to try it, but on first sight it looks fine.
    I'm planning to test it with Visual C#, I'll report result, hopefully - if my spare time allows it.

    Jaromir Sukuba, Bratislava, Slovakia
    http://jaromir.xf.cz/  - open source PIC18 debugger.
    #2
    Kabanga
    Super Member
    • Total Posts : 204
    • Reward points : 0
    • Joined: 2007/11/24 13:25:16
    • Location: 0
    • Status: offline
    RE: HID Host Code in VB .Net 2009/04/20 02:20:07 (permalink)
    0
    Hi
    great job. Thanks!
    Kabanga
    #3
    vpatron
    Junior Member
    • Total Posts : 104
    • Reward points : 0
    • Joined: 2009/02/27 13:01:26
    • Location: 0
    • Status: offline
    RE: HID Host Code in VB .Net 2009/04/20 19:53:39 (permalink)
    0
    evzone, thanks so much. This is exactly what I was looking for!

    The .NET code makes it so easy. Thanks again,

    -Vince

    #4
    Ashok0
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2006/07/06 08:08:54
    • Location: Ohio
    • Status: offline
    RE: HID Host Code in VB .Net 2009/04/21 08:23:31 (permalink)
    0
    Nice job, this is really useful, thanks!

    Btw, how difficult would it be to port the HID - PnP Demo to VB .NET? Smile
    #5
    Maerki_DJ
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2009/04/28 10:16:09
    • Location: 0
    • Status: offline
    RE: HID Host Code in VB .Net 2009/04/29 07:27:17 (permalink)
    0
    Hi, nice job evzone !

    It works good when I load the *.hex file on my PIC via the PICkit2 programmer but I can't build my own *.hex file...

    When I want to build the Microphip demo project "USB Device - HID - Simple Custom Demo" (without any modifications) on MPLAB IDE v8.10 it tells me the following error :

    Build Output :
    ----------------------------------------------------------------------
    Release build of project `C:\Users\david\Documents\Bobs t SA\TIP 2009\Programmation\USB\Program mation PIC\USB Device - HID - Simple Custom Demo\Generic HID - Simple Demo - Firmware\USB Device - HID - Simple Custom Demo - C18 - PICDEM FSUSB.mcp' started.
    Wed Apr 29 13:55:33 2009
    ----------------------------------------------------------------------
    Clean: Deleting intermediary and output files.
    Clean Warning: File "C:\Users\david\Documents\Bobs t SA\TIP 2009\Programmation\USB\Program mation PIC\USB Device - HID - Simple Custom Demo\Generic HID - Simple Demo - Firmware\Objects\USB Device - HID - Simple Custom Demo\usb_descriptors.o" doesn't exist.
    Clean Warning: File "C:\Users\david\Documents\Bobs t SA\TIP 2009\Programmation\USB\Program mation PIC\USB Device - HID - Simple Custom Demo\Generic HID - Simple Demo - Firmware\Objects\USB Device - HID - Simple Custom Demo\main.o" doesn't exist.
    Clean Warning: File "C:\Users\david\Documents\Bobs t SA\TIP 2009\Programmation\USB\Program mation PIC\USB Device - HID - Simple Custom Demo\Generic HID - Simple Demo - Firmware\Objects\USB Device - HID - Simple Custom Demo\usb_function_hid.o" doesn't exist.
    Clean Warning: File "C:\Users\david\Documents\Bobs t SA\TIP 2009\Programmation\USB\Program mation PIC\USB Device - HID - Simple Custom Demo\Generic HID - Simple Demo - Firmware\Objects\USB Device - HID - Simple Custom Demo\usb_device.o" doesn't exist.
    Clean: Done.
    Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4550 /i"." -I".." -I"..\..\Include" -I"..\..\..\Include" -I"..\..\Microchip\Include" -I"..\..\USB Device - HID - Simple Custom Demo" -I"..\..\..\USB Device - HID - Simple Custom Demo" "usb_descriptors.c" -fo=".\Objects\USB Device - HID - Simple Custom Demo\usb_descriptors.o" -pa=4
    MPLAB-C18 v1.0 Copyright 1999 Microchip Technology Inc.
    Unknown processor '18F4550'
    Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4550 /i"." -I".." -I"..\..\Include" -I"..\..\..\Include" -I"..\..\Microchip\Include" -I"..\..\USB Device - HID - Simple Custom Demo" -I"..\..\..\USB Device - HID - Simple Custom Demo" "main.c" -fo=".\Objects\USB Device - HID - Simple Custom Demo\main.o" -pa=4
    MPLAB-C18 v1.0 Copyright 1999 Microchip Technology Inc.
    Unknown processor '18F4550'
    Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4550 /i"." -I".." -I"..\..\Include" -I"..\..\..\Include" -I"..\..\Microchip\Include" -I"..\..\USB Device - HID - Simple Custom Demo" -I"..\..\..\USB Device - HID - Simple Custom Demo" "..\..\Microchip\USB\HID Device Driver\usb_function_hid.c" -fo=".\Objects\USB Device - HID - Simple Custom Demo\usb_function_hid.o" -pa=4
    MPLAB-C18 v1.0 Copyright 1999 Microchip Technology Inc.
    Unknown processor '18F4550'
    Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4550 /i"." -I".." -I"..\..\Include" -I"..\..\..\Include" -I"..\..\Microchip\Include" -I"..\..\USB Device - HID - Simple Custom Demo" -I"..\..\..\USB Device - HID - Simple Custom Demo" "..\..\Microchip\USB\usb_devic e.c" -fo=".\Objects\USB Device - HID - Simple Custom Demo\usb_device.o" -pa=4
    MPLAB-C18 v1.0 Copyright 1999 Microchip Technology Inc.
    Unknown processor '18F4550'
    Executing: "C:\MCC18\bin\mplink.exe" /l"C:\mcc18\lib" "rm18f4550 - HID Bootload.lkr" "Objects\USB Device - HID - Simple Custom Demo\usb_descriptors.o" "Objects\USB Device - HID - Simple Custom Demo\main.o" "Objects\USB Device - HID - Simple Custom Demo\usb_function_hid.o" "Objects\USB Device - HID - Simple Custom Demo\usb_device.o" /u_CRUNTIME /z__MPLAB_BUILD=1 /m"USB Device - HID - Simple Custom Demo - C18 - PICDEM FSUSB.map" /w /o"USB Device - HID - Simple Custom Demo - C18 - PICDEM FSUSB.cof"
    MPLINK 3.00, Linker
    Copyright (c) 2002 Microchip Technology Inc.
    Error - unknown switch: /u_CRUNTIME
    Errors : 1

    Link step failed.
    ----------------------------------------------------------------------
    Release build of project `C:\Users\david\Documents\Bobs t SA\TIP 2009\Programmation\USB\Program mation PIC\USB Device - HID - Simple Custom Demo\Generic HID - Simple Demo - Firmware\USB Device - HID - Simple Custom Demo - C18 - PICDEM FSUSB.mcp' failed.
    Wed Apr 29 13:55:34 2009
    ----------------------------------------------------------------------
    BUILD FAILED

      Thanks very much for your help !

    - Märki DJ -
    #6
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: HID Host Code in VB .Net 2009/04/29 07:53:45 (permalink)
    0

    MPLAB-C18 v1.0 Copyright 1999 Microchip Technology Inc.


    Where did you get this ancient compiler? grin
    You need to get the later version of Microchip C18. You can download the student version for free here.
    http://www.microchip.com/c18

      USB_Links and libusb
    #7
    evzone
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2007/04/06 00:01:06
    • Location: Greece
    • Status: offline
    RE: HID Host Code in VB .Net 2009/05/02 06:55:56 (permalink)
    0
    ORIGINAL: xiaofan


    MPLAB-C18 v1.0 Copyright 1999 Microchip Technology Inc.


    Where did you get this ancient compiler? grin
    You need to get the later version of Microchip C18. You can download the student version for free here.
    http://www.microchip.com/c18


    xiaofan is right! I am using MPLAB IDE 8.10 with MPLAB C18 3.10. So you need to get at least this version or better the latest.
    #8
    etasigma
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2010/05/21 14:43:57
    • Location: 0
    • Status: offline
    RE: HID Host Code in VB .Net 2010/05/21 14:53:33 (permalink)
    0
    I know this post is kind of old, but it is exactly what I was looking for.  I have read Jan's book and downloaded his HID code for use in an application I am writing.  I have been successful in connecting and reading from my PIC24 Microchip via the USB.  The one thing that seems to be eluding me is the ability to toggle the LED on the board.  If I use the Generic HID Sample that is written in C++ from Microchip, it connects to my device and toggles the light perfectly.  I downloaded your application, which is very succinct (thank you very much :D ), changed the VID and PID to my device and attempted to toggle the LED.  It connects fine but doesn't toggle the LED as I had hoped.  I am unsure why the C++ application will do it and the VB.NET application won't.  I don't have access to the firmware code at this time.  I was hoping that since the C++ application worked that I could assume that the VB.NET application would too.  That doesn't seem to be the case.  Anyone have any suggestions?
    #9
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: HID Host Code in VB .Net 2010/05/21 16:04:38 (permalink)
    0
    *her* Smilewink

    GENOVA :D :D ! GODO
    #10
    etasigma
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2010/05/21 14:43:57
    • Location: 0
    • Status: offline
    RE: HID Host Code in VB .Net 2010/05/24 09:04:47 (permalink)
    0
    I never caught that Jan was female.  The name should have given it away.  Thanks!
    #11
    EJ_ZARA
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2018/04/04 18:23:46
    • Location: 0
    • Status: offline
    Re: RE: HID Host Code in VB .Net 2018/10/05 00:40:02 (permalink)
    0
    Good Day,
      I tried the code using the PIC32 USB STARTER KIT II, I did some modification and it works. Right now, I made a new vb.net with updated MetroFramework design and i used the the same code. My problem is it cannot connect to the PIC like the your vb.net. Any tips why it doesn't work?
     
    Here is the Error
    An unhandled exception of type 'System.NullReferenceException' occurred in HID Project.exe
    Additional information: Object reference not set to an instance of an object.
     
    It is pointed to the line
     "Dim OutData(HidPIC32.Capabilities.OutputReportByteLength - 1) As Byte"
    post edited by EJ_ZARA - 2018/10/05 00:59:46
    #12
    nobbyv
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/05/01 09:07:23
    • Location: 0
    • Status: offline
    Re: RE: HID Host Code in VB .Net 2019/05/07 06:06:59 (permalink)
    0
    I tried this code but can’t find any HID devices on my system. HID device list always comes back with a length of 0. I have multiple HID devices connected to my system (mouse, touchscreen) and have changed the PIDs to their PIDs, but with no luck. What could I be doing wrong?
     
    EDIT for anyone that finds this: the project MUST be set to 32-bit (x86). Won't work for x64. 
    post edited by nobbyv - 2019/05/21 06:42:21
    #13
    nobbyv
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/05/01 09:07:23
    • Location: 0
    • Status: offline
    Re: RE: HID Host Code in VB .Net 2019/06/06 10:42:58 (permalink)
    0
    Does anyone know what version of the .NET framework the library here is compiled for? I can't get any of the latest versions of this library from Mike O'Brien's GitHub repo to run, but this one works fine. 
    #14
    Jump to:
    © 2019 APG vNext Commercial Version 4.5