-
Notifications
You must be signed in to change notification settings - Fork 1
/
easyModbus02.h
53 lines (42 loc) · 1.29 KB
/
easyModbus02.h
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
#pragma once
#include <QDebug>
#include <QSerialPort>
#include <QtSerialPort\qserialport.h>
#include <QtSerialPort\qserialportinfo.h>
#include <QString>
#include <string>
#include <iostream>
#include <FxPlc.h>
//#pragma comment(lib,"FxPlc.lib")
/**
* @brief 以ASCII的编码与PLC进行通讯
* 类设计原理:
* 1.类的构造函数分为easyModbus2(int) 功能是指定写入寄存器
* 2.int initSerialPort() -- 自动检测并初始化串口并返回初始化串口的状态
* 3.sengMsg 发送消息至串口
* 4.readMsg 读取串口
* @author George
* @date 2019-07-04
*/
class easyModbus2
{
public:
easyModbus2() = default;
easyModbus2(int numberOfRegister);
~easyModbus2();
int initSerialPort();
void sendMsg(QString input); //发送数据
void sendMsg(int intInput); //发送整形角度数据
QByteArray readMsg(); //接收数据
private:
bool hasMatchPort = false;
QSerialPort serialPort; //串口类
QString serialPortName; //打开的串口
// ==== The setting of modbus ===== //
//// == register == ////
int numberOfRegister = 2000;
//// == Matching message == ////
QString matchMessageSend = ""; // int 0
QString matchMessageRight = "06"; // 发送消息正确后的道德回复
FxLib fxlib;
};