LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write set of periodic measurements to Spreadsheet File in one row

Solved!
Go to solution

I have the following task to finish:

1)      Periodically  every 1 second acquire one (or more) sample of data from two Ai channels

2)      Write 6 consecutive periodic measurements into one row with a timestamp at the beginning. In such situation will be a total of 12 readings (two Ai channels every 1 second for 6 seconds) and the time stamp, total of 13 columns in one row.

3)      Write next (following) sequence of next 6 measurements into a second row with a timestamp at the beginning (append to file), and so on.

 

 

Additionally, for very large file, a sequence of 12 or 18 measurements in one row is required.

How to modify attached file?  or any other solution.

I have another version of this file with “Write to Text File” (spreadsheet format) kipping a file continuously open through entire test.

 

Equipment:

DAQ-6221 (37 pin)

LabView 8.6.1

Tks.

0 Kudos
Message 1 of 10
(5,508 Views)

You are going to have to make quite a few modifications and futher define some of your requirements.

 

First thing to change is to place the DAQ configuration functions and stop task outside the loop. There is no need to repeat all of this with each loop iteration. Second, you say that you acquire one or more samples but want 12 columsn every 6 seconds. The VI is currently set to acquire 2048 samples per channel so you can't save all of that data into 12 columns. You could take the mean of each channel and save that. Third, you have nothing in the program to take samples every second. Use the Wait (ms) or Wait Until Next ms Multiple to control the acquisition rate. Fourth, you are going to have to monitor the iteration count to determine when to save the data. You can use the Quotient & Remainder to do the save every 6 times. Fifth, you are going to have to modify how you are creating the data array. You should use a shift register so that you append new elements to the end and at the sixth iteration and after the file write is done, clear the array in the shift register. Lastly, I think your method of saving the data is confusing. You will have one row with a single timestamp but the different columns will actually be acquired at different times. If you write an analysis program to handle that, it will be fine but anyone looking at the raw data will be totally confused.

Message 2 of 10
(5,501 Views)

Hi Dennis

This program works, tested with PCI-6221. It writes time stamp, Ai0 and Ai1 in a row.

I used “While Loop” to get readings at a time when trigger from the Co0 is fired (1 per second). Trigger is internally connected to the output of the counter (see notes on “Block Diagram”). I do not have clearer solution.

 

Settings have to be reentered, for some reason, the software “SAVE” function does not save new settings, I do not know why?  It saves only some arbitrary settings.

 

I need only two analog channels, Ai0 and Ai1 with only one sample per Ai channel. If program runs with multiple samplings it writes only time stamp, Ai0 and Ai1 as single values in the same row.

The counter Co0 is responsible for taking sample every 1 second (Ai0 and Ai1), (wired internally).

Both circuits, Ai  and Co  are running simultaneously. Probably they  should be connected somehow (error lines ?).

 

They are 6 sequential events (one group) which are monitored over long period of time and one timestamp is more transparent.

I do not have experience with shift registers and data arrays; can you provide more details how to do it?

Tks

0 Kudos
Message 3 of 10
(5,482 Views)
Solution
Accepted by topic author behappy

By settings, I assume you mean the values of the front panel controls. What is saved is not at all arbitrary. The default values of the controls are saved and you must have changed the defaults at one time. To make new defaults, make the changes and then go to Edit>Make Current Values Default.

 

Look at the attached code. On iteration 0, the timestamp and two data points are appended to the array. Iterations 1 through 4 append just the new data. Iteration 5 appends the new data and then clears the array.

Message 4 of 10
(5,473 Views)

 Hi Dennis

You are a brain.

You were right from day one.  I removed the large “While Loop” and now trigger is working properly. Your code is doing exactly what I need it.

If the trigger is activated everything is working well.

Just only one observation, if the circuitry is idling for more than 10 seconds (DAQmax Read TimeOut default setting), it writes empty spaces instead of measurements, whole row every 90 seconds.

My entire project is far from finish. My next dilemma is how to create digital array with (1s) and (0s), writes it into DAQ max Write as a data and generate pulses by a digital output(s) shifted in time compare to mutual clock with fixed duty cycle, similar to pulse width modulation.

Probably, I am going to post another “Please Help”.

This task is SOLVED.

Thank you very much Dennis, you saved me a lot of time! I own you at least a bear, a good one!

Tks.

0 Kudos
Message 5 of 10
(5,452 Views)

behappy wrote:

 Hi Dennis

....

Thank you very much Dennis, you saved me a lot of time! I own you at least a bear, a good one!

Tks.


If it's all the same to you, I'd rather have a beer.Smiley Very Happy

Message 6 of 10
(5,449 Views)

Hi,

 

This solution is very helpful to me. Thanks for it.

However, I encountered difficulty when I tried to output multiple samples. Is there any solution if I need multiple samples instead of only 1 sample?

 

Thank you very much  🙂

 

 

Kid

0 Kudos
Message 7 of 10
(5,237 Views)

You can just change the Analog Read to be N Channels N Samples. Just be aware that when you use build array it'll generate a 3D array. It's simply a matter of manipulating your data appropriately to get it into 2D type before writing to Spreadsheet.

 

You could break up the data into separate shift registers for each channel, or do it before writing it, or whatever.

Jeff | LabVIEW Software Engineer
0 Kudos
Message 8 of 10
(5,223 Views)

Hi Jeff,

 

Thanks for your reply. Do you have any examples or reference on how to achieve this?

I am totally new to LabVIEW and I really appreciate that if there are some examples on this.

 

 

Kind Regards,

kid

0 Kudos
Message 9 of 10
(5,208 Views)

Hi,

 

Something like this is I think what you're looking for.

Jeff | LabVIEW Software Engineer
0 Kudos
Message 10 of 10
(5,196 Views)