summaryrefslogtreecommitdiff
path: root/printerclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'printerclient.cpp')
-rw-r--r--printerclient.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/printerclient.cpp b/printerclient.cpp
index c5bf189..a78de50 100644
--- a/printerclient.cpp
+++ b/printerclient.cpp
@@ -5,10 +5,22 @@
#include <QDebug>
#include <QFile>
#include <QSerialPort>
+#include <QSerialPortInfo>
-PrinterClient::PrinterClient(QObject *parent)
- : QObject { parent }
- , m_serialPort { new QSerialPort { "/dev/ttyUSB0", this } }
+QString getFirstTtyUSB()
+{
+ auto ports = QSerialPortInfo::availablePorts();
+
+ std::remove_if(ports.begin(), ports.end(), [](const auto& port) {
+ return !port.portName().contains("ttyUSB");
+ });
+
+ return ports.isEmpty() ? "" : ports.first().portName();
+}
+
+PrinterClient::PrinterClient(QObject* parent)
+ : QObject{parent} // , m_serialPort{new QSerialPort{"/dev/ttyUSB0", this}}
+ , m_serialPort{new QSerialPort{getFirstTtyUSB(), this}}
{
if (!m_serialPort->setBaudRate(QSerialPort::Baud115200)) {
throw std::runtime_error(