mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 10:46:33 +00:00
Simple program to control Siyi A8 mini gimbal
Simple program to control Siyi A8 mini (actually some other Siyi cameras too). Receiving responce sometimes gives error when checking CRC.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include "serialPort.h"
|
||||
#include <QDebug>
|
||||
|
||||
SerialPort::SerialPort(const QString &portName) : mSerialPort(portName) {
|
||||
mSerialPort.setPortName(portName);
|
||||
mSerialPort.setBaudRate(QSerialPort::Baud115200);
|
||||
mSerialPort.setDataBits(QSerialPort::Data8);
|
||||
mSerialPort.setStopBits(QSerialPort::OneStop);
|
||||
mSerialPort.setFlowControl(QSerialPort::NoFlowControl);
|
||||
}
|
||||
|
||||
SerialPort::~SerialPort() {
|
||||
closePort(); // Close port if open on destruction
|
||||
}
|
||||
|
||||
bool SerialPort::openPort() {
|
||||
if (mSerialPort.isOpen()) {
|
||||
qDebug() << "Port already open";
|
||||
return true;
|
||||
}
|
||||
|
||||
return mSerialPort.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
void SerialPort::closePort() {
|
||||
if (mSerialPort.isOpen()) {
|
||||
mSerialPort.close();
|
||||
}
|
||||
}
|
||||
|
||||
void SerialPort::sendCommand(const QByteArray &command) {
|
||||
if (!mSerialPort.isOpen()) {
|
||||
qDebug() << "Error: Port not open";
|
||||
return;
|
||||
}
|
||||
|
||||
mSerialPort.write(command);
|
||||
}
|
||||
|
||||
QByteArray SerialPort::readResponse() {
|
||||
if (!mSerialPort.isOpen()) {
|
||||
qDebug() << "Error: Port not open";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
// Read data from serial port until timeout or specific criteria met
|
||||
QByteArray response;
|
||||
while (mSerialPort.waitForReadyRead(5000)) { // Adjust timeout as needed
|
||||
response.append(mSerialPort.readAll());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user