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.
74 lines
1.9 KiB
74 lines
1.9 KiB
#pragma once
|
|
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
//
|
|
|
|
#include <winsock2.h>
|
|
//
|
|
#include <Windows.h>
|
|
//
|
|
#include <QtSerialPort/QSerialPort>
|
|
#include <QtSerialPort/QSerialPortInfo>
|
|
//
|
|
#include "zqui\base\zqthread.hpp"
|
|
|
|
#define SDK_VERSION 1
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
// QT_CHARTS_USE_NAMESPACE
|
|
|
|
class QTSerialChannel {
|
|
function<void(uint8_t *data, size_t len)> m_rxcb;
|
|
|
|
QSerialPort::DataBits m_dataBits;
|
|
QSerialPort::Parity m_parity;
|
|
QSerialPort::StopBits m_stopBits;
|
|
QSerialPort::FlowControl m_flowControl;
|
|
string m_name;
|
|
|
|
unique_ptr<thread> m_thread;
|
|
|
|
uint32_t m_baudRate;
|
|
HANDLE m_CommHandler;
|
|
|
|
bool m_isOpen = false;
|
|
|
|
public:
|
|
void init();
|
|
|
|
virtual bool isOpen();
|
|
virtual bool send(const uint8_t *data, size_t len);
|
|
virtual void regRxListener(function<void(uint8_t *data, size_t len)> cb);
|
|
|
|
bool open();
|
|
void close();
|
|
|
|
bool setBaudRate(qint32 baudRate) { m_baudRate = baudRate; }
|
|
qint32 baudRate() const { return m_baudRate; }
|
|
|
|
void setPortName(string name) { m_name = name; }
|
|
void setDataBits(QSerialPort::DataBits dataBits) { m_dataBits = dataBits; }
|
|
void setParity(QSerialPort::Parity parity) { m_parity = parity; }
|
|
void setStopBits(QSerialPort::StopBits stopBits) { m_stopBits = stopBits; }
|
|
void setFlowControl(QSerialPort::FlowControl flowControl) { m_flowControl = flowControl; }
|
|
|
|
QSerialPort::DataBits dataBits() const { return m_dataBits; }
|
|
QSerialPort::Parity parity() const { return m_parity; }
|
|
QSerialPort::StopBits stopBits() const { return m_stopBits; }
|
|
QSerialPort::FlowControl flowControl() const { return m_flowControl; }
|
|
|
|
private:
|
|
int com_receive(uint8_t *rxbuf, int rxbufsize);
|
|
};
|
|
} // namespace iflytop
|