Salut à tous,
je cherche comment je peux lire et écrire des données à travers le port usb de mon pc. :
Salut à tous,
je cherche comment je peux lire et écrire des données à travers le port usb de mon pc. :
Sous noyau NT, tu es bon pour un Driver.
Va voir :
---> ici
Tu y trouveras un dossier pdf. Un projet d'un étudiant de L' INSA de Lyon. A la fin du dossier, tu trouveras toute l'étude concernant l'interfacage USB ... et le developpement du Driver concernant cette communication USB. C'est intéressant ... mais bon, faut déjà quelques bases concernant le développement des drivers, sinon, tu risques de patauger. Dans ce cas, faudra reprendre le sujet depuis le début.
On a un peu abordé ce sujet ici récemment, et sinon y'a un topic avec des infos dans le forum Visual C++ (recherche).
voila avec ca tu peut deja etablir une connexion, cad avoir un handle du port mais apres pour lire et ecrire jai quelques soucis,
Sinon jaurais voulu savoir jarrive aavoir le handle du port lorsque ma cle et connecté au port usb comment pourrais je faire pour creer un fichier texte a linterieur...?
a oui et les GUID ne sont pas forcement les memes que toi...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 #include <stdio.h> #include <stdlib.h> #include <objbase.h> //mais ares jai quelque souci je narrive pas a aller plus loin // you may have to manually include this library. #include <initguid.h> //USBIO_GUID //#include <conio.h> // ? unnecessary for the moment //displayPeriph libs #include <windows.h> //#include <devguid.h> #include <regstr.h> #pragma comment (lib,"setupapi.lib") #define INITGUID int main() { //GUID hidGUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}}; //GUID hidGUID = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}}; /*ROOT_HSB*/GUID hidGUID = {0xf18a0e88, 0xc30c, 0x11d0, {0x88, 0x15, 0x00, 0xa0, 0xc9, 0x06, 0xbe, 0xd8}}; //GUID hidGUID = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}}; ///*DOUCHETTE*/GUID hidGUID = {0x745a17a0L, 0x74d3, 0x11d0, {0xb6, 0xfe, 0x00, 0xa0, 0xc9, 0x0f, 0x57, 0xda}}; ///*DOUCHETTE*/GUID hidGUID = {0xA5DCBF10L, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}}; HDEVINFO hDevInfo; SP_INTERFACE_DEVICE_DATA InterfaceDeviceInfoData; hDevInfo = SetupDiGetClassDevs(&hidGUID, 0, 0, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if (hDevInfo == INVALID_HANDLE_VALUE) { printf("Erreur SetUpDiGetClassDevs\n"); return 0; } SP_DEVINFO_DATA DeviceInfoData; DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); int nb = SetupDiEnumDeviceInfo(hDevInfo,0,&DeviceInfoData); for (int i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++) { InterfaceDeviceInfoData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA); DWORD needed; if (!SetupDiEnumDeviceInterfaces(hDevInfo,NULL,&hidGUID,i,&InterfaceDeviceInfoData)) { SetupDiDestroyDeviceInfoList(hDevInfo); printf("erreur setupenumdevice\n"); return 0; } //une première fois afin de connaître la taille de la zone mémoire à réserver (needed) SetupDiGetDeviceInterfaceDetail(hDevInfo,&InterfaceDeviceInfoData,NULL,0,&needed,NULL); //on réserve la taille mémoire PSP_DEVICE_INTERFACE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) new char[needed]; if (!detail) { printf("Problème mémoire PSP_INTERFACE_DEVICE_DETAIL_DATA"); SetupDiDestroyDeviceInfoList(hDevInfo); return 0; } //on cherche le "nom" du device detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); if (!SetupDiGetDeviceInterfaceDetail(hDevInfo,&InterfaceDeviceInfoData,detail,needed,NULL,NULL)) { delete detail; printf("Aucune information de détail"); SetupDiDestroyDeviceInfoList(hDevInfo); return 0; } printf("device path %s\n",detail->DevicePath); HANDLE hCom; hCom = CreateFile(detail->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); DWORD test = GetLastError(); if (hCom == INVALID_HANDLE_VALUE) { LPSTR Message; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,test, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPSTR)&Message,0,NULL); printf("invalid handle %s\n",Message); } else { printf("HANDLE Correct\n",hCom); } /*char* command=(char*)malloc(100); command="yayayayayaya"; DWORD nboce; int retour; retour=WriteFile(hCom,command,11,&nboce,NULL); if((retour==0) || (nboce<=0)) { return 0; }*/ } SetupDiDestroyDeviceInfoList(hDevInfo); return 0; }
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager