#include "CleanMachineExportManage.h" CleanMachineExportManage::CleanMachineExportManage() { } CleanMachineExportManage::~CleanMachineExportManage() { } void CleanMachineExportManage::InitCleanMachine(QString ip, int port) { m_ip = ip; m_port = port; //TODO:是否需要后续初始化过程 } bool CleanMachineExportManage::ExecuteCommand(CommandType commandType) { QTcpSocket socket; socket.connectToHost(m_ip, m_port); //3S连接不上,即可返回 if (!socket.waitForConnected(3000)) { return false; } QString commandStr; if (COMMON_START_CLEAN == commandType) { commandStr = "ClearDevice;StartProcess;End"; } socket.write(commandStr.toStdString().c_str()); socket.waitForBytesWritten(); // 等待数据发送完成 bool isOk = socket.waitForReadyRead(10000); // 等待数据可读,等待10S,就返回 if (isOk) { QString recvStr = QString::fromUtf8(socket.readAll()); bool commandExcecuteFlag = false; if (COMMON_START_CLEAN == commandType && recvStr.indexOf("ClearDevice;StartProcess:Finish;End") >= 0) { commandExcecuteFlag = true; } socket.disconnectFromHost(); return commandExcecuteFlag; } socket.disconnectFromHost(); return false; }