添加了析构函数
This commit is contained in:
@ -28,6 +28,12 @@ VinceControl::~VinceControl()
|
||||
serial->close();
|
||||
IsMotorInit = false;
|
||||
}
|
||||
if (protools==NETTCP)
|
||||
{
|
||||
tcpServer->close();
|
||||
delete tcpServer;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -189,7 +195,7 @@ void VinceControl::SendCommandtoMotor(QString str, QString modor)
|
||||
str = "0 " + str;
|
||||
}
|
||||
tcpSocket[i]->write(str.toUtf8().data());
|
||||
tcpSocket[i]->waitForBytesWritten(1000);
|
||||
tcpSocket[i]->waitForBytesWritten(50);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -272,7 +278,7 @@ void VinceControl::MoveMotar(bool direction, QString motornetid )
|
||||
}
|
||||
}
|
||||
|
||||
QThread::msleep(100);
|
||||
//QThread::msleep(100);
|
||||
QString commendtosend = "mov\n";
|
||||
SendCommandtoMotor(commendtosend, motornetid);
|
||||
|
||||
@ -290,9 +296,26 @@ void VinceControl::GetCommonRetrun(QByteArray &buf, QString id/*="non"*/)
|
||||
{
|
||||
if (protools==NETTCP)
|
||||
{
|
||||
if (!IsMotorInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
buf.clear();
|
||||
tcpSocket[0]->waitForReadyRead(10000);
|
||||
buf = tcpSocket[0]->readAll();
|
||||
if (tcpSocket.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tcpSocket[0]->waitForReadyRead(4000);
|
||||
if (tcpSocket.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (tcpSocket[0]->bytesAvailable())
|
||||
{
|
||||
buf = tcpSocket[0]->readAll();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -397,10 +420,15 @@ void VinceControl::initme()
|
||||
void VinceControl::initMotor(QString motornetid /*= "non"*/)
|
||||
{
|
||||
QByteArray buf;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>s1<73>½<EFBFBD>ʱֹͣ<CDA3><D6B9>ת
|
||||
QString commonstr = "cfg s1f=2\n";
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
//<2F><><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>
|
||||
commonstr = "cfg mcs=7\n";
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
|
||||
commonstr = "cfg zmd=1\n";//<2F><><EFBFBD>㳢<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
@ -436,12 +464,15 @@ void VinceControl::initMotor(QString motornetid /*= "non"*/)
|
||||
commonstr = "cfg psv=0\n";
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
commonstr = "cfg acc=10000\n";
|
||||
//<2F><><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD><EFBFBD>Ϊ10000
|
||||
commonstr = "cfg acc=20000\n";
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
commonstr = "cfg dec=10000\n";
|
||||
//<2F><><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD><EFBFBD>Ϊ10000
|
||||
commonstr = "cfg dec=20000\n";
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ4
|
||||
commonstr = "cfg crn=4\n";
|
||||
SendCommandtoMotor(commonstr, motornetid);
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
@ -450,6 +481,7 @@ void VinceControl::initMotor(QString motornetid /*= "non"*/)
|
||||
GetCommonRetrun(buf, motornetid);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void VinceControl::MovetoZero(QString motornetid )
|
||||
@ -504,11 +536,28 @@ void VinceControl::StopMotormove(QString motornetid )
|
||||
|
||||
ByteBack VinceControl::GetState(QString motorid /*= "non"*/)
|
||||
{
|
||||
ByteBack back;
|
||||
if (!IsMotorInit)
|
||||
{
|
||||
back.Speed = -1000000;
|
||||
}
|
||||
QString commonstr = "cts\n";
|
||||
SendCommandtoMotor(commonstr, motorid);
|
||||
QByteArray buf;
|
||||
GetCommonRetrun(buf,motorid);
|
||||
ByteBack back = TranslateBytedata(buf, motorid);
|
||||
|
||||
if (buf.size()==0)
|
||||
{
|
||||
back.Speed = -1000000;
|
||||
IsMotorInit = false;
|
||||
emit SendLogToCallClass("motor " + QString::number(tcpServer->serverPort())+ " may be disconnect!!!");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
back = TranslateBytedata(buf, motorid);
|
||||
}
|
||||
|
||||
return back;
|
||||
}
|
||||
|
||||
@ -541,6 +590,7 @@ VinceControl::VinceControl(ProTools proto, int port)
|
||||
connect(tcpServer, &QTcpServer::newConnection, this, &VinceControl::onNewTcpClinetConnet);
|
||||
|
||||
|
||||
|
||||
}
|
||||
void VinceControl::onNewTcpClinetConnet()
|
||||
{
|
||||
@ -552,7 +602,8 @@ void VinceControl::onNewTcpClinetConnet()
|
||||
|
||||
tcpSocket.append(tcpServer->nextPendingConnection());
|
||||
// connect(tcpSocket[tcpSocket.length() - 1], &QTcpSocket::readyRead, this, &VinceControl::onReciveFromClinet);
|
||||
|
||||
connect(tcpSocket[tcpSocket.length() - 1], &QTcpSocket::disconnected, this, &VinceControl::onClinetDisConnet);
|
||||
//connect(tcpSocket[tcpSocket.length() - 1], SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(onClinetDisConnet()));
|
||||
QString ip = tcpSocket[tcpSocket.length() - 1]->peerAddress().toString().split("::ffff:")[1];
|
||||
Motorlist.append(ip);
|
||||
bool statofmotor = false;
|
||||
@ -610,19 +661,24 @@ void VinceControl::onClinetDisConnet()
|
||||
int lenth = Motorlist.length();
|
||||
for (size_t i = 0; i < lenth; i++)
|
||||
{
|
||||
emit SendLogToCallClass(ip + "is disconnect");
|
||||
if (Motorlist[i]==ip)
|
||||
{
|
||||
Motorlist.removeAt(i);
|
||||
isSettingSpeedlist.removeAt(i);
|
||||
Speedlist.removeAt(i);
|
||||
delete tcpSocket[i];
|
||||
//delete tcpSocket[i];
|
||||
tcpSocket.removeAt(i);
|
||||
IsMotorInit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}//<2F>ഫ<EFBFBD><E0B4AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>
|
||||
IsMotorInit = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VinceControl::SendLog(QString str)
|
||||
{
|
||||
#ifdef LOGOUT
|
||||
|
@ -5,11 +5,11 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<QTDIR>C:\Qt\Qt5.8.0\5.8\msvc2013_64</QTDIR>
|
||||
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
|
||||
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<QTDIR>C:\Qt\Qt5.8.0\5.8\msvc2013_64</QTDIR>
|
||||
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
|
||||
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LocalDebuggerEnvironment>PATH="$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
|
||||
|
Reference in New Issue
Block a user