get_serial_number.cpp
Go to the documentation of this file.
1 
11 #include <iostream>
12 
13 #include "kobuki_ftdi/scanner.hpp"
14 
15 int main(int /* argc */, char** /* argv */)
16 {
17  int ret_val;
18  FTDI_Scanner scanner;
19 
20  ret_val = scanner.scan();
21  if (ret_val <= 0) {
22  std::cout << "FTDI device not found!!!" << std::endl;
23  return -1;
24  }
25 
26  unsigned int no_devices = (unsigned int)ret_val;
27  std::cout << no_devices << " device(s) found." << std::endl;
28 
29  std::string serial_number, manufacturer, product;
30  for( unsigned int i=0; i<no_devices; i++ )
31  {
32  ret_val = scanner.get_serial_id(i, serial_number);
33  if (ret_val < 0) break;
34 
35  ret_val = scanner.get_manufacturer(i, manufacturer);
36  if (ret_val < 0) break;
37 
38  ret_val = scanner.get_product(i, product);
39  if (ret_val < 0) break;
40 
41  std::cout << std::endl;
42  std::cout << "Device #" << i << std::endl;
43  std::cout << " Manufacturer : " << manufacturer << std::endl;
44  std::cout << " Product : " << product << std::endl;
45  std::cout << " Serial Number: " << serial_number << std::endl;
46  ret_val = 0;
47  }
48 
49  if (ret_val < 0) std::cerr << "Something went wrong. Did you run with sudo." << std::endl;
50  return ret_val;
51 }
main
int main(int, char **)
Definition: get_serial_number.cpp:15
FTDI_Scanner::scan
int scan()
Definition: scanner.hpp:93
FTDI_Scanner::get_serial_id
int get_serial_id(unsigned int index, std::string &serial_id)
Definition: scanner.hpp:147
FTDI_Scanner::get_manufacturer
int get_manufacturer(unsigned int index, std::string &manufacturer)
Definition: scanner.hpp:162
FTDI_Scanner::get_product
int get_product(unsigned int index, std::string &product)
Definition: scanner.hpp:177
FTDI_Scanner
A Scanner class.
Definition: scanner.hpp:56
scanner.hpp
Scan the usb devices, and retrieve its serial id and else descriptions, especially for ftdi devices.


kobuki_ftdi
Author(s): Younghun Ju
autogenerated on Wed Mar 2 2022 00:26:19