list.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include <ftdi.h>
36 #include <stdio.h>
37 
38 
39 int main(int argc, char **argv)
40 {
41 
42  // Initialize FTDI context
43  struct ftdi_context ftdic;
44  ftdi_init(&ftdic);
45 
46  // List devices
47  int ret = 0;
48  struct ftdi_device_list *devlist;
49  if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) >= 0) {
50  printf("Found %i FTDI devices\n", ret);
51  struct ftdi_device_list *curdev;
52  char manufacturer[128], description[128], serial[128];
53  int i = 0;
54  for (curdev = devlist; curdev != NULL; i++) {
55  printf("Checking device: %d\n", i);
56  if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0) {
57  printf("ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
58  break;
59  }
60  printf("Manufacturer: %s, Description: %s, Serial: %s\n", manufacturer, description, serial);
61  curdev = curdev->next;
62  }
63  } else {
64  printf("ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
65  }
66  ftdi_list_free(&devlist);
67 
68  // De-initialize FTDI context
69  ftdi_deinit(&ftdic);
70 
71  return 0;
72 }
73 
int main(int argc, char **argv)
Definition: list.cpp:39


sainsmart_relay_usb
Author(s): Kevin Hallenbeck
autogenerated on Fri Feb 5 2021 03:33:42