1

firstly I must say that I'm newbie at libusb. I have a usb device and I'm writing code for this device in linux. In my code I'm displaying devices' vendor and product id. After that I'm sending datas from host to device. As expected, product id is changing. After this changing I want to display devices' vendor and product id again. Despite I see new product id when I wrote lsusb in terminal, I cannot display with code. But I can display when I run program again. Code flow likes below:

  struct    libusb_device_handle     *devh    = NULL;
              libusb_device                **devs;
              libusb_device                **devs2;
              libusb_context               *context1 = NULL;
              libusb_context               *context2 = NULL;    
              libusb_config_descriptor *config;

  libusb_init(&context1);

  libusb_set_debug(context1,3);

  counter = libusb_get_device_list(context1,&devs);

  printf("Devices in List.\n");
  ssize_t i;

  for(i = 0; i < counter; i++) printdev(devs[i]); // display function is printdev

After that, I'm sending data and product id is changing with this datas. After this changing I want to display new device list and for that first of all I'm releasing device list and closing the session.

libusb_free_device_list(devs,1);
libusb_exit(context1);

After closing the session I'm initializing new session and I want to get new device list. For that I'm doing this :

 libusb_init(&context2);
 counter = libusb_get_device_list(context2,&devs2);
 for(i = 0; i < counter ; i++) printdev(devs2[i]);

But I can't display new device list. I can display old device list. Only I can new device list display by running program again. Also I can display changing with lsusb after first product id changing process.

I don't know what the problem is.

Thanks from now for your help.

bzkrtmurat
  • 189
  • 1
  • 3
  • 15
  • Is there a delay between the command to change the vendor id and trying to get the new list ? Could it be that the device need a little time to setup or restart ? – Leiaz Jan 24 '15 at 13:31
  • @Leiaz Thanks leiaz. I wrote delay code and it's working now. I can handle new device. – bzkrtmurat Jan 26 '15 at 15:18

0 Answers0