2015-01-07 3 views
0

프로그래밍 방식으로을 나열하고 싶습니다. 기본적으로, 내가 시도한 것은 USB 포트와 PS2 포트에서 얼마나 많은 장치가 연결되어 있는지 확인하는 것입니다.연결된 모든 장치를 나열하는 API?

+0

참조 http://stackoverflow.com/questions/13927475/windows-how-to-enumerate-all-connected-usb-devices-device-path/13928035 # 13928035 USB 장치 열거. – Michael

답변

0

SetupDiEnumDeviceInterfaces 및 SetupDiGetDeviceInterfaceDetail (http://msdn.microsoft.com/en-us/library/windows/hardware/ff551120%28v=vs.85%29.aspx)을 사용하면 Windows에 대한 세부 정보를 얻을 수 있습니다. 반복 SetupDiEnumDeviceInterfaces 모든 연결된 장치를 가져온 다음 연결된 장치에 대한 자세한 정보를 얻을 수 SetupDiGetDeviceInterfaceDetail를 호출하는 전화 https://gist.github.com/rakesh-gopal/9ac217aa218e32372eb4

SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &GUID_DEVINTERFACE_USB_DEVICE,dwMemberIdx, DevIntfData); 
SetupDiGetDeviceInterfaceDetail(hDevInfo, &DevIntfData, NULL, 0, &dwSize, NULL); 

아이디어가 있습니다 :

다음은 샘플 코드입니다.

libusb를 사용하여 유닉스 계열 시스템에서 lsusb와 유사한 출력을 얻을 수도 있습니다. -lusb 플래그를 on으로 컴파일해야합니다. 코드가 여기에

을 libusb를 사용하고 : https://gist.github.com/rakesh-gopal/12d4094e2b882b44cb1d

#include <stdio.h> 
#include <usb.h> 
main(){ 
    struct usb_bus *bus; 
    struct usb_device *dev; 
    usb_init(); 
    usb_find_busses(); 
    usb_find_devices(); 
    for (bus = usb_busses; bus; bus = bus->next) 
     for (dev = bus->devices; dev; dev = dev->next){ 
      printf("Trying device %s/%s\n", bus->dirname, dev->filename); 
      printf("\tID_VENDOR = 0x%04x\n", dev->descriptor.idVendor); 
      printf("\tID_PRODUCT = 0x%04x\n", dev->descriptor.idProduct); 
     } 
} 
+0

비슷한 ** 기본 API **가 있습니까? –

+0

@sonugupta 표준 C 사양은 원하는 경우 USB 장치를 나열하거나 상호 작용할 API를 제공하지 않습니다. USB를 다루려면 라이브러리를 사용해야합니다. BTW, Unix 계열 시스템 용 솔루션을 포함하도록 내 대답을 편집하겠습니다. –