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:
Nffj84
2024-05-26 12:56:51 +03:00
parent a8ba701138
commit 33399370f3
12 changed files with 558 additions and 0 deletions
+53
View File
@@ -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;
}