加入通讯协议 初始化 命令发送 使能 停止使能
This commit is contained in:
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user