Qt Quick QML Read Data over Serial Port and Show on GUI
-
So finally He agreed , He needs to set some values to make it to work.
" We need to go to Linux terminal and set the budrate every time off it to work. "
So this is his fault. And I kept trying with QTSerialPort several time and it had returned with CanReadWrite() as false.
I had provided the right soln and I know it is right. His serial port is not getting value with CanReadWrite() as true. He is now telling this.
In linux terminal port, He is setting some baud rate to make it to work.
I had verified , for corrections, 4 times on his port and made the normal way to work. Now for this , He is tellingthis is not his fault. CanReadWrite() as true only QT Serial Port will work.
If QTSerialPort is working fine, then CanReadWrite() will return value as true.
ie the proof. So why it is returned as false?. whether he again claims that His serial port baud rate or his on off of device, or no data had come?.we work by hrs. we are not infront of the machine and checking and doing it. When it returns false as value, I am sure it had not worked. He is now taking more time than needed.
As Expert always , I gives best soln. I had checked this and told him. Now I am really doubt to work with him again.
-
[quote author="valliammal" date="1418522987"]So finally He agreed , He needs to set some values to make it to work.
" We need to go to Linux terminal and set the budrate every time off it to work. "
So this is his fault. And I kept trying with QTSerialPort several time and it had returned with CanReadWrite() as false.
I had provided the right soln and I know it is right. His serial port is not getting value with CanReadWrite() as true. He is now telling this.
In linux terminal port, He is setting some baud rate to make it to work.
I had verified , for corrections, 4 times on his port and made the normal way to work. Now for this , He is tellingthis is not his fault. CanReadWrite() as true only QT Serial Port will work.
If QTSerialPort is working fine, then CanReadWrite() will return value as true.
ie the proof. So why it is returned as false?. whether he again claims that His serial port baud rate or his on off of device, or no data had come?.we work by hrs. we are not infront of the machine and checking and doing it. When it returns false as value, I am sure it had not worked. He is now taking more time than needed.
As Expert always , I gives best soln. I had checked this and told him. Now I am really doubt to work with him again.[/quote]
You're mixing things up.
The Qt terminal example uses the QtSerialPort library, and works fine on our machine. This means that it initialises the serial port correctly and hence reads it fine. Therefore there is nothing wrong with the actual serial port.
Your code needs this command to run on Linux terminal in order for it to work:
stty -F /dev/ttyUSB0 115200This makes things very manual!
If the code that you tried with QtSerialPort library returns false with CanReadWrite(), there must be something wrong with your code and not with the actual serial port. As explained above Qt terminal example works fine and it does makes used of the QtSerialPort library.
-
Hi guys, we have managed to use QtSerialPort libraries to achieve what we need.
Our serial read code runs in a separate thread in a forever to receive the data and update the GUI.
Here is the serial code. Would you kindly have a look and make sure it is good to go?
Our data that arrives looks like this:-
234|654\n@QString elem0;
QString elem1;forever {
if (serialPort.waitForReadyRead(1500)) //set the timeout time for the port { serialPort.flush(); /make sure there is no old data every time we want to read QByteArray data; QStringList myArrayOfNums; if (serialPort.canReadLine()) //If we can read the data then read it { data = serialPort.readLine(); //Read line of data as Byte Array QString myData(data); //Convert the received the data to String myArrayOfNums = myData.split("|"); //Split the data as it's delimited and put into a String List //USE THE FINAL DATA elem0 = myArrayOfNums[0].simplified(); //simplified removes any white spaces/characters elem1 = myArrayOfNums[1].simplified(); qDebug() << elem0; qDebug() << elem1; } }@
One thing we've noticed is that when waitForReadyRead() is set to for example waitForReadyRead(30), so only 30 millisecs, then waitForReadyRead() returns false quite alot. Does anyone know the reason for that?
Additionally if we monitor the data that arrives into the Qt application, every often canReadLine() also returns false. Is there a way to make sure it always returns true so receiving data can become smoother and loss of data eliminated?
-
Why not it in asynchronous mode and use readyRead() + readAll() ?
-
Actually most of the issues are sorted.
Still not using readyRead() though. However I have connected our microcontroller to our Raspberry Pi via the UART (Rx/Tx pins) with a level shifter.
The Qt app cannot read anything from the /dev/ttyAMA0. It all works fine if the microcontroller is connected to the Raspberry Pi via USB.
Is this normal?
-
Depends, do you have the rights to read/write from /dev/ttyAMA0 ?
-
I mean does your user have the rights to access that device ? What does ls -la /dev/ttyAMA0 return ?
-
port access example: https://github.com/ncp1402/ql-serial
application example: https://github.com/ncp1402/qcsvlog