LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically Changing Table to File - Advice?

My current setup for logging data selected by the user has been to a simple csv file with each read going to a new line.

 

This has proved to be very annoying as the user must then reformat this file to their liking.  An example would be that the user requested a voltage and current at the same time and would like them to be in separate columns on the same row.

Example:

Before

Time,Measurement,Value

0:10:00,Voltage Measure,5.1

0:10:00,Current Measure,.12

0:20:00,Voltage Measure,4.2

0:20:00,Current Measure,.23

 

After

Time,Voltage Measure,Current Measure

0:10:00,5.1,.12

0:20:00,4.2,.23

and so on...

 

So I have decided to allow the user to assign Measurements to a certain "column" in a table.  And for every measurment at that time (1 second intervals), it gets put into the apropriate column.  Then if a measurement comes at a different time, go to the next row and keep going.

 

My issue is if there is an efficient way to go from a table to file??  I know there is ArrayToFile but didn't see any TableToArray or TableToFile (csv type) (may add that as a request).

 

Code replies are appreciated since I would want this to be as efficient as possible.

 

Dependent on people's replies would indicate how often I should flush to the output.  

 

Thanks

0 Kudos
Message 1 of 2
(2,959 Views)

Never tested it against efficiency, but the easiest way of passing data table to a file is using the clipboard: the following code reads an entire table into the clipboard and creates a file with table content; columns are tab-separated, rows are ended with usual CRLF termination, empty cells are honoured; the file can be read next with notepad.

 

    int        avail, fH = 0;
    char    *txt = NULL;

        ClipboardPutTableVals (panel, control, VAL_TABLE_ENTIRE_RANGE);
        ClipboardGetText (&txt, &avail);
        if (avail) {
            fH = OpenFile ("table.txt", VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII);
            WriteFile (fH, txt, strlen (txt));
            CloseFile (fH);
        }
        if (txt) free (txt);

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,939 Views)