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