USB Hid communication in VB6 (Visual Basic 6)

General discussion on mikroC PRO for PIC.
Author
Message
womai
Posts: 239
Joined: 16 Apr 2008 07:45

USB Hid communication in VB6 (Visual Basic 6)

#1 Post by womai » 18 Sep 2010 02:24

Hello,

I have the PIC18F4550 USB HID demo program (which comes with MikroC Pro) up and running successfully - in the sense that I can send and receive data with the USB HID terminal that is part of the MikroC GUI. However I am having trouble achieving the same within a VB6 program. I already downloaded and tried the USB projects from

http://www.programmersheaven.com/downlo ... nload.aspx
http://www.lvr.com/hidpage.htm
http://www.semifluid.com/?p=23

of course with suitable modifications for device ID etc. But none of them seems to be able to even "see" the PIC (they do see my USB mouse only, while the MikroC HID terminal sees both my mouse and the PIC). I ran the programs in the VB6 debugger to make sure it's not just me comparing to a wrong ID or something similarly stupid - when the programs enumerate all attached devices they simply don't find anything else but the USB mouse...

Does anybody have a VB6(!) program that works with the MikroC USB HID demo and would be willing to share it? Would be highly appreciated!

Just for completeness, I am using the EasyPIC5 development board, and my PC rund Windows XP SP3.

Wolfgang

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: USB Hid communication in VB6 (Visual Basic 6)

#2 Post by p.erasmus » 19 Sep 2010 15:37

Why dont you use Visual Studio express (VB.Net)
it is easier to use with HID and secondly there
are a microchip driver available for HID
in VB.Net
the days of VB6 is past
you can download express from here
http://www.microsoft.com/germany/expres ... fault.aspx
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: USB Hid communication in VB6 (Visual Basic 6)

#3 Post by p.erasmus » 19 Sep 2010 15:41

just take a look at this tread it is done with
vb.net and the MC HID Driver
http://www.mikroe.com/forum/viewtopic.p ... us#p121552
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: USB Hid communication in VB6 (Visual Basic 6)

#4 Post by womai » 20 Sep 2010 00:44

First, thanks for the answer! - I'll give that program a try.

The reason I want to stick with VB6 is that I have a very large code base in VB6, so it would be a huge effort to convert everything to .NET. On the other hand, if I can get HID communication working in VB6 then the amount of changes to my existing software would be minimal. Plus, I have never worked with .NET but am quite familiar with VB6.

Wolfgang

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: USB Hid communication in VB6 (Visual Basic 6)

#5 Post by womai » 21 Sep 2010 00:03

Short update: The MikroC program you link to seems to be outdated - does not even compile in MikroC without a few changes (e.g. some library function names are different).

In any case, I finally got Ian Axelson's HID demo working (which is written in VB6 - hurrah!). My troubles were actually due to a stupid mistake - I assumed the product ID (1234) was decimal, but it's in hex - no wonder the PC program never found my USB PIC... but now it's up and running and working perfectly fine.

Nevertheless, thanks for your taking the time to answer!

Wolfgang

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: USB Hid communication in VB6 (Visual Basic 6)

#6 Post by slavisa.zlatanovic » 21 Sep 2010 11:02

Hi womai!
Short update: The MikroC program you link to seems to be outdated - does not even compile in MikroC without a few changes (e.g. some library function names are different).
There were some changes (improvements) of the USB Library (starting from v3.8).
That's why USB code written in older compiler versions couldn't compile.
See Help for more details and consult HID examples distributed with the compiler.
Best regards
Slavisa

gadelhas
Posts: 77
Joined: 09 Apr 2010 01:09

Re: USB Hid communication in VB6 (Visual Basic 6)

#7 Post by gadelhas » 21 Sep 2010 11:41

womai wrote:
In any case, I finally got Ian Axelson's HID demo working (which is written in VB6 - hurrah!). My troubles were actually due to a stupid mistake - I assumed the product ID (1234) was decimal, but it's in hex - no wonder the PC program never found my USB PIC... but now it's up and running and working perfectly fine.
Wolfgang
Hi, can you put your VB code here, or send it to me? h.oliveira@megamail.pt

Thank you

Regards
Thanks and Regards
Gadelhas

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: USB Hid communication in VB6 (Visual Basic 6)

#8 Post by womai » 21 Sep 2010 17:34

