1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2023, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
#include <mrpt/comms/CInterfaceFTDI.h>
#include <mrpt/system/datetime.h>
#include <mrpt/system/os.h>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <thread>
using namespace mrpt;
using namespace mrpt::comms;
using namespace std;
// ------------------------------------------------------
// Test_EnumerateDevices
// ------------------------------------------------------
void Test_EnumerateDevices()
{
CInterfaceFTDI usbDevice;
unsigned long nConectedDevices;
TFTDIDeviceList lstDevs;
while (!mrpt::system::os::kbhit())
{
// Create list of devices:
usbDevice.ListAllDevices(lstDevs);
nConectedDevices = (unsigned long)lstDevs.size();
cout << "There are " << nConectedDevices << " USB devices - "
<< mrpt::system::dateTimeToString(mrpt::system::getCurrentTime())
<< endl;
for (size_t i = 0; i < nConectedDevices; i++)
cout << lstDevs[i] << endl;
printf("\nPRESS ANY KEY TO END THE PROGRAM...\n\n");
cout.flush();
std::this_thread::sleep_for(500ms);
};
}
int main()
{
try
{
Test_EnumerateDevices();
return 0;
}
catch (const std::exception& e)
{
std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
return -1;
}
catch (...)
{
printf("Another exception!!");
return -1;
}
}
|