I'm new in the raspbian bios and programming language, I have problem with receiving data from the raspberry pi 4 uart (ttyS0). I have ADC converter of course, which returns me hexadecimal string with data. The Przemytnik class is for connecting c++ language with qml, I would like to add a few classes in the future that's why I'm using the other class to reconvert data to qml. Sorry for my bad English, I'm still learning

SerialReader.h:
Код: Выделить всё
#ifndef SERIALREADER_H
#define SERIALREADER_H
#include
#include
class SerialReader : public QObject
{
Q_OBJECT
Q_PROPERTY(QString data READ data NOTIFY dataChanged)
public:
explicit SerialReader(QObject *parent = nullptr);
QString data() const;
Q_INVOKABLE void readData();
void writeData(const QString &data);
signals:
void dataChanged();
private:
QSerialPort m_serialPort;
QString m_data;
};
#endif // SERIALREADER_H
Код: Выделить всё
#include
#include
SerialReader::SerialReader(QObject *parent) : QObject(parent) {
m_serialPort.setPortName("/dev/ttyS0");
m_serialPort.setBaudRate(QSerialPort::Baud115200);
m_serialPort.setDataBits(QSerialPort::Data8);
m_serialPort.setParity(QSerialPort::NoParity);
m_serialPort.setStopBits(QSerialPort::OneStop);
m_serialPort.setFlowControl(QSerialPort::NoFlowControl);
if (!m_serialPort.open(QIODevice::ReadOnly)) {
std::cerr readData();
}
SerialReader* Przemytnik::serialReader() const { return m_serialReader; }
void Przemytnik::setSerialReader(SerialReader* serialReader) {
if (serialReader != m_serialReader) {
m_serialReader = serialReader;
emit serialReaderChanged();
}
}
Код: Выделить всё
qmlRegisteredType
And my simple main.qml code:
Код: Выделить всё
import QtQuick 2.9
import QtQuick.Window 2.3
import port 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Item{
Przemytnik{
id: przemytnik
}
Text {
text: przemytnik.serialReader.data
}
}
}
Источник: https://stackoverflow.com/questions/781 ... berry-pi-4