LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I add a time column on my tabular data

Bob schor. I've attached the VI. 

0 Kudos
Message 31 of 59
(999 Views)

First thing to do is to banish the Dreaded DAQ Assistant and its Evil Twin, the Express VI.  I notice in the spirit of providing as little help (to us) as possible, you have failed to mention what DAQ device you are using, so I can't create an equivalent, so I will "do it manually".

 

You seem to have two channels of data from K-type Thermocouples registering temperatures from 50-600°C, and are reading them 1 sample at a time at 3 Hz.  I'm going to approximate them as generating Random Numbers, Channel 0 being 0-1, and Channel 1 being 1-2.

 

DAQmx is really quite simple to use once you understand how to use MAX to build a Task for you.  I can't easily demonstrate it since I don't know your device, but if you do a Web search for "Generate Task with MAX", you might find something useful.  If that fails, look for "Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Situations".  What you really want to do is to generate Waveform output -- for a sample of size 1, this is a little bit silly, but still it makes plotting and other things easier.  Here is a Simulated Generator for a 2-Channel system, plotted on a single Waveform Chart as White (Ch 0) and Red (Ch 1) (this is a Snippet, which means you can copy the image (read instructions at the beginning of the Forum) to a LabVIEW 2018 Block Diagram and it will magically become LabVIEW Code).

Simulate 2-Chan 3Hz 1 Sample AI TaskSimulate 2-Chan 3Hz 1 Sample AI Task

If you run this, you'll see that it builds a nice Waveform Chart for you, starting at t = 0 (why?  because I set the Chart to plot Relative time, meaning from t = 0, instead of "Absolute Time", where the X axis would be, for me, 19:00:00, 12/31/1903).  There's no need for a Graph, so I left it out.

 

You have chosen to use a Table, which is strictly a String representation, for numeric data.  This seems inappropriate -- why reformat data and save it as anything other than it is?  Except, of course, that you can use an Express VI and don't have to think about what you are doing and whether it makes sense or not.

 

I'm going to leave this last part to you, but with a recommendation:  Instead of making a (string) Table, create an Array of Dbl, each Row representing a data point, with three columns representing Time (in seconds), Channel 0 Data, and Channel 1 Data.  Note that the Array of Waveforms going into the Chart gives you the Row information, as it has an Array of two Waveforms (Ch 0 and Ch 1), with t0 and Y for each Channel.  The t0's should be the same (so you can use either the Ch0 or Ch1 value) and the Y Array will be a single number for the Ch0 or Ch1 data point.  Build an Array with these three Dbl values (you'll need to convert the t0 Timestamp to a Dbl, there's a function to do this) and bring it out of the outer While Loop via an Indexing Tunnel, which turns it into the proper 2D Array of Dbl.  Try to do it.

 

Once you've done all this, you just need to replace the Simulated DAQ Task with a real DAQmx Task.  If you create the Task in MAX (look up how to do this), I can tell you the 3-4 DAQmx functions you'll need to use to accomplish this ...

 

Bob Schor

Message 32 of 59
(995 Views)

Bob schor , Thank you so much for your valuable information and time spent for me on this.

 It would be great if u could help me out on this as Im supposed to complete the same  before the weekend.

Thank you . 

0 Kudos
Message 33 of 59
(992 Views)

You supply the next iteration of the code (such as building the three-column array of times (in seconds), Temp 1, and Temp 2), provide some more details on your DAQ device (including a picture of the Task you created in MAX to acquire the two channels of Temperature data from whatever device you are using -- a Screen shot of the Task layout before you "Save Task" would be fine), and your best attempt at building the DAQ code (from your studying the Tutorial material on DAQmx that I pointed you to), uploading more code (means VIs) and pictures of DAQ Tasks, and the Forum members (including me) will provide additional help.  But it has to be your work.

 

Bob Schor

Message 34 of 59
(986 Views)

I'm using compact Rio with modular daq system. And I think I didn't build a task in max.  Anyways I ll learn about it. 

 As of now I'm happy with the readings buh I want to save it to excel , so that I can proceed for now. 

Thank you

0 Kudos
Message 35 of 59
(974 Views)

What more should I add to the snippet uve attached ? I could try too add array for the data. Buh I wasn't able to save the data to excel. 

0 Kudos
Message 36 of 59
(968 Views)

@Zaqf wrote:

I'm using compact Rio with modular daq system. And I think I didn't build a task in max.  Anyways I ll learn about it. 

 As of now I'm happy with the readings buh I want to save it to excel , so that I can proceed for now. 

Thank you


Please write down where you're at, what you've managed to complete so far, and what you're still trying to do.

 

I want to reiterate, the cRIO system/collection of modules are typically really great (especially considering price compared with e.g. PXI) and so they're worth learning to use with either DAQmx (for the newer chassis, 904x) or perhaps even FPGA (although that's a whole new world of complexity - maybe better to work out the existing systems first).

 

Let us know where you're at, what you've gotten done and what you're trying for next. Especially if you've managed to use the DAQmx code or avoided any of the DAQ Assistant nodes. This is the link that I think Dr Schor mentioned earlier: Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications.


GCentral
Message 37 of 59
(957 Views)

I understand Daqmx is really worth the study. So I'll have to do the study in detail .

 Does switching to Daqmx help me save the data in excel ? Coz I just want to save data in excel rn. And yea , I think I should remove the express vi and build an array , buh could someone edit a write to excel function on the VI . 

Thank you so much. 

0 Kudos
Message 38 of 59
(942 Views)

To create real Excel files (i.e. .xls, .xlsx, etc) you can use the Report Generation palette's VIs. There are quite a lot, but these will allow you to create either from a template or from scratch very specific, detailed Excel files. However, they can be quite a bit of work.

 

A much simpler solution is to create a csv file (comma separated variable), or tab-separated variable (sometimes abbreviated tsv, but often still .csv). To do something like that, you can instead use the "Write Delimited Spreadsheet" function on the File I/O palette.

That function is much easier to use and unless you really need some Excel-specific functionality, I'd definitely recommend it. (Of course, you can open csv files in Excel).

 

The "Write Delimited Spreadsheet" function accepts 1D or 2D arrays, along with inputs to control if the data should be transposed, and which delimiter (tab by default) you'd like to use.

 

Here's an example snippet:

csvCreation.png

Because I don't connect a file path or reference to the function, a dialog box will appear to ask for a file name. If you want to specify a path, you can do that too, and it will prevent the dialog from appearing.

I'm using transpose, because here my "data array" is 2 rows of 100 elements, and in Excel you usually prefer to see data going down rather than across the page.

If you want to add data to the same file, make the "append" input true.

 


GCentral
Message 39 of 59
(938 Views)

Thank you so much cbutcher.   You guys are too good. God bless you all. I hope this would do it. 

Would be great if you could attach as vi. 

 

0 Kudos
Message 40 of 59
(928 Views)