114 lines
1.6 KiB
C++
114 lines
1.6 KiB
C++
#include "vincecontrol.h"
|
|
#include"QSerialPortInfo"
|
|
VinceControl::VinceControl(ProTools proto)
|
|
{
|
|
protools = proto;
|
|
IsMotorInit = false;
|
|
RS485ID = "0";
|
|
}
|
|
|
|
VinceControl::~VinceControl()
|
|
{
|
|
serial->close();
|
|
IsMotorInit = false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
}
|
|
|
|
void VinceControl::MoveSetDistance(long distance)
|
|
{
|
|
|
|
}
|
|
|
|
void VinceControl::MoveMotar(bool direction)
|
|
{
|
|
|
|
}
|
|
|
|
void VinceControl::SettingSpeed(unsigned long Speed)
|
|
{
|
|
|
|
}
|
|
|
|
void VinceControl::MovetoZero()
|
|
{
|
|
|
|
}
|
|
|
|
long VinceControl::GetLocationNow()
|
|
{
|
|
return 10000;
|
|
}
|
|
|
|
void VinceControl::MoveToLocation(long Location)
|
|
{
|
|
|
|
}
|
|
|
|
void VinceControl::SettingUpandDownSpeed(int addspeed, int downspeed)
|
|
{
|
|
|
|
}
|