LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Plot serial data to chart

Solved!
Go to solution

I'm trying to make this labview program where it takes the serial data from a microcontroller and charts the values.

 

More specifically, the serial data contains values (continuously) from 0 to 1023 (10bits) where the LS is the lower 8 bits and the MS is the upper 2 bits.

I know the serial connection transmits 8 bits at a time, and my microcontroller program implements a loop to take the data in 8 bit increments.

For example, 1023 is 11111111 in binary. The serial port will take the upper 2 bits as 00000011 and then the lower 8 bits (11111111) where they appear combined together (as 16 bits) in the string of serial data in the correct order.

 

I have a vi to read the data from the serial port, place the string into an array (continuously appends), takes a 10 bit segment ( on next loop it takes the following 10bit segment), a sub vi that converts the 10bit segment to the corresponding decimal number and plots the decimal value (ex. 1023) to the chart.

 

The problem is that it reads the data too slow and writes to the chart to slowly.

How do I speed the process so that ideally the data is read and the 10bit number is taken and graphed (this cycle is continuous) without much delay?

 

Right now the microcontroller and labview have the baud rate set at 9600

 

Please look at my vi and help!

 

Download All
0 Kudos
Message 1 of 12
(8,735 Views)

Hi,

 

You close and open Serial communication in every iteration, no matter if you write or read. Each of these operations takes time.

 

Why don't you start the serial com. at the beginning and close it to the end. Only once.

 

In attachment I've prepared a draft of how it should be easier for you to do it.

 

Paul

0 Kudos
Message 2 of 12
(8,729 Views)
Solution
Accepted by topic author class_a07

Hi,

      This code will help u.

Serial.png

 

Siva

Sivaraj M.S
CLA
0 Kudos
Message 3 of 12
(8,727 Views)

Thanks Paulie and Siva.

I will try out your soloutions a little later and let you know my results

0 Kudos
Message 4 of 12
(8,711 Views)

A suggestion for a modification to Siva's code: Since the code does nothing after an error has occurred, wire a True to the Stop terminal from the Error case (OR it with the Stop button).  Then the VI will not sit there spinning its wheels waiting for the user to push Stop.  Displaying the error or suing one of the Error Handler VIs to pop up an error dialog would let the user know why it stopped.

 

Lynn

0 Kudos
Message 5 of 12
(8,707 Views)

Paul:

Could you by chance save the vi as a previous version?

Im running sp1 2009

0 Kudos
Message 6 of 12
(8,705 Views)

Here you go.

As I've just said, it's just a draft where you can see a better vi structure that you have in your vi.

 

Paul

0 Kudos
Message 7 of 12
(8,697 Views)

Paul's example is not quite there, because he is not reading the serial port in a loop, and you are not providing how much data to read (available) from the serial buffer.

 

Have a look at this code snippet.  Simply add the VISA Configure port in front of it..  It is a modified version of the Basic Serial Write Read.vi that is found in the Help menu (Find examples).  As a matter of fact, I should modify it further to be like what Paul prepared, using an Event Structure... All that he was missing was the number of bytes to read at the port and the loop to continue reading until the buffer is empty..

 

 

 

0 Kudos
Message 8 of 12
(8,687 Views)

After taking into account the suggestions, I was able to read from serial faster and graph to the chart faster. 

 

However, when I first start to run the program, it does not read or chart anything (like it's paused). I have to press run then stop and then press run and stop again (at least 2 or 3 times) before the program starts to read data a chart it. 

 

Does anyone know why its doing this? 

Other than that it's working a lot better. 

 

Thanks

0 Kudos
Message 9 of 12
(8,675 Views)

I was able to figure it out.

I made another while loop inside of the case structue and that corrected the problem

0 Kudos
Message 10 of 12
(8,669 Views)