Commit | Line | Data |
---|---|---|
bf956a00 TJ |
1 | /* find_all.c |
2 | ||
3 | Example for ftdi_usb_find_all() | |
4 | ||
5 | This program is distributed under the GPL, version 2 | |
6db32169 TJ |
6 | */ |
7 | ||
8 | #include <stdio.h> | |
579b006f | 9 | #include <stdlib.h> |
6db32169 TJ |
10 | #include <ftdi.h> |
11 | ||
6ac169ea | 12 | int main(void) |
6db32169 TJ |
13 | { |
14 | int ret, i; | |
15 | struct ftdi_context ftdic; | |
16 | struct ftdi_device_list *devlist, *curdev; | |
17 | char manufacturer[128], description[128]; | |
18 | ||
6ac169ea TJ |
19 | if (ftdi_init(&ftdic) < 0) |
20 | { | |
21 | fprintf(stderr, "ftdi_init failed\n"); | |
22 | return EXIT_FAILURE; | |
23 | } | |
6db32169 | 24 | |
22d12cda TJ |
25 | if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) < 0) |
26 | { | |
6db32169 TJ |
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; | |
22d12cda TJ |
34 | for (curdev = devlist; curdev != NULL; i++) |
35 | { | |
6db32169 | 36 | printf("Checking device: %d\n", i); |
22d12cda TJ |
37 | if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) |
38 | { | |
6db32169 TJ |
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 | } |