LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I am able to save data to a file (csv), but my data does not look right? Can someone please help?

Solved!
Go to solution

My goal is to create a file every whatever time I set (in seconds).

Everything works fine, the problem is just the data structure on my file does not look good. What am I doing wrong? I have attached my vi

 

P.S.: I would like to use "Write to text file" block. I'm not trying to use a different VI/block such "write delimited spreadsheet"

0 Kudos
Message 1 of 12
(1,849 Views)

Write the header just once, when you make the file for example.

 

snip.png

0 Kudos
Message 2 of 12
(1,839 Views)

In the VI you attached, you are generating new data ever 1 second and appending it to the end of your 2-D array but you are also writing the entire header + 2-D array to your text file every single iteration.

 

One way you could fix this would be to write the header when you create the file and then in your write data to file loop only write the array of three random numbers each iteration so you're basically adding a row to your file every iteration.

Matt J | National Instruments | CLA
0 Kudos
Message 3 of 12
(1,835 Views)
Solution
Accepted by topic author GRCK5000

I think I solved the problem.

0 Kudos
Message 4 of 12
(1,816 Views)

@GRCK5000 wrote:

I think I solved the problem.


Remember this is a forum where people come to get answers.  How does your solution help others?  Consider that you wouldn't mark a post like that from someone else as the solution.

 

Would you mark mine as a solution if I merely posted, "Hey I have the solution for you."  Of course not.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 12
(1,776 Views)

Sorry about that, Billko. You are so right. Not showing others what to do would be very selfish of me. I'm not like that. I love helping and sharing with others because I've been helped so many times as well. So I attached the code.

GRCK5000_0-1677214947290.png

 

 

 

Message 6 of 12
(1,718 Views)

Hi GRCK,

 

why do you need to use a local for the file ref? Why not use a shift register?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 12
(1,707 Views)

Hi GerdW,

 

I am so used to local variable because I think it's a shortcut. Shift register can be annoying something especially if you have a state machine with multiple states. 

0 Kudos
Message 8 of 12
(1,669 Views)

Hi GRCK,

 


@GRCK5000 wrote:

I am so used to local variable because I think it's a shortcut


They are no "shortcut". And you should have learned that from all your previous threads…

 


@GRCK5000 wrote:

Shift register can be annoying something especially if you have a state machine with multiple states. 


Why?

  • All you need is one (1) shift register to hold all relevant information, no matter how many states you will have…
  • You can even create linked tunnels for your shift register wire to minimze wiring work…
  • Shift registers create very efficient LabVIEW code…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 12
(1,611 Views)

Thanks GerdW,

I’ve been thinking about staying away from local variables. I noticed it is not as efficient as shift shifters when passing data. 

also not as good as queues when passing data between two parallel loops. Local variables have the tendency to lose some data; whereas queues will make sure you get all your data. I definitely should stay away from local variables. I remember being yelled at so many times about avoiding using local variables unnecessarily.

Message 10 of 12
(1,600 Views)