PDA

View Full Version : EasyHID and USB for Newbies??



Squibcakes
- 3rd January 2006, 07:22
Hi All,

Any info to help a newbie would be greatfully received. How to use EasyHID software and program a USB microchip?

Basically, I would love to replace my old 'mock-up' joystick (connected to rudder pedals) that use the PC game port and build a USB controller.... for starters ;) I heard that USB has better accuracy than the game port.

Cheers
Oh, and Happy New Year too. :-)

Demon
- 9th January 2006, 04:41
Good luck getting it all together. I got myself a 18F4550, EasyHID and gave it my best shot, but it kinda came up a little short. I followed all the steps, but there are still 'things' missing.

There's several threads here explaining the process, but I couldn't find one that spelled it ALL out (last time I looked was a few months ago, maybe new data out now).

Please post a follow-up on your progress.

Robert
:)

Squibcakes
- 10th January 2006, 03:55
Hi Rob,

Yep, I'm still waiting for (as you say) someone to spell it out. Hahaha.

I'm a bit hesitent to buy one of these chips until I have all the facts and a pretty good 'How to' Guide.

Thanks for your comments
J

mister_e
- 10th January 2006, 04:09
Since cash is involve and you don't want to loose any of these green crispy money bill, GOOD NEWS (not really a news but) YOU Don't need to buy them... Microchip offer Free demo... see their website and open an account. Free of charge, freee shipping and blah blah... yeah of course there's some limitation in the quantity but... it's still free.



I'm a bit hesitent to buy one of these chips until I have all the facts and a pretty good 'How to' Guide.

It will never hurt to try
They will never bite you
The worst case, you'll learn something new OR, also possible, waste your time.

Demon
- 10th January 2006, 21:30
Hi J,

Yup, as Steve said, MicroChips offer free samples. I've already ordered many chips from them that way; no hassle, no questions, fast shipping (from Malaysia I believe, took 3 days). I recommend the 18F4550, it looks a lot like the 16F877, but has more bells and whistles.

As soon as I figure this out, I'll report back here with my findings like I did for the graphic LCD. So far I haven't been able to find all the pieces to the puzzle. It's not a matter of them being spread out over several threads or sites, I have no problem with searching. There's 'some' information that people are just not posting. I suspect it's the PC side that is incomplete in the examples I've seen so far.

All I need is a working example of sending a keystroke, I can take it from there. But by the way things appear, I'll probably have to dish out $600 for that specialized software that is supposed to spit it all out; PIC and PC code. I just don't have that kind of money lying around...

http://www.tracesystemsinc.com/usb_tools.ivnu

Robert
:(

Demon
- 10th January 2006, 21:38
The software is ordered here:
http://cippsites.com/Merchant4/merchant.mvc?Screen=PROD&Product_Code=HIDFS&Category_Code=NEW&Store_Code=melabs

Robert
:)

lester
- 14th January 2006, 18:25
EasyHID Wizard is completely free. It is not time limited in any way and it does not have any nag screens!

http://www.mecanique.co.uk/products/usb/easyhid.html

Demon
- 15th January 2006, 02:14
Been there done that, still can't get it to work. It's like some stuff is still missing. I tried making a simple keyboard using the examples that are floating about in here and several other sites, couldn't get it happening after a lot of hours.

So I gave up until I'll have enough money for the software, which ain't tomorrow...

Robert
:(

Squibcakes
- 23rd January 2006, 01:55
Hi Rob,

That HIDMaker FS Software looks really good... but I would have to sell the House Cat in order to afford it!

What we really want is a step by step guide how to write USB code in Picbasic Pro.

Easy HID is a good start but as you say, there are too many blanks.

I ordered my free chips from Micro chip... thanks for the Tip.

Cheers
Jared

Demon
- 23rd January 2006, 04:33
Jared,

I might be able to get it and still keep my 2 house cats, Garfield and Scotchtape. :) I have a cheque coming in for a yet unknown amount of money, hoping for a late Christmas present from the gods.

I'll report back with a basic skeleton if I'm lucky; at least a simple transmission of one byte from the PIC to PC. Once you have a working sample running, it shouldn't be hard to increase bufer size to custom spec. My application is simulating a keyboard, so I only need one VB command to simulate a keystroke (or sequence of keystrokes).

I'm still unsure on how much PC-side material this software will deliver. If I had been smart, I would have spent the last month or so putzing around with Visual Basic, getting myself familiar with its intricacies. I know BASIC, but VB has a lot more power to it, let alone all the Windows crap that goes along with it.

But hey, procrastination is my middle name...

Robert
:)

Squibcakes
- 24th January 2006, 00:28
Robert,

Garfield and ScotchTape, Let me guess, one cat is Fat and Lazy, the other is a Skinny Minnie and very loud?! haha

Our cat is the later.

I digress, Yep, I rekon if we can simulate a key press, it should be a sinch from there.

Cheers
J

sean-h
- 6th February 2006, 20:29
Using easyhid is not that bad.

Basic steps are run up the easyhid program and set the basics like Pid/Vid and buffer size for bytes you want to send back and forth from PC to Pic.

It then by default creates two folders under a top level folder called USBProject

The first folder is PICBasicPRO

This contains the basic code you will need for your pic chip and the include files, do not rename or move this directory once it is created, work from this location.
It will create a example PBP file called USBProject.pbp