gadelhas wrote:
womai wrote: Hi, can you put your VB code here, or send it to me? h.oliveira@megamail.pt
Time to return some favours. See attached zip file. It contains the VB6 project sources as well as the compiled program. Should work out of the box with the MikroC Pro HID examples (both polled and interrupt version). It will send a block of 64 bytes, but prints only the first 8. Simply start the program, press "Once" and it should automatically detect the device, open the connections, send a block of data and then wait for the echo from the device. It will time out after ~6secs if the device does not answer. Make sure you set the USB jumpers on the development board.

I sure wish MikroE would put out a set of standard PC example apps (with source code!) for USB for the most common development environments - VB6, VB.NET, VCC, Delphi should cover most requirements. The HID terminal is great to prove the microcontroller side is working, but doesn't really get you anywhere for your own application. At least their MikroC USB examples are there, that was already a big help, given than the help file for the USB library commands isn't really explaining much. And having extensive support for USB applications (based on PIC18F2550/4550) in MikroC and MikroBasic would be a very attractive marketing tool for them as well, given that all the world is moving to USB now.


Wolfgang
Attachments
USBHIDIO.zip
(18.09 KiB) Downloaded 3176 times

gadelhas
Posts: 77
Joined: 09 Apr 2010 01:09

Re: USB Hid communication in VB6 (Visual Basic 6)

#9 Post by gadelhas » 21 Sep 2010 22:55

Many thanks womai
Thanks and Regards
Gadelhas

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: USB Hid communication in VB6 (Visual Basic 6)

#10 Post by slavisa.zlatanovic » 22 Sep 2010 13:44

Hi!
I sure wish MikroE would put out a set of standard PC example apps (with source code!) for USB for the most common development environments - VB6, VB.NET, VCC, Delphi should cover most requirements. The HID terminal is great to prove the microcontroller side is working, but doesn't really get you anywhere for your own application. At least their MikroC USB examples are there, that was already a big help, given than the help file for the USB library commands isn't really explaining much. And having extensive support for USB applications (based on PIC18F2550/4550) in MikroC and MikroBasic would be a very attractive marketing tool for them as well, given that all the world is moving to USB now.
I will pass this to our developers.
Thank for suggesting it!
Best regards
Slavisa

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: USB Hid communication in VB6 (Visual Basic 6)

#11 Post by Sobrietytest » 23 Sep 2010 07:22

What a great thread, thanks to Womai and everyone else for their input.

I know that I'm going to face this problem eventually, now it's going to be much easier! Thanks again.

Arag
Posts: 7
Joined: 21 May 2009 22:46

Re: USB Hid communication in VB6 (Visual Basic 6)

#12 Post by Arag » 27 Sep 2010 14:30

Wow amazing!!! Thanks for USBHIDIO.zip!
It is what I was looking for!

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: USB Hid communication in VB6 (Visual Basic 6)

#13 Post by womai » 29 Sep 2010 04:51

Here is an improved version of the HID demo program. It still works with the MikroC Pro HID demos. I cleaned up and stripped down the code. I also made it much more modular - moved all the USB code in a separate code module, and encapsulated the base operations (open and close the connection, write data, read data) in streamlined functions. Basically all you need to do is call the read and write functions to transfer data.

There are 3 buttons - to write some test data and receive back the response (either once, or automatically every second); and a speed test that sends 1000 packets (reports) at once, reads back the echo from the microcontroller, and compares them to see if there were any transmission errors. It prints a report showing the errors as well as the achieved data rate (the theoretical maximum for HID is ~64 KByte/sec and on my machine it gets very close to that).

See attached zip file and screenshots.

Wolfgang
program after startup
program after startup
HID Test 01.PNG (10.47 KiB) Viewed 50617 times
sent and received test data
sent and received test data
HID Test 02.PNG (10.91 KiB) Viewed 50617 times
Attachments
USB HID Test.zip
VB6 project & compiled executable
(47.67 KiB) Downloaded 3570 times
Last edited by womai on 29 Sep 2010 04:53, edited 1 time in total.

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: USB Hid communication in VB6 (Visual Basic 6)

#14 Post by womai » 29 Sep 2010 04:52

speed test
speed test
HID Test 03.PNG (11.49 KiB) Viewed 50616 times

gadelhas
Posts: 77
Joined: 09 Apr 2010 01:09

Re: USB Hid communication in VB6 (Visual Basic 6)

#15 Post by gadelhas » 29 Sep 2010 13:18

Many thanks Womai!!!
Thanks and Regards
Gadelhas

Post Reply

Return to “mikroC PRO for PIC General”