Files
vince/vincecontrol.cpp

114 lines
1.6 KiB
C++
Raw Normal View History

2020-08-05 17:04:25 +08:00
#include "vincecontrol.h"
#include"QSerialPortInfo"
VinceControl::VinceControl(ProTools proto)
{
protools = proto;
IsMotorInit = false;
RS485ID = "0";
}
2020-08-05 17:04:25 +08:00
VinceControl::~VinceControl()
2020-08-05 17:04:25 +08:00
{
serial->close();
IsMotorInit = false;
}
2020-08-05 17:04:25 +08:00
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;
2020-08-05 17:04:25 +08:00
}
void VinceControl::SetRS485ID(QString id)
{
RS485ID = id;
}
void VinceControl::EnableMotro()
2020-08-05 17:04:25 +08:00
{
QString str = "ena\n";
SendCommandtoSerial(str);
2020-08-05 17:04:25 +08:00
}
2020-08-05 17:33:45 +08:00
void VinceControl::DisableMotro()
{
QString str = "off\n";
SendCommandtoSerial(str);
}
void VinceControl::SendCommandtoSerial(QString str)
2020-08-05 17:33:45 +08:00
{
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);
2020-08-05 17:33:45 +08:00
}
2020-08-05 17:33:45 +08:00
}
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)
{
}