Forráskód Böngészése

update serial port

xuqiang 4 hónapja
szülő
commit
a71f1fc4f2
1 módosított fájl, 13 hozzáadás és 11 törlés
  1. 13 11
      src/serialport.cpp

+ 13 - 11
src/serialport.cpp

@@ -2,22 +2,24 @@
 #include <QSerialPortInfo>
 #include "logger.h"
 
+#define SERIAL_PORT_DEVICE "/dev/ttyS9"
+
 SerialPort::SerialPort(QObject *parent)
     : QObject{parent}
 {
     QList<QSerialPortInfo> serialPorts = QSerialPortInfo::availablePorts();
     for (const QSerialPortInfo &info : serialPorts) {
-        LOG_INFO("Name         : {}", info.portName().toUtf8().data());
-        LOG_INFO("Description  : {}", info.description().toUtf8().data());
-        LOG_INFO("Manufacturer : {}", info.manufacturer().toUtf8().data());
-        LOG_INFO("Serial Number: {}", info.serialNumber().toUtf8().data());
-        LOG_INFO("Location     : {}", info.systemLocation().toUtf8().data());
-        LOG_INFO("Vendor ID    : {}", info.vendorIdentifier());
-        LOG_INFO("Product ID   : {}", info.productIdentifier());
-        LOG_INFO("-----------------------------------");
+        LOG_DEBUG("Name         : {}", info.portName().toUtf8().data());
+        LOG_DEBUG("Description  : {}", info.description().toUtf8().data());
+        LOG_DEBUG("Manufacturer : {}", info.manufacturer().toUtf8().data());
+        LOG_DEBUG("Serial Number: {}", info.serialNumber().toUtf8().data());
+        LOG_DEBUG("Location     : {}", info.systemLocation().toUtf8().data());
+        LOG_DEBUG("Vendor ID    : {}", info.vendorIdentifier());
+        LOG_DEBUG("Product ID   : {}", info.productIdentifier());
+        LOG_DEBUG("-----------------------------------");
     }
 
-    m_serialPort.setPortName("/dev/ttyS9"); 
+    m_serialPort.setPortName(SERIAL_PORT_DEVICE); 
     m_serialPort.setBaudRate(QSerialPort::Baud115200);
     m_serialPort.setDataBits(QSerialPort::Data8);
     m_serialPort.setParity(QSerialPort::NoParity);
@@ -25,10 +27,10 @@ SerialPort::SerialPort(QObject *parent)
     m_serialPort.setFlowControl(QSerialPort::NoFlowControl);
 
     if (!m_serialPort.open(QIODevice::ReadOnly)) {
-        LOG_ERROR("failed to open port:", m_serialPort.errorString().toUtf8().data());
+        LOG_ERROR("failed to open serial port:", m_serialPort.errorString().toUtf8().data());
         return;
     }
-
+    LOG_INFO("open serial port successfully: {}", SERIAL_PORT_DEVICE);
     ringbuffer_init(&m_ringbuffer, 64);
     memset(m_ringbuffer.data, 0 , 64);