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.

112 lines
2.8 KiB

2 years ago
#ifndef MYMODBUSTCP_H
#define MYMODBUSTCP_H
#include <QModbusTcpClient>
#include <QModbusReply>
#include <QDebug>
#include <QTimer>
#include <QDateTime>
#include <QApplication>
class MyModbusTcp : public QObject
{
public:
MyModbusTcp();
//声明modbusDevice
QModbusClient *modbusDevice;
//modbustcp接收的原始数据,以word为单位
unsigned int wordRCV[40];
//用于存放读取的数据的数组,float类型
float dataRCV[30];
// QTimer *timer = nullptr;
/**
* @brief timeGoBy t毫秒
* @param time
* @param t
*/
void timeGoBy(QTime time, int t);
/**
* @brief connectModbusTcp modbustcp
*/
void connectModbusTcp();
/**
* @brief disconnectModbusTcp
*/
void disconnectModbusTcp();
/**
* @brief writeSingleHR float写入保持性寄存器
* @param address
* @param dataSend
* @param serverID id
*/
void writeSingleFloat(int address, float dataSend, int serverID);
/**
* @brief writeSingleWord wordint
* @param i
* @param w
*/
void writeSingleWord(int i, int w);
/**
* @brief writeMultipleHR HR
* @param address
* @param num
* @param dataSend
* @param serverID id
*/
void writeMultipleHR(int address, int num, float *dataSend, int serverID);
/**
* @brief readMultipleHR dataRCV数组中
* @param startAddress
* @param num
* @param serverID id
*/
void readMultipleHR(int startAddress, int num, int serverID);
// /**
// * @brief onTimeReadHR 定时读HR
// */
// void onTimeReadHR();
// /**
// * @brief stopOnTimeReadHR 停止定时获取数据
// */
// void stopOnTimeReadHR();
private:
/**
* @brief float2Word f转化为2个8位数据存放在word数组中
* @param f
* @param word word数组
*/
void float2Word(float f, unsigned int *word);
/**
* @brief word2Float 2word数据转化为浮点数
* @param p word数组的指针
* @param dataTransformed
*/
void word2Float(unsigned int *p, float dataTransformed);
/**
* @brief errorOccurred_Slot
*/
void errorOccurred_Slot();
/**
* @brief stateChanged_SLot
*/
void stateChanged_SLot();
/**
* @brief onReadReadyHR_Slot HR读取准备就绪
*/
void onReadReadyHR_Slot();
};
#endif // MYMODBUSTCP_H