So open this up and the main program loop you are interested in is:


'****************************************
usbinit ' initialise USB...

ProgramStart:

gosub DoUSBIn
gosub DoUSBOut

goto ProgramStart
'*****************************************

For receving and sending data you just need these two routines.

If you wanted to receive say 10 bytes then it does matter that your buffer is set to 64 bytes because that is the packet size that is going to be received from the PC anyway, so do not worry about this. Just tell it to jump off to that routine and as soon as data is received it will come back from that routine with the usbbuffer(0) to usbbuffer(63) filled as such.
So if your PC sent 10 bytes then the variables usbbuffer(0-9) will hold those 10 bytes, if your pc sent 20 bytes then usbbuffer(0-19) will hold those bytes.

So say you wanted to send 4bytes from your PC to the Pic and then the Pic displays it on the LCD, you could do this:

'*******************************************
usbinit ' initialise USB...
ProgramStart:

gosub DoUSBIn

LCDOUT $FE,1,usbbuffer(0),usbbuffer(1),usbbuffer(2),usbbu ffer(3)

goto ProgramStart
'*******************************************

If you then wanted to send say two bytes back to the PC to say you received them, then just load up your usbbuffer variables and jump to the routine gosub DoUSBOut.

So to send "OK" back to the PC add this to your code.

'*******************************************
usbinit ' initialise USB...
ProgramStart:

gosub DoUSBIn

LCDOUT $FE,1,usbbuffer(0),usbbuffer(1),usbbuffer(2),usbbu ffer(3)

usbbuffer(0)=79 'Ascii value for O
usbbuffer(1)=75 'Ascii value for K
gosub DoUSBOut

goto ProgramStart
'*******************************************

And thats ya simple pic code to receive and send bytes back and forth. Now you know how to get your bytes in and out, you can use them just like any other variables.

The Second Folder it creates is dependent on what you are developing in, I play with Visual Basic so it created me a Folder called VisualBasic and inside here is sample code and the files you will need, I aslo copy the file mcHID.dll from C:\Program Files\Mecanique\EasyHID\ into this folder as well to play safe.

So again for the VB side of things to send data out to the Pic via the USB Port you simply load up the Bufferout(1-64) you always send Bufferout(0)=0 as a header.

So to send 4 bytes from Visual Basic just use the following:

'*******************************************

BufferOut(0) = 0
BufferOut(1) = 68 'Ascii Value for D
BufferOut(2) = 65 'Ascii Value for A
BufferOut(3) = 84 'Ascii Value for T
BufferOut(4) = 65 'Ascii Value for A
hidWriteEx VendorID, ProductID, BufferOut(0)

'*******************************************

To receive Data in VB, the sample code basically sits there and waits for a recieve event to happen and when it does, it jumps off to a routine called OnRead and populates the variables BufferIn(1-64).

So you could do a simple loop to keep checking the value of BufferIn(1) and BufferIn(2) until they receive the "OK\2 back.
To see it in action set up a object called Text1.Text on your VB Form and then in your code add the following:
'*******************************************

Text1.Text = Chr(Val(BufferIn(1)))
Text1.Text = Text9.Text & Chr(Val(BufferIn(2)))

'*******************************************

Hope this helps.

Regards Sean.

Demon
- 10th February 2006, 01:00
Thanks Sean, but like I posted back on Jan 10th that's not quite it. There's gotta be more required on the PC side. That code just doesn't sit in a text file, it has to be compiled or something. That's where all the USB threads come up short. Either everyone is assuming a whole bunch about what we 'should' know, or I'm too dense and just not getting something obvious...

