#ifndef SERIALPORTMANAGER_H #define SERIALPORTMANAGER_H #include #include #include #include #include #include #include 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