| 1 | /* find_all.c |
| 2 | |
| 3 | Example for ftdi_usb_find_all() |
| 4 | |
| 5 | This program is distributed under the GPL, version 2 |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <ftdi.h> |
| 11 | |
| 12 | int main(void) |
| 13 | { |
| 14 | int ret, i; |
| 15 | struct ftdi_context ftdic; |
| 16 | struct ftdi_device_list *devlist, *curdev; |
| 17 | char manufacturer[128], description[128]; |
| 18 | |
| 19 | if (ftdi_init(&ftdic) < 0) |
| 20 | { |
| 21 | fprintf(stderr, "ftdi_init failed\n"); |
| 22 | return EXIT_FAILURE; |
| 23 | } |
| 24 | |
| 25 | if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) < 0) |
| 26 | { |
| 27 | fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic)); |
| 28 | return EXIT_FAILURE; |
| 29 | } |
| 30 | |
| 31 | printf("Number of FTDI devices found: %d\n", ret); |
| 32 | |
| 33 | i = 0; |
| 34 | for (curdev = devlist; curdev != NULL; i++) |
| 35 | { |
| 36 | printf("Checking device: %d\n", i); |
| 37 | if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) |
| 38 | { |
| 39 | fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic)); |
| 40 | return EXIT_FAILURE; |
| 41 | } |
| 42 | printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description); |
| 43 | curdev = curdev->next; |
| 44 | } |
| 45 | |
| 46 | ftdi_list_free(&devlist); |
| 47 | ftdi_deinit(&ftdic); |
| 48 | |
| 49 | return EXIT_SUCCESS; |
| 50 | } |