PDA

View Full Version : Qt with qwt, qextserialport unable to plot from serial port.



maharnab91
8th August 2013, 22:53
Hi,
I am using Qt 4.8.1 in Ubuntu 12.04 with Qwt libraries installed. I also have the qextserialport libraries installed. I have modified the uartassistant example from code.google.com/p/qextserialport/‎ according to my needs. I am able to display (in a plainTextEdit) my embedded device SBC6845 terminal (I can access everything of it) inside the uartassistant through /dev/ttyS0 port from my host PC.
Now I had added a qwtPlot item to a tab widget in uartassisstant, with which I can plot data from .txt files placed in my host PC. But I need to access or use the same data coming to the plainTextEdit and use them in qwtPlot. So far, I have a few ideas:
1. Read from the /dev/ttyS0 directly and plot them in qwtPlot. Now the problem is actually implementing it, I have run out of options. How do I do it?
(One of the problems holding me is that ttyS0 has many other unnecessary data along with my required data. Is there some exclusive way of selecting only int data and plotting on qwtPlot? I have tried implementing other links i came by googling but most of them are too erroneous to proceed further.
2. Save whatever comes through /dev/ttyS0 in a txt file and then read my required data from it. But this isn't the realtime, so I am not so keen on proceeding with this approach.

So in short :
Is there any way to implement qwt and qextserialport in some way to get the desired output in real time?
I just need a push in the right direction, so I welcome any advice, links to more tutorials, docs or few lines of code explaining, if I am missing some point.

Thanks.

IThu8uu1
13th August 2013, 17:07
There is no out-of-the-box way of plotting your data, since qwt does not know what to plot from your data stream and what not (i.e. what is your "required data" and what is not).

The data coming from your serial port has to have some sort of protocol, so you can distinguish between different data items. Specifically, you have to discern your "required data". You have to write some sort of software stack or filter which understands this protocol and is able to extract the data you want. The software stack is fed from one side with data coming form your serial port and the output of the serial port is fed into your plot. For the last part, have a look at the qwt realtime example. The oscilloscope and cpuplot examples may also be of interest to you.

I can't give you a more specific answer without more details about the data you are processing.

Best regards.

maharnab91
13th August 2013, 17:26
I am reading encoder counts of an actuator with the help of my SBC6845. The data generated is actual counts float-numbers (I made it so to make reading from file with qwtPlot easier) which are displayed on the terminal screen of my application(it uses the ttyS0 port for communicating between PC and SBC). Now since I am able to display the data as is, on my host PC, application terminal screen, I was thinking of a way to route those data straight to the qwtPlot. As of now, I am writing the data on to a file in the SBC6845, and copying the file from SBC6845 to host PC using tftp(Ethernet LAN between PC and SBC). This copied file in my host PC is being read by the qwtPlot and displayed as a graph on my application.
I know there are easier and quicker way to do this. But as you said there is need for some sort of protocol to identify the data. I actually tried saving in a file(in host PC) whatever comes from SBC to PC via ttyS0, but this was a disaster as it was only hex code which the 'port' of qextserialport reads and converts before displaying on my application screen. So it was a no go for me, I tried understanding the logic used in 'port' of qextserialport for conversion, but still unable to figure out completely.
If can elaborate on the 'software stack or filter' part with some examples it will be of great help.
Thanks.

Uwe
14th August 2013, 14:26
Only to mention it once: Qt 5.1 came with a new module https://qt-project.org/doc/qt-5.1/qtserialport/qtserialport-index.html

Uwe

IThu8uu1
14th August 2013, 18:15
If can elaborate on the 'software stack or filter' part with some examples it will be of great help.

As I understand your description your data is put out as ASCII, yes?
Then you need to read from your serial port, sscanf(), use fstream (http://stackoverflow.com/questions/14760637/read-large-amount-of-ascii-numbers-and-write-in-binary-form) or so, or write your own parser to translate the ASCII back to the IEEE 754 representation of that floating point number. Then you can put you floating point number into your curve data.

In case I have misunderstood you: You have to extract your floats from your data stream, possibly re-arrange the byte order and put them into your curve data.

Best regards.