You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- #ifndef SERIALPORTMANAGER_H
- #define SERIALPORTMANAGER_H
-
- #include <QDialog>
- #include <QSerialPort>
- #include <QComboBox>
- #include <QPushButton>
- #include <QFormLayout>
- #include <QSpinBox>
- #include <QLabel>
-
- class SerialPortManager : public QDialog
- {
- Q_OBJECT
- public:
- explicit SerialPortManager(QWidget *parent = nullptr);
- ~SerialPortManager();
-
- // 获取串口配置
- QString portName() const;
- int baudRate() const;
- QSerialPort::Parity parity() const;
- QSerialPort::StopBits stopBits() const;
- int stationAddress() const;
-
- // 新增串口操作接口
- bool isOpen() const;
- void openSerialPort();
- void closeSerialPort();
- QByteArray readAll();
- void write(const QByteArray &data);
-
- signals:
- void errorOccurred(const QString &error);
- void logMessage(const QString &message);
-
- private slots:
- void refreshPorts();
- void onConnectClicked();
- void handleReadyRead();
- void handleError(QSerialPort::SerialPortError error);
-
- private:
- void populateBaudRates();
- void populateParities();
- void updateConnectionState(bool connected);
-
- QSerialPort *m_serial; // 串口对象
- QComboBox *m_portComboBox;
- QComboBox *m_baudComboBox;
- QComboBox *m_parityComboBox;
- QSpinBox *m_stationSpinBox;
- QPushButton *m_connectBtn; // 连接/断开按钮
- QLabel *m_statusLabel; // 状态标签
- };
-
- #endif // SERIALPORTMANAGER_H
|