using serial lib, can connect to device
parent
65b755658c
commit
6473b57cef
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "gui/gui/serial"]
|
||||||
|
path = gui/gui/serial
|
||||||
|
url = https://github.com/wjwwood/serial
|
||||||
|
[submodule "gui/serial"]
|
||||||
|
path = gui/serial
|
||||||
|
url = https://github.com/wjwwood/serial
|
@ -0,0 +1 @@
|
|||||||
|
Subproject commit cbcca7c83745fedd75afb7a0a27ee5c4112435c2
|
@ -1,31 +1,17 @@
|
|||||||
#include "stmdsp.hpp"
|
#include "stmdsp.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <serial/serial.h>
|
||||||
#include <filesystem>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
|
||||||
namespace stmdsp
|
namespace stmdsp
|
||||||
{
|
{
|
||||||
void scanner::scan()
|
std::list<std::string>& scanner::scan()
|
||||||
{
|
{
|
||||||
std::string path ("/dev/ttyACM0");
|
auto serialDevices = serial::list_ports();
|
||||||
|
for (auto& device : serialDevices) {
|
||||||
for (unsigned int i = 0; i < 10; i++) {
|
if (device.hardware_id.find(STMDSP_USB_ID) != std::string::npos)
|
||||||
path.back() = '0' + i;
|
m_devices.emplace_front(device.port);
|
||||||
if (std::filesystem::exists(path)) {
|
|
||||||
if (device dev (path); dev.open()) {
|
|
||||||
dev.write("i", 1);
|
|
||||||
std::this_thread::sleep_for(1s);
|
|
||||||
char buf[7];
|
|
||||||
if (dev.read(buf, 6) == 6) {
|
|
||||||
buf[6] = '\0';
|
|
||||||
if (std::string(buf) == "stmdsp")
|
|
||||||
m_devices.emplace(std::move(dev));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return m_devices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue