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; | |
cd2ead2f | 15 | struct ftdi_context *ftdi; |
6db32169 TJ |
16 | struct ftdi_device_list *devlist, *curdev; |
17 | char manufacturer[128], description[128]; | |
4cc3fa8a | 18 | int retval = EXIT_SUCCESS; |
6db32169 | 19 | |
cd2ead2f | 20 | if ((ftdi = ftdi_new()) == 0) |
6ac169ea | 21 | { |
cd2ead2f | 22 | fprintf(stderr, "ftdi_new failed\n"); |
6ac169ea TJ |
23 | return EXIT_FAILURE; |
24 | } | |
6db32169 | 25 | |
cd2ead2f | 26 | if ((ret = ftdi_usb_find_all(ftdi, &devlist, 0, 0)) < 0) |
22d12cda | 27 | { |
cd2ead2f | 28 | fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); |
4cc3fa8a | 29 | retval = EXIT_FAILURE; |
4cc3fa8a | 30 | goto do_deinit; |
6db32169 TJ |
31 | } |
32 | ||
33 | printf("Number of FTDI devices found: %d\n", ret); | |
34 | ||
35 | i = 0; | |
22d12cda TJ |
36 | for (curdev = devlist; curdev != NULL; i++) |
37 | { | |
6db32169 | 38 | printf("Checking device: %d\n", i); |
cd2ead2f | 39 | if ((ret = ftdi_usb_get_strings(ftdi, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) |
22d12cda | 40 | { |
cd2ead2f | 41 | fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); |
4cc3fa8a | 42 | retval = EXIT_FAILURE; |
4cc3fa8a | 43 | goto done; |
6db32169 TJ |
44 | } |
45 | printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description); | |
46 | curdev = curdev->next; | |
47 | } | |
4cc3fa8a | 48 | done: |
6db32169 | 49 | ftdi_list_free(&devlist); |
4cc3fa8a | 50 | do_deinit: |
cd2ead2f | 51 | ftdi_free(ftdi); |
6db32169 | 52 | |
de40c606 | 53 | return retval; |
6db32169 | 54 | } |