Robert
:(

sean-h
- 10th February 2006, 11:15
Hi Robert

When you say more PC side, yep you are correct, you will need a copy of Visual Basic for the code example above and at least know the basics of creating a windows application.

There are a number of different development packages out there for writing your own windows applications, such as Visual Basic, Delphi, Visual C++ or the newer .NET .

The sample code created by easy HID is for the first 3 development platforms listed bove.

So first you need to get a development package, then you need to learn how to use it. Visual Basic to me has always been the easiest, have played with Delphi a little.

When you have your development package you can then start learning how to write your own applications, and there are literaly thousands of development websites where other guys have already came across any problems that you will encounter and also would of posted sample code to help you out.

Regards

Sean.


Thanks Sean, but like I posted back on Jan 10th that's not quite it. There's gotta be more required on the PC side. That code just doesn't sit in a text file, it has to be compiled or something. That's where all the USB threads come up short. Either everyone is assuming a whole bunch about what we 'should' know, or I'm too dense and just not getting something obvious...

Robert
:(

Demon
- 10th February 2006, 14:47
Thanks Sean, that explains it more.

I'm also very interested in VB, I have VB Express installed already. What's the big difference between Visual Basic Express and uh, the 'regular' version?

I keep seeing that .NET mentionned, but I have no idea what that implies. I don't want my application to be dependant on having .NET installed on a PC. I'm interested in a basic 'keyboard' type application that can be connected to a PC with minimal requirements.

Is VB Express the proper tool for me?

Robert
:)

sean-h
- 10th February 2006, 15:12
Visual Basic Express is the cutdown version of VB.net or Visual basic 2005 as it is now called, I even struggle to keep up with the latest versions must admit, good old Mircosoft!!

VB5 and VB6 have been very popular and used alot over the years, but as life moves on, like any other develpment tools they get upgraded to suit the latest operating systems.

I have tried to migrate a few of my applications to Visual basic 2005 from VB6 but it falls over on a few bits of code and so personaly I stick to VB6 for now, but no dought I will have to find time and force myself to look at VB2005 in more depth one day.

I have no idea what they have taken out of VB Express 2005 compared to what is in the full version.
You are best to check the Microsoft site.

Years ago VB6 came in several flavours and the low end version release did not include the Comm components, so for example you could not write applications that used the serial port, without either upgrading or getting the extra components from somewhere else.

I know the sample code that gets produced with EasyHid is for VB5 but it works fine in VB6. It did not work in Visual Basic 2005 for me when trying to do a quick conversion, but I am sure with a bit of time and tweaking it hopefully will.

Regards

Sean.

Demon
- 11th February 2006, 04:45
Hmm, HIDmaker came in today. I checked through the user's manual and it says the code is made for VB6.

So now I'm not really sure what I should do: risk that what I will develop will work on VBexpress, or buy VB6 (investing in something else that is already obsolete, which may very well be dropped by HIDmaker soon).

VBexpress was free...

Robert
:(

dmairspotter
- 11th February 2006, 17:05
VB.net or whatever you want to call it is no doubt the next generation, but VB6 is still around and is very robust.I do quite a bit of work with it and I find it has very few shortcomings for what I do. Programs compile and run seamlessly on all versions of Windows from 98 to XP pro, NT and 2000, Have not tried it on 64 bit Windows as of yet.

If you can get VB6 for a reasonable price I wouldn't hesitate to get started with it. Make sure you patch it with the latest service pack (6).

Demon
- 11th February 2006, 17:24
I found this auction on EBay, but something is fishy:

http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&item=5865411973

The price is WAAAAAY too good to be true compared to other auctions for VB6, and the PRO version too. Does that look like it's a copy? Since when are cd keys contained on the disk? Usually with MicroSoft they are on stickers.

Robert
:)

ferds
- 12th February 2006, 15:53
hi

dont buy this item , read the feedback of the seller and you will see that the seller has a bad reps.

best regards,
ferds

rocky79
- 20th February 2006, 22:58
Using easyhid is not that bad.

Basic steps are run up the easyhid program and set the basics like Pid/Vid and buffer size for bytes you want to send back and forth from PC to Pic.

It then by default creates two folders under a top level folder called USBProject

The first folder is PICBasicPRO

This contains the basic code you will need for your pic chip and the include files, do not rename or move this directory once it is created, work from this location.
It will create a example PBP file called USBProject.pbp

So open this up and the main program loop you are interested in is:


'****************************************
usbinit ' initialise USB...

ProgramStart:

gosub DoUSBIn
gosub DoUSBOut

goto ProgramStart
'*****************************************

For receving and sending data you just need these two routines.

If you wanted to receive say 10 bytes then it does matter that your buffer is set to 64 bytes because that is the packet size that is going to be received from the PC anyway, so do not worry about this. Just tell it to jump off to that routine and as soon as data is received it will come back from that routine with the usbbuffer(0) to usbbuffer(63) filled as such.
So if your PC sent 10 bytes then the variables usbbuffer(0-9) will hold those 10 bytes, if your pc sent 20 bytes then usbbuffer(0-19) will hold those bytes.

So say you wanted to send 4bytes from your PC to the Pic and then the Pic displays it on the LCD, you could do this:

'*******************************************
usbinit ' initialise USB...
ProgramStart:

gosub DoUSBIn

LCDOUT $FE,1,usbbuffer(0),usbbuffer(1),usbbuffer(2),usbbu ffer(3)

goto ProgramStart
'*******************************************

If you then wanted to send say two bytes back to the PC to say you received them, then just load up your usbbuffer variables and jump to the routine gosub DoUSBOut.

So to send "OK" back to the PC add this to your code.

'*******************************************
usbinit ' initialise USB...
ProgramStart:

gosub DoUSBIn

LCDOUT $FE,1,usbbuffer(0),usbbuffer(1),usbbuffer(2),usbbu ffer(3)

usbbuffer(0)=79 'Ascii value for O
usbbuffer(1)=75 'Ascii value for K
gosub DoUSBOut

goto ProgramStart
'*******************************************

And thats ya simple pic code to receive and send bytes back and forth. Now you know how to get your bytes in and out, you can use them just like any other variables.

The Second Folder it creates is dependent on what you are developing in, I play with Visual Basic so it created me a Folder called VisualBasic and inside here is sample code and the files you will need, I aslo copy the file mcHID.dll from C:\Program Files\Mecanique\EasyHID\ into this folder as well to play safe.

So again for the VB side of things to send data out to the Pic via the USB Port you simply load up the Bufferout(1-64) you always send Bufferout(0)=0 as a header.

So to send 4 bytes from Visual Basic just use the following:

'*******************************************

BufferOut(0) = 0
BufferOut(1) = 68 'Ascii Value for D
BufferOut(2) = 65 'Ascii Value for A
BufferOut(3) = 84 'Ascii Value for T
BufferOut(4) = 65 'Ascii Value for A
hidWriteEx VendorID, ProductID, BufferOut(0)

'*******************************************

To receive Data in VB, the sample code basically sits there and waits for a recieve event to happen and when it does, it jumps off to a routine called OnRead and populates the variables BufferIn(1-64).

So you could do a simple loop to keep checking the value of BufferIn(1) and BufferIn(2) until they receive the "OK\2 back.
To see it in action set up a object called Text1.Text on your VB Form and then in your code add the following:
'*******************************************

Text1.Text = Chr(Val(BufferIn(1)))
Text1.Text = Text9.Text & Chr(Val(BufferIn(2)))

'*******************************************

Hope this helps.

Regards Sean.



Hi Sean,

If i want to write a byte to the microncontroller can i say BufferOut(2)=%10011111 (" for example)
In your code above:
BufferOut(1) = 68 'Ascii Value for D
BufferOut(2) = 65 'Ascii Value for A
BufferOut(3) = 84 'Ascii Value for T
BufferOut(4) = 65 'Ascii Value for A
hidWriteEx VendorID, ProductID, BufferOut(0)
and to send the info,
are you sending BufferOut(2), BufferOut(3)....and so on?
if i wanna send the values in bufferout(2) would the code look like this below?
hidWriteEx(VendorID, ProductID, BufferOut(0),BufferOut(2) )


Thanks much

sean-h
- 21st February 2006, 09:05
Hi rocky

When you call hidWriteEx(VendorID, ProductID, BufferOut(0)), what you are doing is sending a packet as such out to the USB port.
So you can define the length of that buffer in your VB vode at the top of the code:
Private Const BufferInSize = 64
Private Const BufferOutSize = 64

and in your PBP code:

USBBufferSizeMax con 64 ' maximum buffer size
USBBufferSizeTX con 64 ' input
USBBufferSizeRX con 64 ' output

I think min is 8 bytes and max 64.

So just change these variables to cut down the amount of bytes you want to send.

BufferOut(0) is a report ID and data starts at BufferOut(1)

Regards

Sean.





Hi Sean,

If i want to write a byte to the microncontroller can i say BufferOut(2)=%10011111 (" for example)
In your code above:
BufferOut(1) = 68 'Ascii Value for D
BufferOut(2) = 65 'Ascii Value for A
BufferOut(3) = 84 'Ascii Value for T
BufferOut(4) = 65 'Ascii Value for A
hidWriteEx VendorID, ProductID, BufferOut(0)
and to send the info,
are you sending BufferOut(2), BufferOut(3)....and so on?
if i wanna send the values in bufferout(2) would the code look like this below?
hidWriteEx(VendorID, ProductID, BufferOut(0),BufferOut(2) )


Thanks much

sean-h
- 21st February 2006, 10:40
Hi Rocky

Sorry forgot to answer this bit


If i want to write a byte to the microncontroller can i say BufferOut(2)=%10011111 (" for example)

In VB you will need to convert your Binary value to Decimal and then load your Bufferout(2) variable.

Here is a nice feunction example for Visual Basic

http://www.vb-helper.com/howto_decimal_to_binary.html

Regards

Sean.

rocky79
- 22nd February 2006, 06:46
Thanks Sean for the explanation, but there is still something i don't understand.
Question#1:
On the microcontroller side: How can i send the results of a 12 bits A2d Signal from the microcontroller to visual basic.net since USBBufferout is defined as a byte.
Question#2
on the Visual basic.net side when your ready to send data back to the controller:
do you just include all the 64 bufferout bufferout(1) bufferout(2)....bufferout(63)
HidWriteEx, VendorId, ProductID, BufferOut(0), BufferOut(1)....BufferOut(63)
Or is there a shorter way to do it.

Thanks Sean

rocky79
- 22nd February 2006, 06:50
Question#2:
On the visual studio.net side: In this code below that i got from EasyHid how do you fill in where it says: put your code here?
I would appreciate Any examples:

Public Sub OnPlugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
End If
End Sub

'************************************************* ****************
' a HID device has been unplugged...
'************************************************* ****************
Public Sub OnUnplugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
End If
End Sub

'************************************************* ****************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'************************************************* ****************
Public Sub OnChanged()
Dim DeviceHandle As Integer

' get the handle of the device we are interested in, then set
' its read notify flag to true - this ensures you get a read
' notification message when there is some data to read...
DeviceHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify(DeviceHandle, True)
End Sub

'************************************************* ****************
' on read event...
'************************************************* ****************
Public Sub OnRead(ByVal pHandle As Integer)

' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontrolller...
End If
End Sub

'************************************************* ****************
' this is how you write some data...
'************************************************* ****************
Public Sub WriteSomeData()
BufferOut(0) = 0 ' first byte is always the report ID
BufferOut(1) = 10 ' first data item, etc etc

' write the data (don't forget, pass the whole array)...
hidWriteEx(VendorID, ProductID, BufferOut(0))
End Sub
End Class

sean-h
- 22nd February 2006, 13:01
Thanks Sean for the explanation, but there is still something i don't understand.
Question#1:
On the microcontroller side: How can i send the results of a 12 bits A2d Signal from the microcontroller to visual basic.net since USBBufferout is defined as a byte.


A byte is only 8 bits so you will have to store your result in a variable defined as a Word (16bits)
Now you will need to split the word and send the highbyte and lowbyte out as two bytes.
In your VB program you will then need to take the 2 bytes and joing them back as a word.



Question#2
on the Visual basic.net side when your ready to send data back to the controller:
do you just include all the 64 bufferout bufferout(1) bufferout(2)....bufferout(63)
HidWriteEx, VendorId, ProductID, BufferOut(0), BufferOut(1)....BufferOut(63)
Or is there a shorter way to do it.


Re-read what I wrote above regards data being sent from VB. when you call HidWriteEx, VendorId, ProductID, BufferOut(0) you are telling the USB port to send all the data in the BufferOut.
So if you have defined your BufferOut as being 64 bytes long then when you call HidWriteEx it will send all 64 bytes, if you defined your BufferOut as being 8bytes long then it will send 8 bytes.

So simply load all the buffers up with the bytes you want and call HidWriteEx when you want to send.

Regards

Sean.

sean-h
- 22nd February 2006, 13:13
Hi Rocky

I got compile errors in VB2005 so sticking with VB6, does it compile okay with ,net your end?

The two main routines to worry about and get you going are receive and transmit Data Routines.

Please scroll up on this post as I have given some VB examples already on what you have just asked.

Regards

Sean.

rocky79
- 28th February 2006, 08:45
sean,
Sorry for the late reply, my computer crashed so i was crippled for the past week. I will try your code as soon as i get things back in place.
thank you much

scorpion
- 28th February 2006, 19:54
Hi
I was wondering what I might be doing wrong...
I used HIDMaker to make an input device. Im using the standard HID descriptors, so I am not writting any PC side software.
Everything is working well, but I have two analog inputs. They are both set to words so i can use the 10bit a/d. but when I look at the input on the computer its only 8 bit. and if i right justify the results i am only getting a change of 3.... which is what i would expect if it was only sending 8 bits.

hrm........
if i do some math (invert one input) i can offset the output to 10 bits, so is my a/d conversion 8 bits?

I have used 10 bit inputs on other projects with other pics and I have never ran into this problem before.

I have everything set up.

DEFINE adc_bits 10
TRISA = 255
TRISB = 255
ADCON0 = 0
ADCON1 = %00001101

does anyone have any idea what im doing wrong?

PJALM
- 28th February 2006, 21:20
USB can only send bytes not words so divide your word into 2 bytes to send to the pc (Byte.HiByte & Byte.LowByte), on the PC side simply convert these 2 bytes back to a Long variable and everything should be fine.

I hope this helps.

scorpion
- 28th February 2006, 21:32
I wish I could say it did help
thank you though.

I set the test data to 1000 and 580 and sent it to the pc and i received 1000 and 580.
I think its the number from the ADC that is 8 bit.

thanks for any help

scorpion
- 1st March 2006, 18:03
its working, but im still not sure why it wasnt working
what I did was:
variable.highbyte = adresh
variable.lowbyte = adresl

again. I dont know why, but I was only an 8 bit result from the adc.

Im glad its working and Ill move along, but does anyone know why my
adcin 0, variable
didnt work?

Other than that snag. my project went well.
I liked hidmaker. It took me alot longer than the hour or whatever Dr. Bob says it should take, but most of my time was deciding which descriptors to use.

sean-h
- 1st March 2006, 21:31
Glad you got it working Scorpion, it is not too bad when you have all the elements in place.

Regards

Sean.

rocky79
- 3rd March 2006, 08:20
I am using easyHID sofware to generate a Visual basic code 6.0. I have the visual basic .net installed. So when i copy the file from vb.6 to vb.net , Vb.net upgrades the file to the .net configuration.Except for one thing that gave me an error:it's the upgrade warning about adding a delegate.

Public Function ConnectToHID(ByVal pHostWin As Integer) As Boolean
FWinHandle = pHostWin
ConnectToHID = hidConnect(FWinHandle)
'UPGRADE_WARNING: Add a delegate for AddressOf WinProc Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'
FPrevWinProc = SetWindowLong(FWinHandle, GWL_WNDPROC, AddressOf WinProc)
End Function

I couldn't figure out how to fix it, Any idea?? here is what the help menu suggested :

In Visual Basic 6.0, the AddressOf operator was used to pass the address in memory of a function to an API procedure that takes a function pointer as an argument.
In Visual Basic .NET, the AddressOf operator must be used with a Delegate type. Delegates allow Visual Basic .NET to maintain a pointer to a function even if the function itself has already been garbage-collected.
The following example illustrates how a callback function that uses AddressOf is upgraded:

' Visual Basic 6.0
Declare Function SetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal attr As Long, ByVal lVal As Long) As Long
Sub SubClassWindow(ByVal hwnd As Long)
If PrevProcPtr = 0 Then
PrevProcPtr = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubClassProc)
End If
End Sub

' After upgrade to Visual Basic .NET
Declare Function SetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA"(ByVal hwnd As Integer, ByVal attr As Integer, ByVal lVal As Integer) As Integer
Sub SubClassWindow(ByVal hwnd As Integer)
If PrevProcPtr = 0 Then
' UPGRADE_WARNING: Add a delegate for AddressOf SubClassProc.
PrevProcPtr = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubClassProc)
End If
End Sub
What to do next

