MRPT  2.0.1
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <mrpt/system/datetime.h>
12 #include <mrpt/system/os.h>
13 
14 #include <cstdio>
15 #include <iostream>
16 #include <thread>
17 
18 using namespace mrpt;
19 using namespace mrpt::comms;
20 using namespace std;
21 
22 // ------------------------------------------------------
23 // Test_EnumerateDevices
24 // ------------------------------------------------------
26 {
27  CInterfaceFTDI usbDevice;
28 
29  unsigned long nConectedDevices;
30 
31  TFTDIDeviceList lstDevs;
32 
33  while (!mrpt::system::os::kbhit())
34  {
35  // Create list of devices:
36  usbDevice.ListAllDevices(lstDevs);
37 
38  nConectedDevices = (unsigned long)lstDevs.size();
39 
40  cout << "There are " << nConectedDevices << " USB devices - "
42  << endl;
43 
44  for (size_t i = 0; i < nConectedDevices; i++)
45  cout << lstDevs[i] << endl;
46 
47  printf("\nPRESS ANY KEY TO END THE PROGRAM...\n\n");
48  cout.flush();
49  std::this_thread::sleep_for(500ms);
50  };
51 }
52 
53 int main()
54 {
55  try
56  {
58  return 0;
59  }
60  catch (const std::exception& e)
61  {
62  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
63  return -1;
64  }
65  catch (...)
66  {
67  printf("Another exception!!");
68  return -1;
69  }
70 }
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
Definition: datetime.h:82
std::deque< TFTDIDevice > TFTDIDeviceList
Used in CInterfaceFTDI::ListAllDevices.
STL namespace.
void ListAllDevices(TFTDIDeviceList &outList)
Generates a list with all FTDI devices connected right now.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A definition of a CStream actually representing a USB connection to a FTDI chip.
std::string dateTimeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
Definition: datetime.cpp:154
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:392
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
void Test_EnumerateDevices()
Serial and networking devices and utilities.



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020