From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Real time Building of array and plotting data

Solved!
Go to solution

 Hello

 

I have a project in which I'm waiting for a string message coming to my Serial port containing two parameters from a sensor ,Tension versus position

I shall then plot  the two parameters to an XY graph as they are arriving to my port in order to build a graph which is continously updated with all the points came to the COM port (all tension readings versus the position of the reading).

 

I know that in order to plot the two parameters against each other I have to use the XY-Graph and for that ,I have to insert my data into arrays first and then give them to the graph.

 

The problem is that the serial message does not come at fixed interval (for example one message comes now ,the other may be after 1 minute ,and then another after half a minute ...and so on). and the graph has to be updated with the new points once they arrive (in addition to display the previous points too ofcourse).

 

I don't know where to start !! can someone put me on a track for that ?!

 

Note: I don't have any problems with the interpretation of the serial data ,at the end I shall have two numerical values which I shall then plot against each other

 

Thanks

 

 

0 Kudos
Message 1 of 12
(5,432 Views)

Shift register.

Build Array.

 

If you need more help, you are going to have to post some code wherever you are at.  You say you don't know where to start, but we can't assume that you know nothing and don't have some inkling of where to start.

0 Kudos
Message 2 of 12
(5,423 Views)

Thanks for your reply

 

shift registers with build array require a while loop and my data is not continously coming ,I need the program to insert the record into the array only when it comes at the serial port.

 

so which structure I'm going to use ??

0 Kudos
Message 3 of 12
(5,414 Views)

You've got to have a while loop somewhere!  Otherwise you'd have only one piece of data and no need to build it into an array.

0 Kudos
Message 4 of 12
(5,407 Views)

Just use a case structure to only add data to the array when new data is available.

0 Kudos
Message 5 of 12
(5,403 Views)

Hello

 

I came up with that last night ,I think it gets the work done in terms of inserting the data when its available.

 

I will have a fixed range for the Y axis of the graph (ex: from 0 to 300) all time ,but in terms of X axis ,I need that at the beginning of the vi execution the X-axis takes the first entry of the array as the minimum ,and apply a maximum of 100 points more than the minium ,for example if the first position entry is 1800 i need the scale be from 1800 to 1900 and then starts drawing as the data comes. and always displays the last 100 points of data only (i.e when the position reaches 1900 ,the scale shall be from 1801 to 1901 and then from 1802 to 1902...and so on) to display the last 100 positions only.

 

how can I get that done ?

 

Thanks

Download All
0 Kudos
Message 6 of 12
(5,385 Views)

That VI looks like a workable solution.  I just have a couple suggestions.

 

.  You need a way to stop it.  Right now all of your loops are inifinite and the only way to stop the program is to hit the abort button.

2.  Your graphing loop runs at light speed of the CPU.  You should put a wait in there also.  Actually, I think you could easily move that into either one of your other loops.

 

 

It sounds like your x and y data are coming in at different times.  Do you have at least a 1:1 correlation between the X and Y?  Could they wind up coming in at different rates and you'd wind up with multiple Y's for a single X, or vice versa.  (If so, you'll have big data problems where the data points no longer line up.)

 

You only add a new X datum to your X array if the X value is different from before.  (Or likewise for the Y).  Could  this ever happen?  If it does, that is another way that X and Y data won't line up properly.

 

As for showing only the last 100 points, you just need to maintain the array in the shift registers so that it never grows above 100 points.  If you add an element and the array gets to 101, then you need to delete the first element from the array.  You can do this yourself.  But I have also seen some subVI's that are called "buffer" or " circular buffer" or something like that.

 

 

0 Kudos
Message 7 of 12
(5,376 Views)

Hey there, like Ravensfan said, run continuously is not the way to run a VI, and yes, if you get the same data twice, your structure won't send the data over, even tho it's new. Instead, try to find another way to detect when new data comes your way and use that instead of the boolean controls you'll find in this mod to your VI that is somewhat less intensive in CPU, using producer-consumer architecture. Also yes, is there correlation between the data? Can it be trusted to update reasonably well? As for the circular buffer, take a look at this example

 

https://decibel.ni.com/content/docs/DOC-3414

 

EDIT: I forgot to add the release queue VIs to stop the consumer loops as well. Just please add those to the end of the producer loop queues and wire the error cable directly to stop condition on consumers instead.

Message 8 of 12
(5,372 Views)

As for the CPU ,I have no problem adjusting the loops to run every 500ms (see the block diagram).

 

and for the two variables I can guarantee that withevery X comes there is a new Y available and thats no problem for me at all ,however I tied the plotting with the arrival of X data only.

 

my problem now is in the array buffer ,I took a look at the link for the circular buffer you sent ,thats not what Im looking for ,I attached a picture illustrating what I mean by keeping the array size constant. the transition im looking for is the same as the ones in the photos.

 

Note: Daikataro ,I didn't get anything from the mods in the vi ,I'm not that expert bro !! 😄

 

Thanks

Download All
0 Kudos
Message 9 of 12
(5,364 Views)
Solution
Accepted by topic author shadymohamed

One thing I didn't notice before on your VI is you are using the wrong function when building data onto your array.  You should be using Build Array.  Not Insert into Array which is more meant for stuff going into the middle of an array.  And the way you are using it, you are actually inserting data at the beginning and not the end.

 

I don't know what you tried and why you think circular buffer is not what you want to do.

 

Take a look for a function called Data Queue Pt by Pt which effectively does what you want.

 

I'm going to attach a subVI I have used.   I modified this from something I found.  I think I found it somewhere within LabVIEW itself, or an example, maybe the forums, but I can't find the original source again.  And I don't see it in the comments of the VI. (If anyone knows, please comment.)

 

 

Message 10 of 12
(5,350 Views)