LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in sorting my measurements in a text file (help with arrays)

Hello, I am a novice in labview, and I have been trying to continuously write my measurements in a text file but I am having difficulties in few things.

I don't like how the express functions look like and actually I am not handling them well with what I want to do.

My goal is:

 

1. I have to write 7 columns of data, continuously from a while loop.

2. In my text file I want to put the title of my 7 columns as strings. thought of doing that outside my while loop.

3. And then fill them out

 

I am measuring a simple sine wave comming from a signal generator, and since I don't have one at home, I created a virtual task...

the columns are: Sample frequency Fs, number of samples #s, I want ot extract time data, then amplitude, minimum peak, maximum peak and frequency.

 

I am having difficulties in handling array functions, and I would be very very very very grateful if anyone can give me an example how my code should look like.

I found many examples in extracting time data and so on, but I am just really overly confused now, and don't know what to do. Can someone also explain to me how to extract the time data?

 

After writing the measurements I need to read them as well and put them on a graph... but I suppose I will hande that when I learn how to write them first!

I appreaciate any help!

 

this is my VI:

 

0 Kudos
Message 1 of 7
(2,872 Views)

Dear aneley,

as you already figured out, it is better to use the lower level file I/O functions (instead of the Express VIs) for continuous writing.

If I understood your application correctly, you would like to save the data in text format with the values ordered into coloumns. To achieve this, it is useful to convert the numeric values to strings, using the string conversion and the concatenate functions.

Please find an example attached. I think you could easily modify this code to suit your needs.

I hope this helps you. Best Regards,

Message 2 of 7
(2,815 Views)

Thank you for your reply. Unfortunately I had a dead line last time i wrote, so I had to make do with express functions, but now I'm back again !

 

Your post really made it clear for me, and I've built a simple sample vi for writing waveform data to txt file to try it out.

 

I am having difficulties again in sorting my elements in the txt file.

I am trying to write two cloumns of X and Y values, X being the time.

It seems the Y values are being written in rows... don't know how to "transpose" it cause it's 1D...I guess that would work and then merge that string with time string?

it just looks messy. I've attached the result txt file as well as the snippet vi.

 

can you help me ?

 

Edit: I just realised that the test txt file I created was roughly about 10MB ! So I've attached just a few lines... Can you give me an advice how to make it simpler?

I asked my teacher should I stick with txt files or go with TDMS, she said stick with the txt...

 

 

Download All
0 Kudos
Message 3 of 7
(2,769 Views)

Just a tip: Your file is too large because you're writing values in every loop, and you're not using timing functions (e.g. Wait). With less than 10 seconds of execution I got more than 40k samples. 

 

Regards.

Mondoni
Message 4 of 7
(2,757 Views)

Hi aneley,

I think the Simulate Signal Express VI outputs a dynamic data type, which can be converted to a waveform. This consists of an array, which holds the Y values, and a time epoch 't0'. For further details please refer to the introduction page of the waveform data type: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8qkSAC&l=en-US

This means that you are writing an array of 'Y' values and a single 't0' value each time to your file and it results in the attached format.

If I understand your application correctly, you should process the Y values sequentially (in a for loop, for instance) and calculate the correct timing information for each sample using the parameters available in the waveform structure (t0 and dt) and then write it to the file.

 

 

As far as numeric accuracy is concerned, TDMS offers much more precise and compact representation for the double precision floating point numbers you are using.

I hope this helps.

Best Regards,

Message 5 of 7
(2,717 Views)

Thank you for your advices!

 

I managed to write X and Y values, time and amplitude, and it even looks nice now!

I attached a snippet.

 

I am back with two questions.

 

1. Now I am experimenting with event structures, and please tell me whether I should make this a new thread.

I've put a button that triggers an event to start the simulated signal in this example, and in that event i have a while loop that writes the data and so on. So i wanted to make the stop button in that while loop be my next trigger event, and I wanted to make that stop button do two things:

- trigger a new event that stops the VI

- stop the while loop in previously triggered event

 

I figured the mechanical action for the stop button has to be "switch when pressed" if I wish to use the "value signaling" property node.

I am not sure what I did, can someone please explain to me what old value is being called and which one is the new then. If I wire the property node to the new value, then the VI stops as soon as it starts the acquisition.

 

 

 

 

 

 

 

 

0 Kudos
Message 6 of 7
(2,690 Views)

Hi aneley,

I am glad that you achieved writing the values as you wanted.

You will also benefit from experimenting and learning event structures in LabVIEW, because they can be used in a lot of cases very efficiently.

As far as the boolean control's mechanical action is concerned we have to distinguish 2 basic types which are switch and latch. In switch mode, the control stays in the switched state until it is either programatically changed or switched again by the user. In latch mode basically it stays in a state until it is read out by your program. Now, if you consider what happens if the button is in latch mode and you read it's value at multiple places, you can easily imagine that it can lead to some confusion, especially when using it in an event case. To guarantee that you don't miss an event and the boolean value will still be valid inside the corresponding event case, LabVIEW only allows to use booleans with switch mechanical action inside an event structure.

 

In your particular case, use the switch mode to catch the event of pressing the stop button and terminate your program. Be sure to initialize the button's value at the beginning of your code in order to start up properly, otherwise, as said, it stays in the switched state.

 

 

By the way, here is some material about the event structures and the discussed settings, you might find useful:

https://www.ni.com/docs/en-US/bundle/labview/page/caveats-and-recommendations-when-using-events-in-l...

https://www.ni.com/en/support/documentation/supplemental/06/event-driven-programming-in-labview.html

https://www.ni.com/docs/en-US/bundle/labview/page/changing-the-mechanical-action-of-a-boolean-object...

 

Best Regards,

0 Kudos
Message 7 of 7
(2,650 Views)