init files
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#ifndef Hd_SocketModule_MES_H
|
||||
#define Hd_SocketModule_MES_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QByteArray>
|
||||
#include <QThread>
|
||||
#include <iostream>
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
#include <QDebug>
|
||||
#include <Windows.h>
|
||||
|
||||
#include "base.h"
|
||||
class MyThread;
|
||||
class Hd_SocketModule_MES :public Base
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//创建,这里new一下锁
|
||||
Hd_SocketModule_MES();
|
||||
//释放,删除连接,释放锁
|
||||
virtual ~Hd_SocketModule_MES();
|
||||
//向主线程发送数据,通信Mat为空
|
||||
//主线程根据通信流程解析数据段。
|
||||
//先writeData,再readData;
|
||||
//从类中读数据到实例对象。通信类返回的内容,只包含数据段,不含包头。
|
||||
bool readData(std::vector<cv::Mat>& vec_mat, QByteArray& data);//readData将PLC读取或者发送的返回值发回给主线程,通过全局变量的方式逐条发送
|
||||
//data为json数据;包含http时,为设置
|
||||
bool writeData(std::vector<cv::Mat>& vec_mat, QByteArray& data); //writeData调用PLC的收发,将需要的数据发给寄存器,返回OK/NG
|
||||
//初始化,未使用
|
||||
bool initParas(QByteArray&);
|
||||
//运行;先initParas,再run;
|
||||
bool run();
|
||||
//检查异常标志
|
||||
bool checkStatus();
|
||||
private:
|
||||
|
||||
QMutex* m_Mutex = nullptr;
|
||||
MyThread* m_Thread = nullptr;
|
||||
|
||||
};
|
||||
|
||||
//自己创建线程
|
||||
class MyThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MyThread(QObject* parent = nullptr) :QThread(parent) {}
|
||||
~MyThread();
|
||||
void setUrl(QString qurl);
|
||||
void run();
|
||||
private:
|
||||
QNetworkAccessManager* net_mgr;
|
||||
QNetworkRequest net_request;
|
||||
QTimer* mytimer = nullptr;
|
||||
|
||||
public slots:
|
||||
void finishedSlot(QNetworkReply*);
|
||||
};
|
||||
extern "C"
|
||||
{
|
||||
Q_DECL_EXPORT Hd_SocketModule_MES * create();
|
||||
Q_DECL_EXPORT void destory(Hd_SocketModule_MES * ptr);
|
||||
}
|
||||
|
||||
#endif // Hd_SocketModule_MES_H
|
||||
Reference in New Issue
Block a user