LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 and Graph

Solved!
Go to solution

Hello ! 

I am new here and I would like to ask a question about Labview. 

Can you help me ?

 

Actually, I am working on a project with a PIC.

The PIC sent 3 informations (that evolves in time) to Laview (in my case, it is current, tension and time)

To send these informations, I use RS-232.

Moreover, I have used examples from Labview called 'Basic Serial Write and Read'.

It is great ! It works and Labview can display my values thus : 'current;tension;time\n'

 

I would like to display these datas on 3 graphs.

I think my first step should be : De-multiplexing or try to convert my data (string made by RS232) into float.

What do you think ? How can I do that ?

 

Thanks for your help and advices.

0 Kudos
Message 1 of 21
(4,633 Views)

For parsing a single line, I would use the Scan From String.  If parsing many lines, use the Spreadsheet String To Array.  Using either of those will get your your values.  You then just need to wire those into a chart.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 21
(4,623 Views)

It looks like your strings are separated by semicolons (;). It is very straightforward to convert a string of this type to an array of nunbers. The Spreadsheet String to Array function on the String palette can do it in one step. The default delimiter (tab) needs to be replaced by semicolon. You should also change the default datatype to a 1D array of DBL. A format string of '%f' will work well.  The constant string would be replaced by your data string from the Serial Read VI.

 

Convert data.png

 

This will generate an array with three elements, one each for current, tension, and time. To create your graphs you need to accumulate the points from multiple readings into separate arrays for each parameter.  One way is to use a shift register and Build Array. This can have problems when the arrays get large but is a simple way to get started. You can also use charts rather than graphs. Then you would just wire the scalar values from each iteration to the graph terminals. Charts have internal buffers similar to the shift register.

 

Read the Help for the functions and graphs and charts for more information.

 

Lynn

0 Kudos
Message 3 of 21
(4,614 Views)

Thanks for your replies ! I appreciated a lot.

I will try as soon as I can I will held you informed if I had difficulties.

Thanks

0 Kudos
Message 4 of 21
(4,576 Views)

Hi Mike,

 

Can you tag this topic as resolved please ?

 

Best Regards,

 

0 Kudos
Message 5 of 21
(4,543 Views)

Hi IsabelleG,

 

Actually, there is something very strange with my arrays. 

I would like to fix that first if it is possible

When it is finished, I won't forget to tag the topic.

 

I had followed your advices, Crossrulz and Lynn by using the Spreadsheet String to Array function.

It works perfectly but after a while, it stops and restarts. I don't understant what's going on.

I have recorded gif in order to explain well my problem.

 

Let's me explained how I proceeded.

 

Firstly, I had used the Spreadsheet String to Array function.

It has generated an array with three elements : current, tension, and velocity (I change 'time' by 'velocity').

Here, velocity must always equal to 0.

It works perfectly, thanks !

 

Then, I had split the array in three arrays (I used the block 'Array subset').

It works well (I divided by 10. Don't pay attention to that)

 

In the end, I wire a chart and I can see how it evolves each elements. I didn't use 'shift register'.

Here is the problem : after a while, 'current' and 'tension' values disappear and there is the 'tension value' in 'velocity'.

I am getting confused

Have you got any ideas ?

 

I join you :

- the vi

- a gif where the problem is occuring

- a screenshot where the problem is.

 

Thanks for your help

Download All
0 Kudos
Message 6 of 21
(4,518 Views)

Bytes at Port is "biting" you. When the remote device sends a termination character, do not use Bytes at Port. Set the byte count to a value larger than the maximum number of characters (including the termination character) which will ever occur in a message. You are receiving 3 values, and each may have 4-15 characters, depending on the data format. You also have the semicolons and the line feed. Set byte count to 100.

 

Why are you using arrays? It appears that you get one value each for velocity, current, and tension on each read from the serial port. Use Index Array rather than Array Subset and get scalars. Index Array can be expanded vertically to return all three values from a single instance of the funciton. The constant array connected to the divisor input for velocity has 9 elements which are zero. Does dividing by zero produce the scaling you want?

 

The Read (and perhaps the Write) should be inside a loop. Do not use Run Continuously to operate this VI . That results in the port being configured and closed repeatedly. This could also contribute to your loss of data.

 

Lynn

 

Serial fixes.png

0 Kudos
Message 7 of 21
(4,509 Views)
Personally, I would use the Scan From String as mentioned by crossrulz. One function instead of two.
0 Kudos
Message 8 of 21
(4,483 Views)

Hello !

 

Thanks for your replies !

 

I have followed your advices Lynn and the problem seems to have disappeared. Great !
Actually, I would like to ask just two questions about this topic and it will end my problems (sorry, I asked a lot of questions 🙂 )

 

1) What about sampling and chart ? 
Thanks to my PIC, I can measure current,velocity and tension. And I send datas every 200 ms. 
Do the charts display my values every 200 ms ?

 

2) When I start "Writing", my charts don't start at 0 second. Why ? It looks like there is already something.
I recorded another gif in order to show you what's happened.

 

 

About what you did the last time, your method with Index Array is clearer and smarter. I will remember that.


[QUOTE]The constant array connected to the divisor input for velocity has 9 elements which are zero. Does dividing by zero produce the scaling you want?[/QUOTE]

 

About the scaling, I would like to divide each element (velocity, current and tension) by 10. So, I just used the divisor as you did.
I don't use the part 'Original velocity divisor'.

 

[QUOTE]The Read (and perhaps the Write) should be inside a loop. Do not use Run Continuously to operate this VI . That results in the port being configured and closed repeatedly. This could also contribute to your loss of data.[/QUOTE]

 

Alright, I added a While Loop instead of the old structure and I have deleted the last part in order to Run Continously

 

[QUOTE]Personally, I would use the Scan From String as mentioned by crossrulz. One function instead of two.[/quote]
Thanks for this advice. I am going to keep that in mind 😉

 

 

 

Thanks for your help.

Download All
0 Kudos
Message 9 of 21
(4,453 Views)
Solution
Accepted by Mike.Ad

Your graphs are actually charts.  Charts keep a history.  You can use a property node to clear out the history.

 

Why are you still using the Run Continuously?  Stop that.  You should just use the Run.  And don't use the Abort.

 

Close your port when you are done.

 

Do you even need that loop for writing?  It doesn't make sense that you would request something without looking for the response.

 

You have things on your front panel way too spread out.  Try to reduce what you have and fit it all into a single screen.

 

Here's what a cleaned up version of your block diagram should somewhat resemble:


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 21
(4,444 Views)