LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write to spreadsheet always writing header

Hi There

 

i am trying to save data using a write to spreadsheet file.vi whilst using multiple instances to write both a header and channel names.

 

The issue I am having is that I dont know how to only get the Header and channels to write only once whilst continuously updating the actual data.

 

I know i need a loop but am having difficulties as to where to locate the header and channel write commands due to not being able to place a loop in a loop as im trying to use this in a producer consumer architecture.

 

write to spreadsheet.JPG

 

The actual data at the moment is saving like this;

 

Channel 1,Channel 2,Channel 3,Channel 4,Channel 5
26.695931 1264.239175 1265.031245 1263.931402 1264.283218 1265.603335 1265.295188 24.961623 1264.767105 1264.723050 1264.767077 1264.371149 1265.251065 1264.283201 1265.031094 1264.899071 1263.799468 1264.503094 1263.711894 653.372587
Test Name,Operator,UUT
Voltage Test,Nigel,AAA123
Channel 1,Channel 2,Channel 3,Channel 4,Channel 5
26.625061 1264.244430 1265.036502 1263.936655 1264.288472 1265.608592 1265.300445 24.928457 1264.772360 1264.728305 1264.772333 1264.376403 1265.256322 1264.288456 1265.036350 1264.904326 1263.804721 1264.508349 1263.717147 817.308725
Test Name,Operator,UUT
Voltage Test,Nigel,AAA123
Channel 1,Channel 2,Channel 3,Channel 4,Channel 5
26.701701 1264.245743 1265.037816 1263.937969 1264.289786 1265.609907 1265.301759 24.891822 1264.773674 1264.729619 1264.773647 1264.377717 1265.257636 1264.289769 1265.037664 1264.905640 1263.806034 1264.509663 1263.718460 818.468651
Test Name,Operator,UUT
Voltage Test,Nigel,AAA123
Channel 1,Channel 2,Channel 3,Channel 4,Channel 5
26.701701 1264.245743 1265.037816 1263.937969 1264.289786 1265.609907 1265.301759 24.854029 1264.773674 1264.729619 1264.773647 1264.377717 1265.257636 1264.289769 1265.037664 1264.905640 1263.806034 1264.509663 1263.718460 819.440776
Test Name,Operator,UUT
Voltage Test,Nigel,AAA123
Channel 1,Channel 2,Channel 3,Channel 4,Channel 5
26.704009 1264.248370 1265.040444 1263.940595 1264.292413 1265.612535 1265.304387 24.931925 1264.776302 1264.732247 1264.776274 1264.380344 1265.260264 1264.292396 1265.040292 1264.908268 1263.808661 1264.512291 1263.721086 820.826856
Test Name,Operator,UUT
Voltage Test,Nigel,AAA123
Channel 1,Channel 2,Channel 3,Channel 4,Channel 5
26.666267 1264.248370 1265.040444 1263.940595 1264.292413 1265.612535 1265.304387 24.894134 1264.776302 1264.732247 1264.776274 1264.380344 1265.260264 1264.292396 1265.040292 1264.908268 1263.808661 1264.512291 1263.721086 822.360773

 

Thanks

 

0 Kudos
Message 1 of 15
(4,018 Views)

Include some information in the queue data about the start of a new measurement. The evaluate that information in the writing case and write only a header if needed.

 

Regards, Jens

Kudos are welcome...
0 Kudos
Message 2 of 15
(4,001 Views)

I would not suggest Write to Spreadsheet file.vi to be used inside a loop, since it opens and closes file whenever you execute it. Instead use the write to text file primitive by converting the data to string and converting that to a spreadsheet string. In one case write the header value and then execute data writing in another case. Post your code for a clean suggestion.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 15
(3,989 Views)

It appears that you may have a state machine or something similar. Split the Write to File state into two states: Write Header to FIle and Write Data to File. Then call Write Header one time for each file and Write Data as often as needed.

 

Lynn

0 Kudos
Message 4 of 15
(3,965 Views)

Hi P@Anand

 

Thankyou for your reply after a few iterations i have come up with this solution to my problem

 

write header files.JPG

Although i didnt use the write to text and then convert i can work on that now I have something working.

 

Thankyou for your input its always appreciated.

0 Kudos
Message 5 of 15
(3,939 Views)

There is no way to tell from that pciture what you did (what's in the other case? what else is there? Why all these local variables?)

 

Overall, seems like way too much convoluted code.

0 Kudos
Message 6 of 15
(3,916 Views)
Hey altenback

Sorry for the late reply,

The first case "log file directory" when true writes the log file name and selects a directory to save to then at the same time changes the "change path" local variable to false, this is to ensure that this part of the code only runs once even though it is within the consumer state machine.

Following on from that into the next case when the "write log head" variable is true the sequence writes the log channel headers to the path then the next part of the sequence changes the variable to false so that this code doesn't run again on the next loop iteration.

The false case of this structure doesn't contain anything apart from the wires going through after this case there is another write to file that writes the actual data in the array to the file.

I was struggling with how to only change the path and write the log data once and could only manage to do it like this,

Any constructive criticism on how to code this task better is always appreciated.
0 Kudos
Message 7 of 15
(3,834 Views)

Please attach the VI. We cannot debug pictures.

0 Kudos
Message 8 of 15
(3,828 Views)

On a side note, I wish that write to spreadsheet file would just be scrapped. It causes more problems than it's worth. Just teach people from the start the proper way to do File I/O, don't abstract away open write and close all into a single VI.

0 Kudos
Message 9 of 15
(3,795 Views)

Heres the main VI with its additional sub VIs attatched

 

Sorry I dont know how to compile the whole project and upload that so some of the other sub VIs called on will be missing mainly the averaging ones.

 

0 Kudos
Message 10 of 15
(3,779 Views)