Home Forums C Programming USB programming

Viewing 0 reply threads
  • Author
    Posts
    • #2036
      bill
      Participant

      The purpose of this program is to establish communincation b/n the USB device. Here in the program the bolded if loop is failing and the in the debug condition im getting this result
      InterfaceClassGuid {CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC} as this is failing here
      and the program returns from this if loop
       
      The following is the way i have tried

      DEFINE_GUID(USBIODS_GUID,0x1f537664, 0x37a9, 0x48c1, 0x96, 0xe7, 0x1a, 0x8a, 0x18, 0x48, 0x41, 0xfd);
      // {1F537664-37A9-48c1-96E7-1A8A184841FD}

      HDEVINFO hInfo = SetupDiGetClassDevs((struct _GUID *)&USBIODS_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

      int i;
      char *Devices[10]; // an array of cstrings
      char name[150];
      for ( i=0; ; ++i)
      {
      SP_INTERFACE_DEVICE_DATA Interface_Info;

      Interface_Info.cbSize = sizeof(Interface_Info);
      // Enumerate device


      if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
      &USBIODS_GUID,i, &Interface_Info))
      {
      SetupDiDestroyDeviceInfoList(hInfo);
      return(i);
      }

      DWORD needed; // get the required lenght
      SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info,
      NULL, 0, &needed, NULL);

      PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
      if (!detail)
      {
      SetupDiDestroyDeviceInfoList(hInfo);
      return(i);
      }

      detail->cbSize =
      sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
      if (!SetupDiGetInterfaceDeviceDetail(hInfo,&Interface_Info,detail, needed,NULL, NULL))
      {
      free((PVOID) detail);
      SetupDiDestroyDeviceInfoList(hInfo);
      return(i);
      }
      strncpy(name, detail->DevicePath, sizeof(name));
      free((PVOID) detail);
      strcpy(Devices,name); // keep a copy of each device name
      printf("%s", name);
      }
      HANDLE hUsbDevice = CreateFile(name, GENERIC_READ |GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      }

      This is the way i have used, kindly suggest any changes to be done for the same as the

      if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
      &USBIODS_GUID,i, &Interface_Info))

      is failing and entering the if condition in the code

Viewing 0 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.