LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing values to a csv file using LabVIEW

Solved!
Go to solution

Hello LV Experts,

 

I am reading voltage and temperature values from an Adam 5017 and Adam 5018 respectively using Modbus Communication. I need to write this values to a csv file with datetime stamp, Voltage, Temperature . I tried "Read a text file IO", it is only writing a single value and stops. Can anybody give me some suggestions. I am a student and I am new to LabVIEW. Your support in this matter would be valuable. Thank you in advance :')

0 Kudos
Message 1 of 13
(961 Views)

Hi Varghese,

 


@Varghese89 wrote:

I need to write this values to a csv file with datetime stamp, Voltage, Temperature . I tried "Read a text file IO", it is only writing a single value and stops.


Why do you use a read function when you want to write to a file?

 

How do you write to the file?

Why don't you attach your code?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(943 Views)

@Varghese89 wrote:

I tried "Read a text file IO", it is only writing a single value and stops. 


Do you mean "Write Delimited Spreadsheet.vi"? Or the "Write To Measurement File" express VI?

 

Post what you have. A lot could be wrong and if we post code it's unlikely it will fit in your code.

0 Kudos
Message 3 of 13
(933 Views)

- you need to convert numbers into string, 

- for the date stamp use the function FORMAT Date time , 

separate them with coma and

- use the function WRITE DELIMITED SPREADSHEET, using Comma as separator, this function expects you to input an array of strings. so when you have your string ready, just use build array and wire your string as a 1 element array ,

Share your code if you still have issues. 

 

LVNinja_0-1733765523535.png

LVNinja_1-1733765571362.png

 

 

0 Kudos
Message 4 of 13
(897 Views)

Hello LV Experts,

 

I am reading 8 voltage and 7 temperature values from Adam device using Modbus Communication. Now I need to write these values to a csv file along with timestamp. I tried "Write text file" but I am only getting a single row and not continuous values with time stamp and also my headers are not getting written. I converted the numbers into string using "Format into String" but I am confused how to loop and which loop should I use to get continuous values. Is there any better way to write to csv?. I am attaching my vi and Block diagram here. I am a student and I am new to LabVIEW. Your help is greatly appreciated. Thanks in advance :')

 

 

Download All
0 Kudos
Message 5 of 13
(850 Views)

Hi Varghese,

 


@Varghese89 wrote:

I converted the numbers into string using "Format into String" but I am confused how to loop and which loop should I use to get continuous values. Is there any better way to write to csv?. I am attaching my vi and Block diagram here. I am a student and I am new to LabVIEW. Your help is greatly appreciated. Thanks in advance :')


I don't see anything of this in your blockdiagram image. And I can't open your VI because of the LabVIEW version you use.

(Please downconvert to an older LabVIEW version before attaching. I prefer LV2019.)

 


@Varghese89 wrote:

I tried "Write text file" but I am only getting a single row and not continuous values with time stamp and also my headers are not getting written.


Do you correctly handle the "append to file" input of the WriteDelimitedSpreadsheetFile function?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(828 Views)

Hey, Thank you for the reply. I tried "write delimited spreadsheet". Now I am getting continuous values, but the date time is not visible in the csv and for each second, multiple entries are getting generated. I only want to write values every 10 seconds. Also I am unable to add headers to the csv. Please provide me with some more information. Thank you so much. 

Download All
0 Kudos
Message 7 of 13
(823 Views)

Hi GerdW, 

 

Thank you for your reply. Please find the down converted version of my vi. I am unable to add Headers and to control the duration of writing. Thanks in advance.

0 Kudos
Message 8 of 13
(808 Views)

Hi Varghese,

 


@Varghese89 wrote:

I am unable to add Headers and to control the duration of writing.


  1. To "add headers" you should write once to your file upon creation of that file and write your header row(s).
    In all later file writes you just append measurement data to the CSV file…
  2. You don't want to control "duration of writing", but "duration of execution"…
    There is no loop in your VI so it runs once and finished. When you want to repeat code (or parts of) then you need to place a loop in your code. Typically you initialize once before the loop (modbus communication, file creation), read data and save to file inside the loop, and finally close all references after the loop!

@Varghese89 wrote:

the date time is not visible in the csv


The date+time is clearly visible, but Excel indicates a "narrow column" with those hashmarks!

 


@Varghese89 wrote:
for each second, multiple entries are getting generated.

Because there is no timing in your VI.

How often/fast do you call your VI?

 

(I guess you use the RunContinuous button, which is WRONG for production stuff. That button/run mode is meant ONLY for debugging purposes!)

 

On your code: You could apply scaling directly on your array data, no need to index each element and scale it on its own by using so much duplicated code!

Best regards,
GerdW


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

Hi GerdW,

 

Thank you for your help. I need some more details.

 

1. Should I use one more "Write delimiter Spreadsheet" and add the header before the appending "Write delimiter Spreadsheet"

 

2. Which loop should I use?. Where can I adjust the time of execution in the loop.

 

Sorry, I am little confused as I am new to this. 

0 Kudos
Message 10 of 13
(780 Views)