加入通讯协议 初始化 命令发送 使能 停止使能

This commit is contained in:
xin
2020-08-05 18:15:32 +08:00
parent 93cd9f1af2
commit 657493ba8e
2 changed files with 173 additions and 9 deletions

View File

@ -1,16 +1,77 @@
#include "vincecontrol.h"
VinceControl::VinceControl()
#include"QSerialPortInfo"
VinceControl::VinceControl(ProTools proto)
{
protools = proto;
IsMotorInit = false;
RS485ID = "0";
}
VinceControl::~VinceControl()
{
serial->close();
IsMotorInit = false;
}
void VinceControl::connect(QString comname, QString bandrate)
bool VinceControl::serialconnect(QString comname, QString bandrate)
{
QSerialPortInfo info;
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
int i = 0;
foreach(info, infos) {
if (info.portName() == comname) break;
i++;
}
if (i != infos.size())
{
serial->close();
serial->setPort(info);
bool aa = serial->open(QIODevice::ReadWrite);
qint32 b = bandrate.toInt();
serial->setBaudRate(b);
IsMotorInit = true;
}
else
{
serial->close();
IsMotorInit = false;
}
}
void VinceControl::SetRS485ID(QString id)
{
RS485ID = id;
}
void VinceControl::EnableMotro()
{
QString str = "ena\n";
SendCommandtoSerial(str);
}
void VinceControl::DisableMotro()
{
QString str = "off\n";
SendCommandtoSerial(str);
}
void VinceControl::SendCommandtoSerial(QString str)
{
if (protools == RS232)
{
QByteArray buf;
buf.append(str);
serial->write(buf);
}
else if(protools==RS485)
{
QString str2 = RS485ID + " " + str;
QByteArray buf;
buf.append(str2);
serial->write(buf);
}
}