#include "thread.h" #include "capture.h" #include "queue" #include "QDataStream" #include "iostream" using namespace std; #define ResultPath "C:/Users/14542/Desktop/Log.txt" extern QFile file0; extern QFile file1; extern QFile file2; extern QFile file3; extern modbus_t* pressure_LowMachine; extern modbus_t* temprature_Lowmachine; QMutex stop_mutex; modbus_t* pl; plc_fds fd = { // .d1 = NULL, // .d2 = NULL, }; extern uint8_t start_flag; QMutex pressure_mutex; QMutex torque_mutex; QMutex temprature_mutex; QMutex moto_mutex; extern modbus_t* LowMachine; extern Capture* cap; extern U32 *g_pAIBuf; //capture.cpp的全局变量 extern std::queue dataQueue0; void AI_EndCallBack() { /* * 根据所选的连续AI函数,循环缓冲区的一半数据将保存到用户缓冲区 * (如果连续AI函数为:UD_AI_ContReadChannel和UD_AI_ContReadMultiChannels) * 或登录到磁盘文件(如果连续AI函数为:UD_AI_ContReadChannelToFile和UD_AI_ContReadMultiChannelsToFile)。 * 您可以重复执行此函数以返回数据的连续半缓冲区。 * */ I16 err = UD_AI_AsyncDblBufferTransfer32(cap->card, g_pAIBuf); cap->display_buffer_data(g_pAIBuf); } SerialThread::SerialThread(QObject *parent) : QThread(parent) { } void SerialThread::run() { serial = new QSerialPort(); //连接信号槽 connect(serial, &QSerialPort::readyRead, this, &SerialThread::ReadData); } void SerialThread::ReadData() { } //温度,压力,扭矩仪通过modbus读取 ModbusThread::ModbusThread(QObject *parent) : QThread(parent) { } void ModbusThread::run() { //传输数据 while (1) { uint16_t pressI1; uint16_t pressI2; uint16_t pressDouble; uint16_t temp; if(start_flag) { //压力 pressure_mutex.lock(); int ret = modbus_read_registers(pressure_LowMachine, 0x0000, 1, &pressI1); qDebug()<(static_cast(pressI1)<<16) | pressI2; emit pressureValue(pressInt,pressDouble); pressure_mutex.unlock(); } } } //modbus控制电机 ModbusMotorThread::ModbusMotorThread(QObject *parent):QThread(parent),isStop(false) { } ModbusMotorThread::~ModbusMotorThread() { } void ModbusMotorThread::exitThread() { stop_mutex.lock(); isStop=true; stop_mutex.unlock(); } void ModbusMotorThread::run() { if(start_flag) { moto_mutex.lock(); int ret = modbus_write_register(fd.d2,0x0603,enterSpeed); qDebug()<<"写0603: "<扭矩小数部分ret: "<(static_cast(tq1)<<16) | tq2; qDebug()<<"tq2: "<(static_cast(sp1)<<16) | sp2; qDebug()<<"------>扭矩仪转速spInt: "<(static_cast(pw1)<<16) | pw2; qDebug()<<"------>>>>>>>扭矩仪功率pwInt: "<