LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write spreadsheet files of data from NI OPC

Hi Everyone,

 

I am new to lab view and want to start by completing my application. I have some tags in my NI OPC server. SOme of these tags are to be saved in spreadsheet file for analysis with ms timestamps. SInce the tags from OPC only contains samples , I have to generate the timestamps from system PC.

Can anyone guide me from where should I start.

 

Thanks.

0 Kudos
Message 1 of 9
(3,235 Views)

Hi falcon,

 

when you are new to LabVIEW you should take all those free online courses offered by NI on their website. They are for FREE!

 

I have to generate the timestamps from system PC. Can anyone guide me from where should I start.

Well, I would start looking at the functions in the "timing functions" palette…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(3,220 Views)

By "spreadsheet file", do you mean a file with the .xls or .xlsx extension, or a text file written to "look like" a spreadsheet, such as a .csv file?  

 

I also second Gerd's recommendation to learn the basics with the Online courses, and to do some code development and testing yourself first.  Note that a good way to learn how LabVIEW does things (such as TimeStamps) is to write a tiny LabVIEW VI that simply has the function in question "inside", with controls wired to the input and indicators wired to the output.  You then put test values on the Input Controls, press Run, and see what (all of) the Outputs say.

 

BS

0 Kudos
Message 3 of 9
(3,202 Views)

Hi GerdW,

 

Thanks for d reply. My main challenge is that I have been able to data bind the field from OPC tag, but how to create a dynamic 1 D array.

I praciced some normal programs on loops and i now understand that I have to build a 2 D array , one consisting data and one consisiting of time stamps.

Please correct me if I am wrong in my approach. But I am stuck in the begining regarding how to save all the data at a specfic rate which is being sent through the NI OPC tag.

 

Thanks

Falcon

0 Kudos
Message 4 of 9
(3,178 Views)

I mean xls or xlsx format only.

thanks,

0 Kudos
Message 5 of 9
(3,177 Views)

Personally, I would go with the 2D array to keep the data and timestamps separate.

 

If you REALLY insist on a 1D array, you'll need to convert your data and your timestamps into strings and concatenate the strings to a single data point.  But, what would you really gain from doing this?

 

xls means using the Report Generation Toolkit or putting together ActiveX calls by yourself.  In case you were curious, they were asking because there's a Write to Spreadsheet File VI that would allow you to easily write to something like a csv.  I believe Excel handles csv files rather well if you want to try this and then opening it in Excel.

 

If you already have the data, as it sounds like you do, the issue really just writing to a spreadsheet.  The NI OPC piece is handled.  You can check out: http://www.ni.com/newsletter/51339/en/ for a variety of ways to handle that.  I'd take a look at the code they have from the Report Generation Toolkit.  I try to avoid Express VIs whenever possible.

0 Kudos
Message 6 of 9
(3,151 Views)

You know, by now, that for true Excel files (.xls, .xlsx), you really need to use the Report Generation Toolkit (which you may, nor may not, have installed or available).  About a year ago, I posted a revised Example showing how to generate a simple Workbook here.  Feel free to adapt it to your needs.

 

Bob Schor

Message 7 of 9
(3,141 Views)

HI,

 

Thanks a lot for the help. I have been able to write the data along with the time stamps.I am now trying to make the file created more readable and working on following 3 tasks:

 

1)I am trying to add the name of columns in the spreadsheet created. I tried a lot but some how I was unable to do this. i am attaching my snippet and the csv file created in this process.

 

2) Is it possible to view the data of entire day through any other method other than Chart ( I have tried on chart and was able to observe data for longer durations)

 

3. How can I name my file with name containing the current date on which the logging was initiated?

 

Thanks and Regards,

Falcon.

Download All
0 Kudos
Message 8 of 9
(3,122 Views)

Hi Falcon,

 

1 - use a 1D array constant with the column names. Use several elements instead of just one as you do now…

 

2 - Yes. you can do. Collect the data of one day in a shift register and use a graph instead of a chart…

 

3 - There is a function "Format DateTime string" in the timing functions palette. And there is BuildPath in the File palette. See if you get things right using those two functions…

Best regards,
GerdW


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