Add a delegate for the AddressOf operator, and change the parameter of the function declaration to the Delegate type:
Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function SetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal attr As Integer, ByVal lVal As SubClassProcDelegate) As Integer
Sub SubClassWindow(ByVal hwnd As Integer)
If PrevProcPtr = 0 Then
PrevProcPtr = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubClassProc)
End If
End Sub


Thank you in advance

lentz
- 7th March 2006, 19:47
Hi, my name is Davide. i'm start to program the pic18f4550.
This topic is very interesting!!

Usually i program pic16c765 and i use VB6 and the HIDcomm component for comunicate by USB with my pic.
Now, my question is: Have you got a simple example for turn on a led with pic18f4550 by vb6?

Thank for your time.

Regard, Davide

rocky79
- 16th March 2006, 00:55
Hi Rocky

I got compile errors in VB2005 so sticking with VB6, does it compile okay with ,net your end?

The two main routines to worry about and get you going are receive and transmit Data Routines.

Please scroll up on this post as I have given some VB examples already on what you have just asked.

Regards

Sean.

Sean,
I am just wondering if you know any good graphical widgets for Visual basic 6.0. Like meters, gauges, level indicators and so forth.

Thanks

mister_e
- 16th March 2006, 04:34
http://www.picbasic.co.uk/forum/showthread.php?t=1001&highlight=softwire

