HID and VB6
HID and VB6
HID and VB6
HID and VB6
HID and VB6
HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6
HID and VB6 HID and VB6
HID and VB6
Go Back  Xtreme Visual Basic Talk > > > HID and VB6


Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2006, 10:10 PM
Grayda's Avatar
Grayda Grayda is offline
Centurion
 
Join Date: Jun 2003
Location: Australia
Posts: 145
Default HID and VB6


I just bought myself a set of four Buzz! controllers from eBay for $30, and while waiting for them to arrive, I'm writing a trivia game for VB6. At first I thought they were standard PS2 controllers, which meant I could plug them into my PS2 -> USB adapter and map them out and stuff. But nope. They're four controllers connected to a "hub" and sent through one USB plug. They apparently come up as "compliant HID devices" or something. I've found an article that details what sort of information I need to be reading and writing to the device(s) (Check out http://www.vsj.co.uk/articles/display.asp?id=600 if you're interested), but as for actually reading and writing to the USB devices, I'm lost.

I've found quite a few projects that use four files: HIDInterface.bas, OSInterface.bas, USBInterface.bas and APIGID32.DLL. I've downloaded them, and tried hard to use them, but keep coming up with "False" when I try and open any HID device on my PC (That includes my existing PS2 -> USB adapter, and my Microsoft USB Mouse), so that's a no-go there..

So how would I go about opening a HID device in Visual Basic, and work with the info that comes from it?

Any help or pre-made examples would be really good thanks

-G
__________________
Solid Inc. Media Productions
Reply With Quote
  #2  
Old 12-03-2006, 08:49 AM
dilettante's Avatar
dilettanteHID and VB6 dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,520
Default

Sorry, I don't have a lot to contribute here.

It does seem as if HID Class USB devices are accessed as files or streams of some sort. The Windows DDK may have the documentation, but I don't have a copy here. Added: You can always look at the online version however.

Have you looked at The HID Page? It has some info and at least one VB6 program as well as more links.

Last edited by dilettante; 12-03-2006 at 08:51 AM. Reason: more
Reply With Quote
  #3  
Old 12-04-2006, 08:53 PM
Grayda's Avatar
Grayda Grayda is offline
Centurion
 
Join Date: Jun 2003
Location: Australia
Posts: 145
Default

My controller arrived yesterday, and I spent the day putting together a VB6 quiz program. I found Intel's HID class, and used that. It works for my Buzz! Controllers, but not for my HID mouse. That's no worries. I now have working, a fully featured quiz game that uses Intel's 3 modules (which I believe are free to distribute, and which I have included here for reference).

Using these classes, I can successfully read FROM the controller, get the button pressed, and turn that into human-readable information (ie. Player One Pressed Red). But I'm having troubles WRITING to the device. If you read the article I posted above (see http://www.vsj.co.uk/articles/display.asp?id=600) you'll see that to turn the lights on in the device, you need to write to it. I've had a bit of a play around with the 3 modules, trying to get stuff to work, but all I can get is this:

Quote:
---------------------------
Project1
---------------------------
Could not write an Output Report
---------------------------
OK
---------------------------
Which doesn't make a whole lot of sense to me. Is anyone able to look over the modules and try and find out how I can write to the device without error? Any help is very much appreciated.

And thanks dilletante. I found that page before I posted here, and that's where I found the Intel modules. Thankyou very much ;D
Attached Files
File Type: zip HIDClass.zip (5.1 KB, 262 views)
__________________
Solid Inc. Media Productions
Reply With Quote
  #4  
Old 12-04-2006, 10:01 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

What code are you using to write to the USB HID Device?

I looked at the attachments and found the following code for writing to a device.
Code:
Public Sub WriteUSBdevice(BufferPtr&, ByteCount&) ' This subroutine "writes" to an openned USB device ' Copy the user buffer into a local buffer so that a ReportID (=0) may be prepended ' The first byte will contain the ReportID (=0) Dim ReportBuffer(256) As Byte If ByteCount& > 254 Then ErrorExit ("Maximum ByteCount for WriteUSBdevice is 254") Call CopyBuffer(BufferPtr&, AddressFor(ReportBuffer(1)), ByteCount&) ReportBuffer(0) = 0 ' ReportID Success = WriteFile(HidHandle&, AddressFor(ReportBuffer(0)), ByteCount& + 1, BytesWritten&, 0) If (Success = 0) Then ErrorExit ("Could not write an Output Report") End Sub
Notice the notes on teh buffer and the call needs to include the bytes.

Post your code that is calling the function and the data you are trying to write and maybe we can help.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #5  
Old 12-04-2006, 10:09 PM
Grayda's Avatar
Grayda Grayda is offline
Centurion
 
Join Date: Jun 2003
Location: Australia
Posts: 145
Default

Well that's the thing. I don't know what code to write in there. I've got something like this:

