取消了自动反馈机制 增加了手动反馈机制 修改了若干bug
This commit is contained in:
164
vincecontrol.cpp
164
vincecontrol.cpp
@ -2,13 +2,15 @@
|
|||||||
#include"QSerialPortInfo"
|
#include"QSerialPortInfo"
|
||||||
#include "QDebug"
|
#include "QDebug"
|
||||||
#include "QThread"
|
#include "QThread"
|
||||||
|
union MyUnion
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned char a[4];
|
||||||
|
};
|
||||||
VinceControl::VinceControl(ProTools proto)
|
VinceControl::VinceControl(ProTools proto)
|
||||||
{
|
{
|
||||||
protools = proto;
|
protools = proto;
|
||||||
IsMotorInit = false;
|
initme();
|
||||||
RS485ID = "0";
|
|
||||||
Speednow = 0;
|
|
||||||
SpeedisSet = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +62,25 @@ bool VinceControl::serialconnect(QString comname, QString bandrate)
|
|||||||
|
|
||||||
void VinceControl::Handshacke(QString motorid)
|
void VinceControl::Handshacke(QString motorid)
|
||||||
{
|
{
|
||||||
|
|
||||||
SendCommandtoMotor("dev\n", motorid);
|
SendCommandtoMotor("dev\n", motorid);
|
||||||
|
QByteArray buf;
|
||||||
|
|
||||||
|
GetCommonRetrun(buf);
|
||||||
|
if (unsigned char(buf[0])==0xff)
|
||||||
|
{
|
||||||
|
if (motorid == "non")
|
||||||
|
{
|
||||||
|
motorid = Motorlist[0];
|
||||||
|
}
|
||||||
|
buf.remove(0, 3);
|
||||||
|
buf.remove(buf.length() - 3, 4);
|
||||||
|
|
||||||
|
QString str=motorid+":";
|
||||||
|
str.append(buf);
|
||||||
|
SendLog(str);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VinceControl::SetRS485ID(QString id)
|
void VinceControl::SetRS485ID(QString id)
|
||||||
@ -80,6 +100,13 @@ void VinceControl::EnableMotro(QString id )
|
|||||||
{
|
{
|
||||||
SendCommandtoMotor(str, id);
|
SendCommandtoMotor(str, id);
|
||||||
}
|
}
|
||||||
|
QByteArray buf;
|
||||||
|
GetCommonRetrun(buf,id);
|
||||||
|
|
||||||
|
|
||||||
|
ByteBack Camback = TranslateBytedata(buf,id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +147,7 @@ void VinceControl::SendCommandtoMotor(QString str)
|
|||||||
{
|
{
|
||||||
tcpSocket[0]->write(str.toUtf8().data());
|
tcpSocket[0]->write(str.toUtf8().data());
|
||||||
}
|
}
|
||||||
tcpSocket[0]->waitForBytesWritten(1000);
|
//tcpSocket[0]->waitForBytesWritten(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +266,19 @@ void VinceControl::SettingSpeed(unsigned long Speed, QString motornetid /*= "non
|
|||||||
//speed
|
//speed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VinceControl::GetCommonRetrun(QByteArray &buf, QString id/*="non"*/)
|
||||||
|
{
|
||||||
|
if (id == "non")
|
||||||
|
{
|
||||||
|
if (protools==NETTCP)
|
||||||
|
{
|
||||||
|
buf.clear();
|
||||||
|
tcpSocket[0]->waitForReadyRead(10000);
|
||||||
|
buf = tcpSocket[0]->readAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VinceControl::SettingSpeedByThis( long Speed, QString motornetid)
|
void VinceControl::SettingSpeedByThis( long Speed, QString motornetid)
|
||||||
{
|
{
|
||||||
if (motornetid=="non")
|
if (motornetid=="non")
|
||||||
@ -252,6 +292,8 @@ void VinceControl::SettingSpeedByThis( long Speed, QString motornetid)
|
|||||||
{
|
{
|
||||||
Speednow = Speed;
|
Speednow = Speed;
|
||||||
SpeedisSet = true;
|
SpeedisSet = true;
|
||||||
|
|
||||||
|
// TranslateBytedata(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -266,12 +308,70 @@ void VinceControl::SettingSpeedByThis( long Speed, QString motornetid)
|
|||||||
|
|
||||||
isSettingSpeedlist[i] = true;
|
isSettingSpeedlist[i] = true;
|
||||||
Speedlist[i] = Speed;
|
Speedlist[i] = Speed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QString commentosend = "cfg spd=" + QString::number(Speed) + "\n";
|
QString commentosend = "cfg spd=" + QString::number(Speed) + "\n";
|
||||||
SendCommandtoMotor(commentosend, motornetid);
|
SendCommandtoMotor(commentosend, motornetid);
|
||||||
|
QByteArray buf;
|
||||||
|
GetCommonRetrun(buf, motornetid);
|
||||||
|
TranslateBytedata(buf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBack VinceControl::TranslateBytedata(QByteArray buf, QString motornetid)// = "non")
|
||||||
|
{
|
||||||
|
ByteBack backdatt;
|
||||||
|
backdatt.Speed = -1000000;
|
||||||
|
if (buf.length()!=21)
|
||||||
|
{
|
||||||
|
return backdatt;
|
||||||
|
}
|
||||||
|
if (unsigned char(buf[0]) == 0xff)
|
||||||
|
{
|
||||||
|
|
||||||
|
buf.remove(0, 3);
|
||||||
|
buf.remove(buf.length() - 3, 3);
|
||||||
|
int location;
|
||||||
|
unsigned char a[15];
|
||||||
|
memcpy(a, buf.data(), 15);
|
||||||
|
location = ((a[0] & 0x0f) << 28) | ((a[1] & 0x7f) << 21) | ((a[2] & 0x7f) << 14) | ((a[3] & 0x7f) << 7) | ((a[4] & 0x7f));
|
||||||
|
float speed;
|
||||||
|
|
||||||
|
memcpy(&speed, &location, 4);
|
||||||
|
backdatt.Speed = speed;
|
||||||
|
int loc;
|
||||||
|
loc = ((a[5] & 0x0f) << 28) | ((a[6] & 0x7f) << 21) | ((a[7] & 0x7f) << 14) | ((a[8] & 0x7f) << 7) | ((a[9] & 0x7f));
|
||||||
|
backdatt.Location = loc;
|
||||||
|
backdatt.Speed = speed;
|
||||||
|
location = ((a[10] & 0x0f) << 28) | ((a[11] & 0x7f) << 21) | ((a[12] & 0x7f) << 14) | ((a[13] & 0x7f) << 7) | ((a[14] & 0x7f));
|
||||||
|
backdatt.Stata = unsigned int(location);
|
||||||
|
|
||||||
|
if (motornetid == "non")
|
||||||
|
{
|
||||||
|
motornetid = Motorlist[0];
|
||||||
|
}
|
||||||
|
//memcpy(buf.data() + 6, &location, 4);
|
||||||
|
QString str1 = motornetid + ": Speed " + QString::number(backdatt.Speed, 'f', 2) + " location " + QString::number(backdatt.Location);
|
||||||
|
|
||||||
|
SendLog(str1);
|
||||||
|
|
||||||
|
return backdatt;
|
||||||
|
//memcpy(buf.data() + 6, &location, 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
return backdatt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VinceControl::initme()
|
||||||
|
{
|
||||||
|
|
||||||
|
IsMotorInit = false;
|
||||||
|
RS485ID = "0";
|
||||||
|
Speednow = 0;
|
||||||
|
SpeedisSet = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,11 +399,26 @@ void VinceControl::StopMotormove(QString motornetid )
|
|||||||
{
|
{
|
||||||
QString commonstr = "stp\n";
|
QString commonstr = "stp\n";
|
||||||
SendCommandtoMotor(commonstr, motornetid);
|
SendCommandtoMotor(commonstr, motornetid);
|
||||||
|
QByteArray buf;
|
||||||
|
GetCommonRetrun(buf,motornetid);
|
||||||
|
TranslateBytedata(buf,motornetid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteBack VinceControl::GetState(QString motorid /*= "non"*/)
|
||||||
|
{
|
||||||
|
QString commonstr = "cts\n";
|
||||||
|
SendCommandtoMotor(commonstr, motorid);
|
||||||
|
QByteArray buf;
|
||||||
|
GetCommonRetrun(buf,motorid);
|
||||||
|
ByteBack back = TranslateBytedata(buf, motorid);
|
||||||
|
return back;
|
||||||
|
}
|
||||||
|
|
||||||
VinceControl::VinceControl(ProTools proto, int port)
|
VinceControl::VinceControl(ProTools proto, int port)
|
||||||
{
|
{
|
||||||
|
//VinceControl(proto);
|
||||||
|
initme();
|
||||||
if (proto != NETTCP)
|
if (proto != NETTCP)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -329,6 +444,7 @@ void VinceControl::onNewTcpClinetConnet()
|
|||||||
QTcpSocket *tcpsocket1;
|
QTcpSocket *tcpsocket1;
|
||||||
|
|
||||||
tcpSocket.append(tcpServer->nextPendingConnection());
|
tcpSocket.append(tcpServer->nextPendingConnection());
|
||||||
|
// connect(tcpSocket[tcpSocket.length() - 1], &QTcpSocket::readyRead, this, &VinceControl::onReciveFromClinet);
|
||||||
|
|
||||||
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);
|
||||||
@ -337,22 +453,42 @@ void VinceControl::onNewTcpClinetConnet()
|
|||||||
int speed = 200;
|
int speed = 200;
|
||||||
Speedlist.append(speed);
|
Speedlist.append(speed);
|
||||||
qint32 port = tcpSocket[tcpSocket.length() - 1]->peerPort();
|
qint32 port = tcpSocket[tcpSocket.length() - 1]->peerPort();
|
||||||
QString str11 = ip + " Connected The Port Number is "+port+"\n";
|
QString str11 = ip + " Connected The Port Number is "+QString::number(port)+"\n";
|
||||||
SendLog(str11);
|
SendLog(str11);
|
||||||
|
Handshacke(Motorlist[Motorlist.length()-1]);
|
||||||
qDebug() << ip << ":" << port;
|
qDebug() << ip << ":" << port;
|
||||||
|
IsMotorInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VinceControl::onReciveFromClinet()
|
void VinceControl::onReciveFromClinet(QString motornetid)// = "non")
|
||||||
{
|
{
|
||||||
QTcpSocket* sc = dynamic_cast<QTcpSocket*>(sender());
|
//QTcpSocket* sc = dynamic_cast<QTcpSocket*>(sender());
|
||||||
QString ip = sc->peerAddress().toString().split("::ffff:")[1];
|
//QString ip = sc->peerAddress().toString().split("::ffff:")[1];
|
||||||
|
|
||||||
//<2F><>ȡ<EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
|
//<2F><>ȡ<EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if (motornetid=="non")
|
||||||
|
{
|
||||||
|
if (protools==NETTCP)
|
||||||
|
{
|
||||||
|
QByteArray buf;
|
||||||
|
tcpSocket[0]->waitForReadyRead(1000);
|
||||||
|
buf = tcpSocket[0]->readAll();
|
||||||
|
if (buf.length()==0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString str = Motorlist[0] + ":";
|
||||||
|
str.append(buf);
|
||||||
|
SendLog(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
#ifdef LOGOUT
|
#ifdef LOGOUT
|
||||||
QByteArray array = sc->readAll();
|
// QByteArray array = sc->readAll();
|
||||||
QString strofrecive;
|
// QString strofrecive;
|
||||||
strofrecive.append(array);
|
// strofrecive.append(array);
|
||||||
QString strtosend = "sender " + ip + ":" + strofrecive;
|
//QString strtosend = "sender " + ip + ":" + strofrecive;
|
||||||
SendLog(strtosend);
|
// SendLog(strtosend);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -57,6 +57,13 @@ enum ProTools
|
|||||||
RS232 = 0,
|
RS232 = 0,
|
||||||
RS485 = 1,
|
RS485 = 1,
|
||||||
NETTCP=2
|
NETTCP=2
|
||||||
|
};
|
||||||
|
struct ByteBack
|
||||||
|
{
|
||||||
|
float Speed;
|
||||||
|
int Location;
|
||||||
|
unsigned int Stata;
|
||||||
|
|
||||||
};
|
};
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
* 描述:马达控制程序
|
* 描述:马达控制程序
|
||||||
@ -224,19 +231,19 @@ public:
|
|||||||
void SettingUpandDownSpeed(int addspeed, int downspeed);
|
void SettingUpandDownSpeed(int addspeed, int downspeed);
|
||||||
|
|
||||||
void StopMotormove(QString motornetid = "non");
|
void StopMotormove(QString motornetid = "non");
|
||||||
|
ByteBack GetState(QString motorid = "non");
|
||||||
|
|
||||||
QStringList Motorlist;
|
QStringList Motorlist;
|
||||||
|
bool IsMotorInit;
|
||||||
signals:
|
signals:
|
||||||
void SendLogToCallClass(QString str);
|
void SendLogToCallClass(QString str);
|
||||||
public slots :
|
public slots :
|
||||||
void onNewTcpClinetConnet();
|
void onNewTcpClinetConnet();
|
||||||
void onReciveFromClinet();
|
|
||||||
void onClinetDisConnet();
|
void onClinetDisConnet();
|
||||||
private:
|
private:
|
||||||
QSerialPort *serial;
|
QSerialPort *serial;
|
||||||
|
void onReciveFromClinet(QString motornetid = "non");
|
||||||
|
|
||||||
bool IsMotorInit;
|
|
||||||
ProTools protools;
|
ProTools protools;
|
||||||
QString RS485ID;
|
QString RS485ID;
|
||||||
unsigned long speed;
|
unsigned long speed;
|
||||||
@ -247,8 +254,11 @@ private:
|
|||||||
QList<int> Speedlist;
|
QList<int> Speedlist;
|
||||||
bool SpeedisSet;
|
bool SpeedisSet;
|
||||||
int Speednow;
|
int Speednow;
|
||||||
|
void GetCommonRetrun(QByteArray &buf,QString id="non");
|
||||||
//
|
//
|
||||||
void SettingSpeedByThis(long Speed, QString motornetid = "non");
|
void SettingSpeedByThis(long Speed, QString motornetid = "non");
|
||||||
|
ByteBack TranslateBytedata(QByteArray buf, QString motornetid = "non");
|
||||||
|
void initme();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
<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$(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$(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$(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$(PATH)</LocalDebuggerEnvironment>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user