LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I display single elements on a graph

I have a program which reads in data from a TCP/IP port. This data comes in as a string array. I then manipulate the data, convert to binary, and then finally this data is converted to a double. The problem I am having is that at some point along my conversion, I am no longer dealing with arrays. I had to index a binary array to use some boolean function. Now I am only dealing with single elements. How do I get these single elements to display on a graph?
0 Kudos
Message 1 of 11
(4,089 Views)
Based on your description it sounds like that after indexing and processing the data you should combine the single elements (scalars) back into an array for display on the graph. This is done using the 'Build Array' function.

If the scalars represent different channels that you want to display on the graph, you in fact may want to use a waveform chart instead of the waveform graph. In this case you should combine the scalars into a cluster using the Bundle function instead of building an array.
authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 2 of 11
(4,077 Views)
JoeLaRosa,

I am not sure exactly what you are attempting so forgive me if I missed the mark but I think what you need to do is use a Build Array sub-VI in cooperation with a shift-register on your for-loop or while-loop.

Basically what happens is you create an array with one element on the first iteration of the loop and simply append an element to the array with each subsequent iteration of the loop. I have provided an image of the code snippet here for your use.

I hope that helped you.
-scraggs99
0 Kudos
Message 3 of 11
(4,075 Views)
Scraggs, I followed your example to the T, but still no go. Your approach was similar to one I have already tried using a For Loop. The graph would display no data, but the diplay was autoscaling. So I looked to see how big the array was going to the graph, and it had size 1. I am attaching a copy of my vi. I need to graph whats attached to "Output."
0 Kudos
Message 4 of 11
(4,069 Views)
Now I know that this problem needs to be resolved with some variation of the "Build Array" function, but it's not that simple. If someone suggests this to me, please support with additional information (just like scraggs did).
0 Kudos
Message 5 of 11
(4,068 Views)
The main thing I noticed about your code was that the while loop has no time delay in it other than the amount of time it takes the code in it to execute. I couldn't run the code as it was so I replaced the TCP code with two random number generators and also included my previous suggestions for building the array. When I was finished,I ran it and experienced the same incorrect behavior you were explaining!

I also noticed that my machine seemed to be bogged down. So, I checked it out and sure enough the CPU was maxed out running the LabVIEW process. I added in a time delay in the while loop to allow the processor time for other operations and it worked great. The CPU was also not bogged down.

Is it possible that your while loop is just spinning out of control? Or do you believe the TCP communication provides enough latency to keep this from happening? I would recommend placing an indicator by your iteration counter to see if this is what is happening.

Anyway, let me know how it goes. I have attached some of the modified code for you.
-scraggs99
0 Kudos
Message 6 of 11
(4,054 Views)
I added a for loop to your VI and was ready to post it when I saw Scraggs99 latest post. I did not test because I had no realistic data and no TCP device to talk to. I think the for loop is the answer to your question about how to re-build the array. It auto-indexes through all the elements in the array derived from your TCP string.

If we have not answered your question, post a version with a string control with the TCP string data saved as default so we can see your data.

Lynn
0 Kudos
Message 7 of 11
(4,048 Views)
Ok, now this is just wierd. This is maybe the 3rd program or so I've written in Labview, so please consider me a noobie. I had no idea that time delays are required in While Loops (maybe that's why my 2 other programs ALWAYS ran at 100% CPU...guess LabView isn't as inefficient as I thought!!!). When I originally tried scraggs' suggestion, the program would just crash giving me a TCP timeout error. With the delay (of 1ms) in the while loop used to fill the array, the program no longer crashes; however, my original problem still exists. The graph continuously autoscales, but no data is displayed (could it be that only index 0 is being updated?). I tried to view your vi, scraggs, but I have version 7.0...it couldn't open it. Is there anyway you can port this to 7.0? Or could you just send me a jpeg? I greatly appreciate everyone's input and I know we can solve this quickly. We are definitely on the right track. Thanks, Joe.
0 Kudos
Message 8 of 11
(4,044 Views)
Here is the image you asked for.... All it really shows is the use of a time delay, displaying the loop iteration count and the appended array wired to a waveform chart.
-scraggs99
0 Kudos
Message 9 of 11
(4,038 Views)
Ok, problem solved...I think. I gave up trying to add the single elements to an array, and fixed my program from the start. I orginally had an array of 2048 bytes coming from the TCP function. This array was then indexed and the single elements were processed. Instead, I decided to put the processing inside a For Loop (now that I know what a for loop does!!!) and everything works fine, or at least until my hardware stopped working:(. But that's a different situation.

P.S. My program functions as a Data Acquisition application, acquiring data over TCP/IP. My hardware is sampling at 10k. How does the delay function really work? Will I be losing samples by putting a delay of 1ms (the smallest value I could find) in my While Loop? Thanks.
0 Kudos
Message 10 of 11
(4,003 Views)