Code:
Private Sub LightsOn()
Dim Buff(128) as byte

WriteUSBdevice(AddressFor(Buff(0)), 6)
End Sub
But I don't know what to put in for the values for Buff(0), Buff(1) etc.

Here's my code to read FROM the controller:

Code:
Private Sub ReadController()

ReadUSBdevice AddressFor(Buffer(0)), 6

    ' Has a valid button been pressed?
    If Buffer(2) <> CInt(0) Or Buffer(3) <> CInt(0) Or Buffer(4) <> CInt(240) Then
        ' Send the input off to be checked
        ParseInput Buffer(2) & "," & Buffer(3) & "," & Buffer(4)
    End If
End Sub
And the ReadController Sub works fine. It seems to like byte lengths of 6, but only for reading.

And just as a bit of a side note, Player 2 doesn't work (I got the controllers as damaged stock, which is why it was so cheap), so that explains why I'm only reading 3 players

If you would like the contents of Buffer(2), Buffer(3) etc. (ie. Button data), then just ask..

Hope this helps
__________________
Solid Inc. Media Productions
Reply With Quote
  #6  
Old 12-04-2006, 10:18 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

Since I am not familure with the controllers I am just guessing here.
How many buttons are on the controllers? if there are 2 I think it may be that the receive buffers are boolian 1 for press 0 not pressed for each controller the system sees. If this is the case and the controllers have 1 light then you may only be able to write 3 bytes 0/1 off/on for each controller light.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #7  
Old 12-04-2006, 10:29 PM
Grayda's Avatar
Grayda Grayda is offline
Centurion
 
Join Date: Jun 2003
Location: Australia
Posts: 145
Default

Well the controllers have 5 buttons. The big red button on the top for buzzing in, Blue, Orange, Green and Yellow (in that order). The article I pointed to twice above, shows a picture, and a diagram on how to turn the lights on and off, but it's for C#, which I'm unfamiliar with, and the diagram isn't that well laid out to begin with anyway (plus the data they show in

Oh and in case I forgot to mention, the 4 controllers (3 in my case) are connected to a sort of 'hub' 4 controllers go into one moulded box, and is sent via 1 USB cable to the host

The data that comes BACK looks something like this. The first value is equal to Buff() (so if I write 1,8 that means Buff(1), 8 is the number returned from the device)

Player 1:
2,1 = Red
2,16 = Blue
2,8 = O
2,4 = G
2,2 = Y

Player 3 (Remember Player 2 doesn't work):

3,4 = Red
3,64 = Blue
3,32 = Orange
3,16 = Green
3,8 = Yellow

Player 4:

3,128 = Red
4,248 = Blue
4,244 = Orange
4,242 = Green
4,241 = Yellow


I hope this all makes sense, and I'm not confusing anyone.. XD
__________________
Solid Inc. Media Productions
Reply With Quote
  #8  
Old 12-04-2006, 11:09 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

OK, I looked at the information and I am still not sure (Would need to play myself to be sure) But I think the write data buffer is Buff(1) {Buff(0) is not used} and will need the following values (I think MaybePossiblyperhapsiflucky)
1,0 - All lights off
1,1 - Controller 1 Light on
1,2 - Controller 2 Light on
1,4 - Controller 3 Light on
1,8 - Controller 4 Light on
You can turn on more than 1 light by adding the numbers for example
1,6 - Lights 2 and 4 are on.

As I understand it here is what is going on.
Each Byte is a 4 bit binary each of the bits represents an on/off state of each device.
So the first byte (not counting the report byte i.e. Buff(0) would consist of 0000 for all lights off 0001 for controller 1 light on 1000 for controller 4 light on 1001 for both 1 and 4 ect.

Hope this helps get hoy in the right direction.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #9  
Old 12-04-2006, 11:16 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

Oh, and one other thing.. It may be that the write buffer my ony be 1 or 2 bytes.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #10  
Old 12-04-2006, 11:55 PM
Grayda's Avatar
Grayda Grayda is offline
Centurion
 
Join Date: Jun 2003
Location: Australia
Posts: 145
Default

Partially Solved! I did a brute-force attack, and found out (which I had somehow missed before), that to turn on Player one, you just send:

2,255 (ie. Buff(2) = 255) with a byte length of 7 and it works! Now to try and crack the other codes..

When it's all done, I'll be compiling my knowledge into a redistributable class, and posting it on either Sourceforge, Planet Source Code or even here if someone wishes to post it in the Code library or something ;D

Thankyou so much for your help! Means lots to me!
__________________
Solid Inc. Media Productions
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HID and VB6
HID and VB6
HID and VB6 HID and VB6
HID and VB6
HID and VB6
HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6 HID and VB6
HID and VB6
HID and VB6
 
HID and VB6
HID and VB6
 
-->