[問題] 請問我這樣取得vid & pid有什麼問題

看板LinuxDev作者 (evilkiss)時間10年前 (2013/08/27 17:05), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
最近需要開機自動執行程式,要去自動辨別哪一個hiddev才是我們操作的裝置 所以我用Vid Pid來判別,google了一下,寫了下面的測試程式 但結果好像錯很大,請問我哪邊做錯了? ======================================================= #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <linux/hiddev.h> 改成hidraw.h #include <sys/ioctl.h> struct hiddev_devinfo device_info; 改成hidraw_devinfo #define MODEMDEVICE "/dev/hidraw5" char *HidrawList[6]={"/dev/hidraw0","/dev/hidraw1","/dev/hidraw2", "/dev/hidraw3","/dev/hidraw4","/dev/hidraw5"}; int main() { int id; for(id=0;id<6;id++) { printf("%s is %d\n",HidrawList[id], TestDevice(HidrawList[id])); } return 0; } int TestDevice(char* name) { int fd; fd = open(name, O_RDWR | O_NOCTTY ); if (fd <0) { printf("Open device failed!\n"); return -1; } ioctl(fd,HIDIOCGDEVINFO,&device_info); 改成 HIDIOCGRAWINFO printf("vid = 0x%04hx, pid = 0x%04hx\n",device_info.vendor ,device_info.product); if(device_info.vendor==0x04d8) { close(fd); return 1; } else { close(fd); return -1; } } 得到的答案是 : vid = 0x0000, pid = 0x0000 /dev/hidraw0 is -1 vid = 0x0000, pid = 0x0000 /dev/hidraw1 is -1 vid = 0x0000, pid = 0x0000 /dev/hidraw2 is -1 vid = 0x0000, pid = 0x0000 /dev/hidraw3 is -1 vid = 0x0000, pid = 0x0000 /dev/hidraw4 is -1 vid = 0x0000, pid = 0x0000 /dev/hidraw5 is -1 但lsusb的結果卻是 : Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 002: ID 1bc0:8100 Bus 003 Device 006: ID 413c:3012 Dell Computer Corp. Optical Wheel Mouse Bus 002 Device 007: ID 1c4f:0016 SiGma Micro Bus 001 Device 046: ID 05e3:0610 Genesys Logic, Inc. 4-port hub Bus 001 Device 047: ID 0d8c:0126 C-Media Electronics, Inc. Bus 001 Device 048: ID 04d8:00df Microchip Technology, Inc. 請問我哪個步驟做錯了? 謝謝,大家的幫忙 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.72.92.44 ※ 編輯: evilkiss 來自: 211.72.92.44 (08/27 17:37)

08/27 17:58, , 1F
找到問題了.... 把hiddev相關的換成hidraw
08/27 17:58, 1F
※ 編輯: evilkiss 來自: 211.72.92.44 (08/27 18:00)
文章代碼(AID): #1I76lLDS (LinuxDev)