Seems to have change now.. maybe there's still some free version for VB6 somewhere :confused:

Ask them

sjohansson
- 27th March 2006, 22:48
Hi.
Im using EasyHID and a 18f4550 to communicate with VB6.
I use MicroCode Studio Plus and PicBasic 2.46. I download my programs using Microchip USB bootloader. And this works just fine.
Now I want to write a program that counts how long time an input pin is activated. Typical time will be in range form about 1ms - 120ms.
Normaly I would use "Pulsin" but what I understand the USB commands must be polled every 1ms or so. Is there another way to solve it in Basic?
Maybe to use the timers in 4550? If so, how shall that basic code be written?
Im not skilled enough to write the code in asm so it would be great if it is possible to do it in PicBasic.

Thanks in advance.

/Stefan.

Squibcakes
- 9th July 2006, 09:30
Just revisiting this topic again....

It seems that HID is good enough to program and set up the PIC for USB use, but <i>one really needs to generate a VB program to interface the PC to the USB device (aka PIC device)</i>

I don't have VB, and was considering downloading the 60MB VB express from Microsoft.

Does anybody have experience with VB Express?

<b>Does it have COMM components included?</b> Or can you get them from a 3rd party? Prefer if they were free.... hahaha

I'm really interested in doing a bit of serial communications between the PIC(4550) and PC over the USB link, as most PC nowdays don't even come with Serial Com ports, USB interfacing is gonning to be the way of the future.

