Change values on Qt according to a serial port string
I know that Qt has a great documentation, but it has been weeks that I'm reading everything on it and can't find a solution. I'll explain you my setup so you can figure it out.
I have a microcontroller called "STM32 Nucleo" which is used to read several inputs and to deducts from these inputs, other electrical quantities.
This STM32 is connected to a Bluetooth Module, which is used to send a string (and only this way, the other way (receiving data) is not wired. I've tested with HyperTerminal-like programs and it sends it really well.
In the other hand, I have a Raspberry Pi which will have a Qt program running. This Qt program is used to receive the electrical quantities as a string and display them on a GUI.
So here's my problem : I don't know how to read the data received on the serial port /dev/rfcomm0 of the raspberry with the Qt program, and then I need to parse the string and update the values of the GUI according to the data received.
If I make a step-by-step list of my problem :
- Read the /dev/rfcomm0 on my Qt program
Parse it to have my electrical quantities(I've already find it on the documentation)
- Update some Labels and Values of CircularGauge QML Type
So if anyone could give me a hint, i'll be glad and it will be a great step to finish my uni project.
Thanks a lot,
For part 1 have a look at the Serial Port Reader Example
It's very simple and you will be able to re-use the class SerialPortReader in your project.
I suggest that you first take the example as-is and see if you actually can receive data.
Than integrate SerialPortReader in your project and check again.
The last step is to change the QML elements from C++, but there are lots of examples also.
I've already read it, but I've difficulties to understand it.
And doesn't it seem too much for what I'd like to do in my program ? Because I'll always connect to the same serial port, with the same BaudRate, etc...
Although, in the example, I don't find where do I tell to the C++ to connect to /dev/rfcomm0 ? Did I miss something ?
Have you actually tried it? It does exactly what you demand in step 1.
And if you look in http://doc.qt.io/qt-5/qtserialport-creaderasync-main-cpp.html you will see that the serial port and the baud rate are given as command line parameters.
Just (cross-)compile the program for the Raspberry, and run it. It should work like your HypterTerminal test.