LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Waveform saves to file but only shows 1 data point.

Hi all,

I am trying to write a simple (time,data) column to a CSV file.

 

I seem to hit a brick wall with every single step when trying to code LabVIEW. I do my best to learn, but have difficulty learning and making progress and seem to stumble around hitting dead end after dead end on what should be easy-to-solve problems.

 

I tried desperately to use the example here to incorporate it into my code: http://www.ni.com/newsletter/51339/en/ but the "Write To Spreadsheet File" is X'd out whenever I load the png.

 

I searched the forums and found that from the previous link, you can invoke a property node to export to excel. It works in the easy sine wave example, but when I do the same thing with my code I get nothing. I also need to hard code the path and writing to file, so I don't know if the invoke property node is the right solution for me. I have tried writing to delimited spreadsheet to no avail.

 

Right now I have the following code that is reading from an NI 9209 on channel 23 and is supposed to write to file. It does, but it only writes one data point (time,data). In every other simple example I see, including in the first link above, the write-to-file shows a continuous dataset from t0 to tFinal.

 

 

Once again I seem to be stumbling around trying to solve an easy problem. The examples I find are all different, extremely simple, and don't seem to help when I try to incorporate into what I am doing.

 

Can anyone please help me understand what I am doing wrong? I find LabVIEW one of the most difficult programming languages to learn and it is usually because I am not able to find the information that helps, or when I do, it doesn't seem to fit with what I am doing. I've uploaded the code I have right now into a snippet.

 

 

 

0 Kudos
Message 1 of 15
(3,314 Views)

You have a plain output tunnel, so all you get is the value from the last iteration once the while loop completes (and nothing before that: dataflow!). If you want to append new data as it is generated, the file IO belongs inside the loop (If the acquisition is more time critical, use a producer/consumer architecture and save  asynchronously).

Why do you configure the task with every iteration? Wouldn't once before the loop be sufficient?

0 Kudos
Message 2 of 15
(3,304 Views)

The subVI you are loading maybe "X'ed" out if you are loading an older LabVIEW VI into a newer version of LabVIEW.  Write to Spreadsheet File was modified a bit and renamed in the last couple years.  If you have an older VI that uses the older version, it will load a copy of that deprecated VI from another library.  It still works.  Or you can delete it and replace it with the newer version from the palettes.

 

The reason you only get 1 value is because tht's the way you programmed it.  You have a regular tunnel coming out of the loop which means you only get the last value.  You could try setting it as auto-indexing and it will build an array of waveforms.

 

Also things you need to fix.

1.  Create Task doesn't belong in the loop, it should be before the loop.  If you let your VI run long enough it would crash continually creating new task resources.

2.  You should have a Close Task after the loop.

3.  You need some timing function in there, either with a wait statement, or better yet using the DAQmx sample clock.

 

I would recommend you learn more about LabVIEW from here. How to Learn LV

0 Kudos
Message 3 of 15
(3,301 Views)

Hi Altenbach, thanks for the help.

 

I understand what you mean by the plain output tunnel and the value from the last iteration. I don't understand what you mean by " use a producer/consumer architecture and save  asynchronously". I honestly have no idea what you mean by that. That's how green I am.

 

The reason I have the task configured with every iteration is simple: I don't truly know what I am doing. In the past, I've used sequence structures to control DAQmx. What I hear you saying is that the DAQmx channel should be configured, then the dataflow goes into a while loop to read the data, and the write to file outside of the loop?

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

Thanks RavensFan.

 

"You could try setting it as auto-indexing and it will build an array of waveforms." I'm not sure what auto-indexing is, but I will google it and try my best.

 

I can fix (1) and (2). For (3), I've used wait statements in the past but I don't understand the difference between clock references. The only time I've used a sample clock is in an already created example.

 

I don't mean to sound dismissive when I say this: I've tried that link before. I went through all of the DAQmx tutorials and have still wound up at this point. I think I may have to accept that I'm not a programmer and that even though all of the tools are in front of me, I don't know what to do with any of them. It becomes complex very fast and I seem to just hit walls. I seem to be extremely ignorant of what you guys are trying to tell me, and that's the problem. Again, with total honesty, I am trying to learn this but it doesn't seem to work. I stumble around and sometimes I get things to work, but other times I am 100% lost. Am I just not a good fit?

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

@JAB2019 wrote:

What I hear you saying is that the DAQmx channel should be configured, then the dataflow goes into a while loop to read the data, and the write to file outside of the loop?


The configuration comes before the loop. If the data acquisition is not time critical and the disk IO can keep up easily, you would acquire and append to the file with every iteration (inside the loop, not after!).

Message 6 of 15
(3,267 Views)

Thanks Alten. I think I am getting closer to what I need, but every time the disk IO appends it creates a new header. I attached a screenshot. This is using the Export Waveform to Spreadsheet VI. I would expect LabVIEW to export the entire waveform, but it doesn't. It's not a waveform at all, it's 1 data point. Why do they call it "Export Waveform" if this is the case? It isn't making sense to me.

 

It looks like there is a Boolean option to turn the headers on and off with this VI that I can use, but this is where I run into troubles programming: if there weren't an option to turn off the headers, would I have to write an entirely different set of code?

 

EDIT - turning off headers gave me what I need, however, I have this set to 1 channel out of 32 that are being used. My only path forward that I know now is to create 32 of these programs that call each of the 32 channels. I know there has to be a better way to do that. I know I can specify for it to open the entire port, but I don't know how to separate all of the data in each channel from that point. It is easier, for me, to create 32 of these separate loops, but I fear it may be too slow. Thoughts?

Download All
0 Kudos
Message 7 of 15
(3,265 Views)

For some reason the forum won't let me edit my reply again.

 

EDIT 2 - I have successfully added 5 channels to the task and have 5 channels writing to a single file. With more than one channel, the Write Waveform to Spreadsheet VI puts a space between each row. This is strange to me. With one channel only, there are no row spaces, and I expected it to be the same with multiple channels. I hope what you are seeing here is an honest effort to solve this problem on my own.

 

EDIT 3 - When I add all 32 channels to the task, the whole program is extremely slow and only records a data point every 5 or 6 seconds. This isn't going to work for me because I need millisecond recording. What can I do?

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

For speed, you really should use lowlevel file IO:

  • before the loop, open the file and write the column headers once
  • inside the loop,format each row and append to the open file using lowlevel primitives..
  • Close the file once the loop completes.

What are the loop time requirements?

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

RavensFan, I have a timer in the loop but the DAQmx Read VI is running way too slowly for what I need. I am acquiring data every 5 seconds with 32 channels whereas I was acquiring 5 datapoints per second with 1 channel. Will adding the DAQmx Timing help this? I don't understand why it is running so slowly here. When I use the DAQ Assistant to configure all 32 channels and test them, they all run very fast. I know I am doing something wrong here. What is it?

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