<i>I don't want to go down the path of using a pre built usb 2 serial converter when a USB pic should be good enough, right?</i>

mister_e
- 9th July 2006, 10:05
interfacing a PIC to a pc is still easy.. the main problem is still that you have to keep the connection by send data to PC every 10mSec or so. Not so much problem but in some case, it's a pain. some conventionnal PIC and a RS232 to USB ic is still cheap and save the day when timing is critical.

But i'm still new in USB, there's so much things to learn before be comfortable with everything. Yeah it's more complicated than just USBIN, USBOUT, USBINIT, and USBSERVICE.. Jan Axelson's book is more than enough.

I use Visual C++, Visual Basic 6 and , beurk Delphi, so i'd never use the VB Express as now, it should have what you need. Case not, i guess you can use the API or DLL (i don't remind) of HID maker and play 'round it.

Demon
- 9th July 2006, 20:50
I had tried with VB Express but had quickly ditched it for VB6 from EBay. There were several things about VB Express; it lacks several features like Package Deployment which I require. I don't remember all the other reasons why I dropped it, but I "REALLY" didn't like it.

Check out EBay for VB6, there were several cheap auctions for the academic versions of VB6. I ended up getting the full corporate version for just a bit more, with all the manuals and tutorials.


Here's a NEW package for $125USD:
http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&item=160004563299

This kit includes:
*Microsoft Visual Basic 6.0 Learning Edition
*Learn Microsoft Visual Basic 6.0 Now
*Microsoft Visual Basic 6.0 step by step
*Microsoft Visual Basic 6.0 Programmer's Guide
*The MSDN Library on two CD-ROMs


Some more learning editions:
http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&item=250004751173
http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&item=160005627793


Here's a professional edition:
http://cgi.ebay.ca/ws/eBayISAPI.dll?ViewItem&item=300005730012

The action includes:
Microsoft Visual Basic 6.0 Professional Edition. One CD in Original Case.
Microsoft Visual Studio 6.0 Service Pack 5.0 One CD in a jewled case.
MS MSDN Libray-Visual Studio 6.0. 2 CDs in the original case.
MS Visual Studio 6.0 PLUS PACK. 4 CDs in the original case.
These are the full functional sets, not educational settings or demos.

Good luck!

Robert
:)

Rob
- 24th July 2006, 10:21
Hi,

I suspect a lot of you that have posted on this thread are subscribed to it. I'm having problems with Easy HID and have posted a new subject. Obviously a lot of you guys have used it and I'm wondering what I'm doing wrong. Please chack my post out - it's driving me mad:

http://www.picbasic.co.uk/forum/showthread.php?t=4304

I am ONLY having problems with the PIC program on compile

Thanks a lot

Rob

skimask
- 25th July 2006, 21:25
I just got an started using VB Express. Yes, it's a bit different, but it works great. You do have to learn a new way of writing things, but it's "the new way of doing things" according to Micro$oft.

If you use the "Upgrade Wizard", you can take your older VB6 type programs and import them into VB Express without much problem at all. VB Express uses a bunch of compatibility files to make it work with the old code just fine. Took me about 2 minutes to get an old serial port program with with VB Express...and the price was right too...
JDG

bigbear
- 9th August 2006, 03:48
I am working to convert the VB file from easyHID to a REALBASIC file. I am almost there but need some help. Anyone here do anywork in realbasic? You can check out the thread here:

http://forums.realsoftware.com/viewtopic.php?t=6516&postdays=0&postorder=asc&start=75&sid=da674a98ed4fcdc0a8b170185ab69b24

I will post the files for anyone who wants them when the conversion is done. Advantage of RB is it compiles into Windows, Mac OS, and Linix. Not sure if the app will work in non windows apps, but I'll find out. Looks like it should work.

bigbear
- 9th August 2006, 03:49
Also ordered free samples from microchip! Great deal!!!!!

bigbear
- 9th August 2006, 04:05
Do you guys recommend PicBasic or PIcbasic PRO? I know pro is better, but do I need it?

mister_e
- 9th August 2006, 05:16
It's up to you to decide but for the price difference between the two... it worth to invest a bit much and save tons of headaches... even if Aspirins, Advil or else are cheap :)

Demon
- 14th August 2006, 22:43
Do you guys recommend PicBasic or PIcbasic PRO? I know pro is better, but do I need it?

It depends on what you want to do. Take a look at the commands available in each and decide:
http://www.melabs.com/resources/pbpmanual/
http://www.melabs.com/resources/pbcmanual/

Robert
:)

Demon
- 15th August 2006, 00:25
Hi rocky
...
USBBufferSizeMax con 64 ' maximum buffer size
USBBufferSizeTX con 64 ' input
USBBufferSizeRX con 64 ' output

I think min is 8 bytes and max 64.
...
Sean.

Nope, 1 to 64 bytes for both input and output buffers according to EasyHID help files under Configuration Details.

Robert
:)

bigbear
- 15th August 2006, 04:19
Is there somewhere that I can see a list of the assembly codes for a PIC such as the 18F4550? From what I understand there are not a huge list of them. It has been a while since I did assembler, but I would like to have the ability to combine PBP and assembler.

Demon
- 15th August 2006, 04:47
You'll have better luck getting an answer to an Assembler-related question if you start a new thread in the General forum:
http://www.picbasic.co.uk/forum/forumdisplay.php?f=7

This thread is about EasyHID and interfacing via USB.

Robert
:)

mister_e
- 15th August 2006, 08:57
Is there somewhere that I can see a list of the assembly codes for a PIC such as the 18F4550? From what I understand there are not a huge list of them. It has been a while since I did assembler, but I would like to have the ability to combine PBP and assembler.
you can mix both of them using ASM and ENDASM. You can have the asm list if you open the .COD file or the .LST file

Demon
- 16th August 2006, 23:17
Ok, I've reread this thread hoping to find a hint why the device is not recognized by windows.

I had it working using HIDMaker FS, but I'm trying to use EasyHID since the resulting code is MUCH more compact. Here's what I've done so far:

- generated code with EasyHID, 1 byte to PC, 30 bytes to PIC.
- modified generated PBP program to include an LCD, that works great.
- move MCHID.dll to VB6 working folder.
- compiled the generated VB code using VB6.
- started up the executable.
- reset the PIC and that's when the error appears in Windows.

Can the generated VB6 code work without doing any input or output? I was trying to just get a skeleton VB6 program working first, and then add 1 feature at a time.

Robert
:)

mister_e
- 16th August 2006, 23:30
Sure the VB program can work without any in/out.

Demon
- 17th August 2006, 01:29
Well that's good news.

One thing that I find strange is that I don't get the same number of generated files between each software. I would have expected that both would have to override the same number of files.

EasyHID:
- DESCProject.ASM
- USBDESC.ASM
- Project.ASM
- Project.PBP

HIDMaker:
- descript.ASM
- usb18.ASM
- usb18.INC
- usb18mem.ASM
- usbdesc.ASM
- Project.BAS

Is that normal?

Robert
:)

mister_e
- 17th August 2006, 05:41
sure it is as log it's two diferent company.

Let's see a common example.. Darrel's codes have more INCLUDE than mine and all other folks here... is it normal? Sure ;)

Demon
- 19th August 2006, 00:57
Yup, the includes are normal. I compiled the original generated code from EasyHID and the device is recognized. I'm in the process of trying to get an interrupt working for USBSERVICE. After that I'll add basic I/O between the PC and PIC and then I'll post the results.

Robert
:)

bigbear
- 19th August 2006, 04:03
I have converted the easy HID VB template to a RealBasic Template, and it was tested by Sean (thanks again) and it works. You can download the template here.

http://www.members.cox.net/walachcnc/usb.html

Demon
- 19th August 2006, 05:06
Using easyhid is not that bad.

...

If you wanted to receive say 10 bytes ... Just tell it to jump off to that routine and as soon as data is received it will come back from that routine with the usbbuffer(0) to usbbuffer(63) filled as such.
So if your PC sent 10 bytes then the variables usbbuffer(0-9) will hold those 10 bytes, if your pc sent 20 bytes then usbbuffer(0-19) will hold those bytes.

...

Hope this helps.

Regards Sean.


(yup, I saw the correction in another post about byte 0 containing the endpoint and the data being in bytes 1 to 10.)


