473,692 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading from a USB keyboard (HID)

rs
Hi guys,

I am trying to read from a USB keyboard using vb.net and HID classes. the
USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and
is detected in device manager as my keyboard. the USB keyboard is detected
as HID keyboard device. the program finds the keyboard if it is attached.
and I am getting valid handles. however, everytime I use the readfile
function I am getting "object reference not set to an instant of an object"
exception. if i use any other function it fails and I am getting -1 in the
"success" parameter. I am including my code:

HidD_GetHidGuid (HidGuid)

'Friend Function FindDeviceFromG uid _

'(ByVal myGuid As System.Guid, _

'ByRef devicePathName( ) As String) _

'As Boolean

'Purpose : Uses SetupDi API functions to retrieve the device path name of an

' : attached device that belongs to an interface class.

'Accepts : myGuid - an interface class GUID.

' : devicePathName - a pointer to an array of strings that will contain

' : the device path names of attached devices.

'Returns : True if at least one device is found, False if not.

'Fill an array with the device path names of all attached HIDs.

DeviceFound = MyDeviceManagem ent.FindDeviceF romGuid _

(HidGuid, _

DevicePathName)

'If there is at least one HID, attempt to read the Vendor ID and Product ID

'of each device until there is a match or all devices have been examined.

If DeviceFound = True Then

MemberIndex = 0

Do

HIDHandle = CreateFile _

(DevicePathName (MemberIndex), _

0, _

FILE_SHARE_READ , _

Security, _

OPEN_EXISTING, _

0, _

0)

If (HIDHandle <> INVALID_HANDLE_ VALUE) Then

MyHID.DeviceAtt ributes.Size = Marshal.SizeOf( MyHID.DeviceAtt ributes)

Result = HidD_GetAttribu tes(HIDHandle, MyHID.DeviceAtt ributes)


If (Result <> 0) Then

'Find out if the device matches the one we're looking for.

If (MyHID.DeviceAt tributes.Vendor ID = MyVendorID) And _

(MyHID.DeviceAt tributes.Produc tID = MyProductID) Then

MyDeviceDetecte d = True

'Save the DevicePathName so OnDeviceChange( ) knows which name is my device.

MyDevicePathNam e = DevicePathName( MemberIndex)

Else

'It's not a match, so close the handle.

MyDeviceDetecte d = False

Result = CloseHandle(HID Handle)

End If

Else

'There was a problem in retrieving the information.

MyDeviceDetecte d = False

Result = CloseHandle(HID Handle)

End If

End If

'Keep looking until we find the device or there are no more left to examine.

MemberIndex = MemberIndex + 1

Loop Until ((MyDeviceDetec ted = True) Or _

(MemberIndex = UBound(DevicePa thName) + 1))

If MyDeviceDetecte d Then

rtbstatus.Text = rtbstatus.Text + vbCrLf + "keyboard found"

'The device was detected.

'Register to receive notifications if the device is removed or attached.

Success = MyDeviceManagem ent.RegisterFor DeviceNotificat ions _

(MyDevicePathNa me, _

Me.Handle, _

HidGuid, _

DeviceNotificat ionHandle)
'Debug.WriteLin e("RegisterForD eviceNotificati ons = " & Success)

'Learn the capabilities of the device.

MyHID.Capabilit ies = MyHID.GetDevice Capabilities _

(HIDHandle)

If Success Then

'Get and display the Input report buffer size.

'GetInputReport BufferSize()

rtbstatus.Text = rtbstatus.Text + vbCrLf + "register notification is set"

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

ReadHandle = CreateFile _

(MyDevicePathNa me, _

GENERIC_READ, _

0, _

Security, _

OPEN_EXISTING, _

0, _

0) I also tried it with overlaping. nogo

rtbstatus.Text = rtbstatus.Text + vbCrLf + "handle created"

'(optional)

'Flush any waiting reports in the input buffer.

MyHID.FlushQueu e(ReadHandle)

MyHID.FlushQueu e(HIDHandle)

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

'start reading

Dim InputReportBuff er() As Byte

Dim NumberOfBytesRe ad As Long

ReDim InputReportBuff er(32)

success = HidD_GetFeature _

(hidHandle, _

InputReportBuff er(0), _

CInt(UBound(inF eatureReportBuf fer) + 1))

'sucess always = false and input report buffer = 0s. I also tried

HidD_GetInputRe port and read file functions. nogo.

any idea what i am doing wrong? any input is appreciated.


Nov 21 '05 #1
0 6679

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
17750
by: CMiYC | last post by:
I'm attempting to open an USB HID device using createfile from kernel32. The open attempt always fails. This is the call I'm using: CreateFile(HidName$, &HC0000000, 3, 0, 3, 0 ,0) HidName$ gets assigned the device: \\?\hid #vid_7766&pid_1629 #6&1b9813bf&0&0000 #{4d1e55b2-f16f-11cf-88cb-00111100030}
2
16398
by: Michael Bendzick | last post by:
Is there a simple way in python to read a keyboard scan code? I'm working on a shell script that interfaces with a proprietary keyboard device (extra buttons) and need to be able to distinguish between those keys. Thank you
2
8810
by: Hubert Hermanutz | last post by:
Hello, Where can i get a sample about HID communication with .NET Framework? I don't know enough about HID communication, only that with VC++ it is possible to using the Windows Device Development Kit. Exists for .NET specifically namespaces or must i also use the DDK? Thanks in advance, Hubert
7
10637
by: Don Riesbeck Jr. | last post by:
I'm working on an application (OEM) using C# that utilizes input from a keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device, and input from it is sent to the system as if it were a keyboard. I need to be able to identify input from the scanner and keyboard independently. I've looked at DirectX.DirectInput, and using user32.dll to hook into the keyboard messages, but neither method seems to allow for identification of...
1
5449
by: Eric Renken | last post by:
We are developing an HID device and I have a couple questions about communicating with it. I need to be able to do a direct Interrupt Endpoint call to the USB device. Is this possible to do from Windows/C#? I can do a create file and get a handle to the device, the problem is right now I would have to talk directly to an Interrupt and I don't know if this is possible with HID. Thanks, Eric Renken
2
8761
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as my keyboard. the USB keyboard is detected as HID keyboard device. the program finds the keyboard if it is attached. and I am getting valid handles. however, everytime I use the readfile function I am getting "object reference not set to an instant...
0
4393
by: Chris Herring | last post by:
I am writing a WinForms app that will integrate a handheld voting device system into the app. The handhelds communicate to the PC via a USB connection. The USB device has no manufacturer driver, it simply uses the built in MS HID srv driver. It sends the results as keyboard commands. I have 2 ways to catch this data as I see it: 1) I can read the keyboard commands as they come in. In order to make sure that I get the commands even when my...
3
1836
by: jodansmif | last post by:
I've been teaching myself Python as part of my senior design project at university. The obstacle our group currently faces is communicating with a microcontroller (ACS USB Servo II) that appears in Windows as a USD HID. Unfortunately, the vendor's sample code is in Visual Basic and Visual C++ which none of our group members have any experience using. My hope is that someone has experience with this type of problem and can point me to...
0
2059
by: LawrenceK | last post by:
Hi All, I don't know if this is the right forum for my question. I want to be able configure a USB HID through a web page (i.e. using IE). I read some where in this forum that it was possible to enable this communication between web page and USB HID with an ActiveX Control. I have tried realise an ActiveX control for my project in VC+++ (VS2005) but it did not work at all. Since I am new in to this sort of programming, I could not trace...
0
8538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9083
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6459
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4323
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1957
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.