2023-11-29 15:36:45 +08:00
|
|
|
#ifndef if_uart_h__
|
|
|
|
#define if_uart_h__
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <interface/interface.h>
|
|
|
|
#include "QTimer"
|
|
|
|
#include <QThread>
|
|
|
|
#include <QTimer>
|
|
|
|
#include "QByteArray"
|
|
|
|
#include "base/mycfg.h"
|
2023-12-02 11:27:25 +08:00
|
|
|
#include <QSerialPort> // 提供访问串口的功能
|
|
|
|
#include <QSerialPortInfo> // 提供系统中存在的串口信息
|
2023-11-29 15:36:45 +08:00
|
|
|
|
|
|
|
class if_uart : public InterFace
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-12-02 11:27:25 +08:00
|
|
|
if_uart(mystring com, int bsp) : InterFace()
|
|
|
|
{
|
2023-11-29 15:36:45 +08:00
|
|
|
this->com = com;
|
|
|
|
this->bsp = bsp;
|
2023-12-02 11:27:25 +08:00
|
|
|
serial_ = nullptr;
|
|
|
|
serial_open = false;
|
2023-11-29 15:36:45 +08:00
|
|
|
}
|
2023-12-02 11:27:25 +08:00
|
|
|
virtual ~if_uart()
|
|
|
|
{
|
|
|
|
if (serial_open == true)
|
|
|
|
{
|
2023-11-29 15:36:45 +08:00
|
|
|
serial_->close();
|
|
|
|
delete serial_;
|
|
|
|
}
|
2023-12-02 11:27:25 +08:00
|
|
|
}
|
2023-11-29 15:36:45 +08:00
|
|
|
void init();
|
|
|
|
int write(myarray data);
|
|
|
|
protected slots:
|
|
|
|
void ready_read_cb();
|
|
|
|
|
2023-12-02 11:27:25 +08:00
|
|
|
protected:
|
|
|
|
mystring com;
|
|
|
|
int bsp;
|
|
|
|
QSerialPort *serial_;
|
|
|
|
bool serial_open;
|
2023-11-29 15:36:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|