46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#pragma once
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include <QDebug>
|
|
#include <QTcpServer>
|
|
#include <QTcpSocket>
|
|
|
|
#include "CommunicationInterfaceBase.h"
|
|
|
|
namespace MotorParams {
|
|
|
|
class CommunicationViaTCP :
|
|
public CommunicationInterfaceBase
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
CommunicationViaTCP(TCPConnectionParams connectionParams, QObject* parent = nullptr);
|
|
~CommunicationViaTCP();
|
|
|
|
//继承基类
|
|
bool connect2Motor();
|
|
//void disconnect();
|
|
//bool isConnected() const;
|
|
|
|
int sendCommand(const QString cmd);
|
|
//void sendCommandAsync(const QString& command);
|
|
int recvData(QByteArray& dataRecv);
|
|
|
|
private:
|
|
QTcpServer* m_tcpServer;
|
|
QTcpSocket* m_tcpSocket;
|
|
int m_iCommunicationProtocol;
|
|
|
|
bool m_bConnected;
|
|
bool isConnected() const;
|
|
|
|
public Q_SLOTS:
|
|
void onNewConnection();
|
|
void onTcpSocketDisconnected();
|
|
|
|
signals:
|
|
void commandSendResult(int bytesWritten, const QString& error = QString());
|
|
};
|
|
}
|