So if I understand this properly, we don't have to worry about any of the USB registers when we receive data. I assume this is all done by the generated assembler code?

The important thing is for us to know the exact length of our transferred data and that's it. We don't need any interrupt either, the USBIN command will execute until all the bytes are received (returning to the label DoUSBIn until complete).

That leaves one thing, how do we handle an error? Are we to assume everything will always work? Are there flags provided by the assembler routines? Or are we supposed to use the USB error registors described in the PIC datasheet?

Robert
:)

mister_e
- 27th May 2007, 23:04
I am using easyHID sofware to generate a Visual basic code 6.0. I have the visual basic .net installed. So when i copy the file from vb.6 to vb.net , Vb.net upgrades the file to the .net configuration.Except for one thing that gave me an error:it's the upgrade warning about adding a delegate.

I couldn't figure out how to fix it, Any idea??

Sorry for the about 1 year later reply but anyways, this will be handy for new VBExpress 2005 user... probably .NET ones too.

Today, while trying to port USBDemo From VB6 to VBExpress, i came across the same issue. The simple fix is to add those 2 lines bellow in the mcHIDInterface.vb module, right under all Declare statement


'
' adding delegate to suite VBExpress 2005 requirement
' ================================================== =
Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function SetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal attr As Integer, ByVal lVal As SubClassProcDelegate) As Integer

HTH

T.Jackson
- 28th May 2007, 05:50
.net :eek: No way for me! I will be using .com (VB5 & 6) for life. There will always be backwards compatibility for .com, no matter what. Out of interest, even the latest versions of MS Office still use .com Microsoft will never completely abandon .com, willing to bet my life on it.

mjwaldner
- 23rd April 2008, 00:34
Like a lot of you I’m just starting to migrate some of my applications to USB. I’ve tried to us EasyHID to help me get started. I’ve read threw this post and it makes sense what I’m reading. My problem is that when I try to compile the PBP file it creates I get the compilation error

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

I’ve seen several posts’ that ask this question and I haven’t seen a good answer to what is causing it and how to fix it. I suspect it has to do with directory structure.

I’m using MCSP 3.0.0.5 and PBP 2.47.
PIC18F4550

Please help,

Rob
- 23rd April 2008, 09:54
Hi mjwaldner,

Using Microcode Studio, make sure you have the correct chip selected, 18F4550. The editor sometimes defaults to a different IC when you open it - this has caught me out a couple of times!

Make sure that all the files that were generated by EasyHID are in the same folder as the file you are trying to compile - see attached image

Let us know how you get on

Cheers

Rob

mjwaldner
- 3rd May 2008, 23:25
Thanks Rob,
I started over form scratch and it worked this time. I must have moved something to the wrong directory.
My next question is. Should the computer recognize the USB device and try to install it automatically? I understand that I will need to work on the PC software to make it work but when I plug the USB cable into the PC nothing happens. It doesn’t try to install. I haven’t modified the software the Easy HID created. I just programmed it to the PIC 18F4550. Is there more code needed to initialize it.
I’m just taking baby steps threw this. Any information is helpful.
Thanks
Matt

mister_e
- 3rd May 2008, 23:38
In case it have already worked and if you haven't change the PID, VID and all other settings, if you plug the device you're not going to have any bubbles on the task bar.

If you want some, you'll need to uninstall the device. That's pretty easy to do with USBDeview
http://www.nirsoft.net/utils/usb_devices_view.html

mjwaldner
- 6th May 2008, 02:29
I found out what was going wrong. It was a hardware problem. I did not turn on the USB Voltage Regulator in the melabs programmer. So now my PC is recognizing the USB HID.
The problem I’m having now is that I can’t seem to get any data from the PIC to the VB.Net application. My VB application is recognizing that the device is plugged in or unplugged but nothing else. The application never seems to jump into the OnRead event.
I must be missing something. What tells the VB aplication to jump to the OnRead event?

Any suggestions.
Thanks,
Matthew

This is what I have.


VB.Net----------------------------------------------------------------
'************************************************* ****************
' on read event...
'************************************************* ****************
Public Sub OnRead(ByVal pHandle As Integer)

' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontrolller...
TextBox1.Text = Chr(Val(BufferIn(1)))
End If
End Sub

PICB----------------------------------------------------------------------

' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********
usbinit ' initialise USB...
ProgramStart:
gosub DoUSBIn
USBBuffer(0)=32
USBBuffer(1)=16
gosub DoUSBOut
goto ProgramStart

mister_e
- 6th May 2008, 04:45
Comment out the GOSUB DoUSBIn and see if works better.

I suggest you to have a look on USBDemo.
http://www.picbasic.co.uk/forum/showthread.php?t=5418

Maybe this one too
http://www.picbasic.co.uk/forum/showthread.php?t=6463&

luisfe
- 24th November 2015, 21:51
Hello. I'm making a program who include easyhid for the 18f4550 but I have some questions:
I want to pass 10 decimal 2 digit variables and 11 bit variables from the PIC to the PC, then something simmilar in return. Do the usb buffers support this just declaring de proper variables?
Or I need some kind of conversion or trick?
Thank you for your help.
Luis

towlerg
- 26th November 2015, 23:41
USB doesn't really work like that. The buffer is just a string of bytes, the significance is determined by your application. For instance the first byte could be the status of a LED or the first digit of a number.

George