-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmythread.cpp
More file actions
56 lines (48 loc) · 1.07 KB
/
Copy pathmythread.cpp
File metadata and controls
56 lines (48 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "MyThread.h"
#include <QMetaObject>
#include <QDebug>
MyThread::MyThread(QObject *parent)
: QThread{parent}
{
stopped=false;
}
void MyThread::run()
{
MC_3E=new Mitsubishi_MC_3E_bin(this);
MC_3E->open("127.0.0.1",6000,1000);
address="D100";
regType="int";
count=1;
unsigned short value;
QString adr2="D101";
qDebug()<<"MyThread通信实例线程ID:"<<QThread::currentThreadId();
this->msleep(1000);
qreal i=0;
bool flag;
while(!stopped)
{
this->msleep(3);
//MC_3E->writeInt(adr2,2);
value=MC_3E->readUShort(address);
if(value==1)
MC_3E->writeUShort(adr2,2);
else if(value==0)
MC_3E->writeUShort(adr2,3);
if(value==0 && MC_3E->readUShort("D102")==1) MC_3E->writeShort("D103",56);
}
stopped=false;
}
void MyThread::stop()
{
stopped=true;
}
comThread::comThread(QObject *parent)
: QThread{parent}
{
;
}
void comThread::run()
{
qDebug()<<"comThread通信实例线程ID:"<<QThread::currentThreadId();
this->exec();
}