Softwareentwicklung
›
Thread
HID Gerät Ansprechen
DD
Dominik Dahlen
Gast
24.09.2007 08:58
#661087
Hallo ich bin seit einiger Zeit drüber eine eigene USB-Firmware für
einen AT90USB162 zu schreiben.
Nach dem ich jetzt endlich das Gerät richtig in Windows als HID-Tastatur
erkannt habe wollte ich nun die ersten Kommunikationsversuche mit dem
Host starten. Dafür wollte ich mir eine kleine C Application schreiben.
Soweit so gut:
Das Problem ist wenn ich HidP_GetCaps aufrufe stürtzt mein Programm
jedesmal mit dem Fehler hidparse.sys konnte nicht gefunden werden.
Jetzt ist die Datei aber im richtigen verzeichniss und auch vorhanden.
Die richtigen Bibiliotheken müsste ich auch eingebunden haben sonst
könnte ich es ja nicht compelieren.
Jemand eine idee an was das liegen könnte
hier mal der C-Code
1 #include <windows.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <ddk/hidsdi.h>
5 #include <ddk/hidpi.h>
6 #include <ddk/hidusage.h>
7 #include <setupapi.h>
8
9
10 int main ()
11 {
12 PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd ;
13 SP_DEVICE_INTERFACE_DATA spdid ;
14 SP_DEVINFO_DATA spdd ;
15 HDEVINFO hDevInfo ;
16 DWORD dwIndex , dwSize , dwType ;
17 TCHAR szProperty [ 256 ];
18 GUID guid ;
19 HANDLE DeviceHandle ;
20 HIDD_ATTRIBUTES Attributes ;
21 PHIDP_PREPARSED_DATA PreparsedData ;
22 HIDP_CAPS Capabilities ;
23
24 ZeroMemory ( & spdid , sizeof ( spdid ));
25 spdid . cbSize = sizeof ( spdid );
26 HidD_GetHidGuid ( & guid );
27 hDevInfo = SetupDiGetClassDevs ( & guid , NULL , NULL , DIGCF_DEVICEINTERFACE | DIGCF_PRESENT );
28
29 if ( hDevInfo == INVALID_HANDLE_VALUE )
30 {
31 printf ( "SetupDiGetClassDevs failed, Error %u \n " , GetLastError ());
32 return ( FALSE );
33 }
34
35 for ( dwIndex = 0 ; ( SetupDiEnumDeviceInterfaces ( hDevInfo , NULL , & guid , dwIndex , & spdid )); dwIndex ++ )
36 {
37 printf ( "Geraete-Index: %u \n " , dwIndex );
38 dwSize = 0 ;
39
40 SetupDiGetDeviceInterfaceDetail ( hDevInfo , & spdid , NULL , 0 , & dwSize , NULL );
41
42 if ( dwSize )
43 {
44 if ( NULL == ( pspdidd = ( PSP_DEVICE_INTERFACE_DETAIL_DATA ) HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY , dwSize )))
45 continue ;
46
47 pspdidd -> cbSize = sizeof ( * pspdidd );
48
49 ZeroMemory (( PVOID ) & spdd , sizeof ( spdd ));
50 spdd . cbSize = sizeof ( spdd );
51
52 if ( SetupDiGetDeviceInterfaceDetail ( hDevInfo , & spdid , pspdidd , dwSize , & dwSize , & spdd ))
53 {
54 printf ( "Name fuer CreateFile(): %s \n " , pspdidd -> DevicePath );
55
56 if ( SetupDiGetDeviceRegistryProperty ( hDevInfo , & spdd , SPDRP_FRIENDLYNAME , & dwType ,( PBYTE ) szProperty , sizeof ( szProperty ), NULL ))
57 {
58 if ( dwType == REG_SZ )
59 printf ( "FriendlyName: %s \n " , szProperty );
60 }
61 if ( SetupDiGetDeviceRegistryProperty ( hDevInfo , & spdd , SPDRP_DEVICEDESC , & dwType ,( PBYTE ) szProperty , sizeof ( szProperty ), NULL ))
62 {
63 if ( dwType == REG_SZ )
64 printf ( "DeviceDescription: %s \n\n " , szProperty );
65 }
66 }
67 HeapFree ( GetProcessHeap (), 0 , pspdidd );
68 }
69 if (( strstr ( pspdidd -> DevicePath , "hid#vid_03eb&pid_201c#6&1cdb5d6c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}" )) != NULL )
70 break ;
71 }
72 SetupDiDestroyDeviceInfoList ( hDevInfo );
73 DeviceHandle = CreateFile ( pspdidd -> DevicePath , GENERIC_READ , FILE_SHARE_READ ,( LPSECURITY_ATTRIBUTES ) NULL , OPEN_EXISTING , 0 , NULL );
74 HidD_GetAttributes ( DeviceHandle , & Attributes );
75 // printf("\nVendorID : %X",Attributes.VendorID);
76 // printf("\nProductID: %X",Attributes.ProductID);
77 // printf("\nVersion : %X",Attributes.VersionNumber);
78 HidD_GetPreparsedData ( DeviceHandle , & PreparsedData );
79 HidP_GetCaps ( PreparsedData , & Capabilities );
80
81 return ( 0 );
82 }
gruß
R
Rupplyn
Gast
24.09.2007 12:25
#661238
zwar in vb aber vielleicht hilft's...
DD
Dominik Dahlen
Gast
24.09.2007 13:12
#661276
DD
Dominik Dahlen
Gast
24.09.2007 14:21
#661327
2 Sachen hab ich mitlerweile rausgefunden die ich leider aber auch nicht
wirklich verstehe.
Es scheint so als würde ich keinen Handle bekommen jedenfalls schlägt
CreateFile immer mit error-code 3 fehl also ERROR_PATH_NOT_FOUND.
Das passiert aber nur wenn ich vorher SetupDiDestroyDeviceInfoList
aufrufe.
wenn ich SetupDiDestroyDeviceInfoList nicht aufrufe schlägt CreateFile
mit error-code 5 also ERROR_ACCESS_DENIED fehl.
Alle andern vorherigen aufrufe funktionieren so wie sie sollen und
werden bis auf beim ersten mal SetupDiEnumDeviceInterfaces aufrufen mit
error-code 0 beendet.
gruß
R
Rupplyn
Gast
24.09.2007 19:18
#661507
DD
Dominik Dahlen
Gast
25.09.2007 08:01
#661692
Danke dein Programm scheint genau das zu sein was ich gesucht habe um
die ersten Kommunikationsversuche auszuprobieren.
Werds mir gleich zu Hause mal anschauen.
DD
Dominik Dahlen
Gast
04.10.2007 08:33
#668277
Hallo vielleicht kann sich doch nochmal jemand der sache annehmen ich
komm leider nicht wirklich weiter.
Ich bin mir mitlerweile sicher das mein uC die Daten richtig an den PC
sendet.. Da ich das Device als Gamecontroller definiert habe und bereits
unter der Systemsteuerung Gamecontroller das drücken der einzelnen
knöpfe angezeigt bekomme.
jetzt funktioniert der Code auch soweit bis ich zum Readfile komme. Dort
bekomm ich dann immer ein ERROR_IO_PENDING.
gruß
1 #include <iostream>
2 #include <windows.h>
3 #include <winerror.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <ddk/hidsdi.h>
7 #include <ddk/hidpi.h>
8 #include <ddk/hidusage.h>
9 #include <setupapi.h>
10
11
12 int main ()
13 {
14 BOOL Return ;
15 PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd ;
16 SP_DEVICE_INTERFACE_DATA spdid ;
17 SP_DEVINFO_DATA spdd ;
18 HDEVINFO hDevInfo ;
19 DWORD dwIndex , dwSize , dwType ;
20 TCHAR szProperty [ 256 ];
21 GUID guid ;
22 HANDLE DeviceHandle ;
23 HIDD_ATTRIBUTES Attributes ;
24 PHIDP_PREPARSED_DATA PreparsedData ;
25 HIDP_CAPS Capabilities ;
26 LPVOID InputReport ;
27 DWORD * OutputReport ;
28 DWORD numBytesReturned ;
29 OVERLAPPED s_overlapped ;
30 HANDLE hEventObject ;
31
32
33 dwIndex = 0 ;
34
35 spdid . cbSize = sizeof ( spdid );
36 HidD_GetHidGuid ( & guid );
37 printf ( " \n 1. %d" , GetLastError ());
38 hDevInfo = SetupDiGetClassDevs ( & guid , NULL , NULL , DIGCF_DEVICEINTERFACE | DIGCF_PRESENT );
39 printf ( " \n 2. %d" , GetLastError ());
40 if ( hDevInfo == INVALID_HANDLE_VALUE )
41 {
42 printf ( "SetupDiGetClassDevs failed, Error %u \n " , GetLastError ());
43 return ( FALSE );
44 }
45
46 SetupDiEnumDeviceInterfaces ( hDevInfo , NULL , & guid , dwIndex , & spdid );
47 printf ( " \n 3. %d" , GetLastError ());
48 dwSize = 0 ;
49
50 SetupDiGetDeviceInterfaceDetail ( hDevInfo , & spdid , NULL , 0 , & dwSize , NULL );
51 printf ( " \n 4. %d" , GetLastError ());
52
53 if ( dwSize )
54 {
55 pspdidd = ( PSP_DEVICE_INTERFACE_DETAIL_DATA ) malloc ( dwSize );
56
57 pspdidd -> cbSize = sizeof ( * pspdidd );
58 spdd . cbSize = sizeof ( spdd );
59
60 if ( SetupDiGetDeviceInterfaceDetail ( hDevInfo , & spdid , pspdidd , dwSize , & dwSize , & spdd ))
61 {
62 printf ( " \n 5. %d" , GetLastError ());
63 printf ( "Name fuer CreateFile(): %s" , pspdidd -> DevicePath );
64
65 if ( SetupDiGetDeviceRegistryProperty ( hDevInfo , & spdd , SPDRP_FRIENDLYNAME , & dwType ,( PBYTE ) szProperty , sizeof ( szProperty ), NULL ))
66 {
67 printf ( " \n 6. %d" , GetLastError ());
68 if ( dwType == REG_SZ )
69 printf ( "FriendlyName: %s \n " , szProperty );
70 }
71 if ( SetupDiGetDeviceRegistryProperty ( hDevInfo , & spdd , SPDRP_DEVICEDESC , & dwType ,( PBYTE ) szProperty , sizeof ( szProperty ), NULL ))
72 {
73 printf ( " \n 7. %d" , GetLastError ());
74 if ( dwType == REG_SZ )
75 printf ( "DeviceDescription: %s" , szProperty );
76 }
77 }
78
79 }
80 SetupDiDestroyDeviceInfoList ( hDevInfo );
81 DeviceHandle = CreateFile (( LPCTSTR ) pspdidd -> DevicePath , GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING , FILE_FLAG_OVERLAPPED , NULL );
82 printf ( " \n 8. %d" , GetLastError ());
83 HidD_GetAttributes ( DeviceHandle , & Attributes );
84
85 printf ( " \n 9. %d" , GetLastError ());
86 printf ( " \n VendorID : %X" , Attributes . VendorID );
87 printf ( " \n ProductID: %X" , Attributes . ProductID );
88 printf ( " \n Version : %X" , Attributes . VersionNumber );
89
90 HidD_GetPreparsedData ( DeviceHandle , & PreparsedData );
91 printf ( " \n 10. %d" , GetLastError ());
92
93 HidP_GetCaps ( PreparsedData , & Capabilities );
94 printf ( " \n 11. %d" , GetLastError ());
95 printf ( " \n Usage: %X "
96 " \n UsagePage: %X "
97 " \n InputReport: %X "
98 " \n Outputreport: %X "
99 " \n FeatureReportByteLength: %X"
100 " \n NumberLinkCollectionNodes: %X"
101 " \n NumberInputButtonCaps: %X"
102 " \n NumberInputValueCaps: %X"
103 " \n NumberInputDataIndices: %X"
104 " \n NumberFeatureButtonCaps: %X"
105 " \n NumberFeatureValueCaps: %X"
106 " \n NumberFeatureDataIndices: %X" ,
107 Capabilities . Usage ,
108 Capabilities . UsagePage ,
109 Capabilities . InputReportByteLength ,
110 Capabilities . OutputReportByteLength ,
111 Capabilities . FeatureReportByteLength ,
112 Capabilities . NumberLinkCollectionNodes ,
113 Capabilities . NumberInputButtonCaps ,
114 Capabilities . NumberInputValueCaps ,
115 Capabilities . NumberInputDataIndices ,
116 Capabilities . NumberFeatureButtonCaps ,
117 Capabilities . NumberFeatureValueCaps ,
118 Capabilities . NumberFeatureDataIndices );
119
120 HidD_FreePreparsedData ( PreparsedData );
121 printf ( " \n 12. %d" , GetLastError ());
122
123 InputReport = ( DWORD * ) malloc ( Capabilities . InputReportByteLength );
124 // OutputReport = (DWORD*) malloc(Capabilities.OutputReportByteLength);
125
126 hEventObject = CreateEvent ( NULL , TRUE , TRUE , "" );
127 printf ( " \n 13. %d" , GetLastError ());
128 s_overlapped . hEvent = hEventObject ;
129 s_overlapped . Offset = 0 ;
130 s_overlapped . OffsetHigh = 0 ;
131
132 // OutputReport[0] = 0x01;
133 // OutputReport[1] = 0x02;
134
135 // WriteFile(DeviceHandle,OutputReport,Capabilities.OutputReportByteLength,&numBytesReturned,(LPOVERLAPPED)&s_overlapped);
136 Return = ReadFile ( DeviceHandle , InputReport , Capabilities . InputReportByteLength , & numBytesReturned ,( LPOVERLAPPED ) & s_overlapped );
137
138 printf ( " \n NumBytesReturned: %d" , numBytesReturned );
139 printf ( " \n %X" , InputReport );
140 printf ( " \n 14. %d" , GetLastError ());
141 return ( 0 );
142 }
X
Xenu
Gast
05.10.2007 11:49
#669249
>Dort bekomm ich dann immer ein ERROR_IO_PENDING.
Das heisst bei einem Overlapped-Read nur, dass die Datenübertragung noch
andauert. Du musst mit WaitForSingleObject() auf das Ende der
Datenübertragung warten.
K
Knopf
Gast
17.11.2007 08:22
#703856
Ich stehe vor dem gleichen Problem.
Kannst Du als Beispielcode die PC und die Firmware mal posten. For allem
jene die funktioniert.
Danke
Ralf
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.
Noch kein Account?
Die Registrierung ist kostenlos und dauert nur eine Minute.
Jetzt registrieren