74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
|
#ifndef LOTMACHINE_H
|
|||
|
#define LOTMACHINE_H
|
|||
|
|
|||
|
#include "gatewaytcpclient.h"
|
|||
|
#include "comport.h"
|
|||
|
#include "comm/typedef.h"
|
|||
|
|
|||
|
#include <QThread>
|
|||
|
#include <QTimer>
|
|||
|
#include <QDebug>
|
|||
|
#include <QStringList>
|
|||
|
|
|||
|
#define USE_TCP_COMM 0
|
|||
|
#define USE_SERIAL_COMM 1
|
|||
|
|
|||
|
class LotMachine: public QObject
|
|||
|
{
|
|||
|
Q_OBJECT
|
|||
|
|
|||
|
public:
|
|||
|
explicit LotMachine(QObject *parent = NULL);
|
|||
|
virtual ~LotMachine();
|
|||
|
|
|||
|
public:
|
|||
|
void initConnectMode(s16 val = 0);//初始化通讯连接方式
|
|||
|
void setConfigFileName(QString configfilename);
|
|||
|
void setComportName(QString portName);//设置串口名称
|
|||
|
QString getConfigFileName();
|
|||
|
int startCommunication();
|
|||
|
|
|||
|
private:
|
|||
|
QString m_configFileName;
|
|||
|
QByteArray m_receiveBuff;//接收到的buf
|
|||
|
QByteArray m_keyBuff;//键值对buf
|
|||
|
s16 m_reFlag;
|
|||
|
|
|||
|
private:
|
|||
|
s16 m_connectMode; //通讯连接方式 0:网口,1:串口
|
|||
|
// 通讯线程和网络连接
|
|||
|
QThread * m_pTcpThread;
|
|||
|
GatewayTcpClient * m_pTcpClient;
|
|||
|
QThread * m_pComThread;
|
|||
|
ComPort * m_pComPort;
|
|||
|
|
|||
|
// 连接
|
|||
|
public:
|
|||
|
inline int isConnected() const { return m_connected; }
|
|||
|
|
|||
|
private:
|
|||
|
int m_startComm;
|
|||
|
int m_connected; // 机器连接状态. 0, 未连接; 1, 连接中; 2,
|
|||
|
|
|||
|
signals: // 发送数据到机器的信号
|
|||
|
void siSendData(QByteArray dat);
|
|||
|
void siRunLotDataAction(QString cmd);//执行物联网数据动作
|
|||
|
void siConnectToMqtt();//与网关已连接
|
|||
|
|
|||
|
private slots: // 和线程通讯的槽
|
|||
|
void slotConnectSta(int sta); // 连接状态改变的槽函数
|
|||
|
void slotConnectErr(QString errinfo); // 接收到通讯错误槽函数
|
|||
|
void slotReceiveData(QByteArray dat); // 接收到数据的槽函数
|
|||
|
void slotIfOpenSerialPort(int val);//串口是否打开
|
|||
|
|
|||
|
private:
|
|||
|
QString getJsonValue(QString name1,QString name2 = NULL);//获取键值对属性值
|
|||
|
|
|||
|
public:
|
|||
|
void sendLotDataToGateway(QString str);//发送物联数据到网关
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
#endif // LOTMACHINE_H
|
|||
|
|