Table Of Contents

DAQ PlotProgramming ► Logger

Note: Programming is an optional feature and is not part of DAQ Plot

This section shows how to embed DAQ Command into your own application for logging purposes. It shows how to do it in vanilla C-Code.

#import <stdio.h>

int print_daq_data()
{
/*
Instructions:

1) Run DAQ Plot and configure DAQ hardware.

1.a) Make sure the data source outputs to stdout.
1.b) Choose single-shot or continuous CLI operation
1.c) Save the preference file to /Library/Vvidget/Configuration/daq_command/my_config.daqplot
1.d) Quit DAQ Plot.

2) Run this program.
*/

FILE *p_stream;
int number_read;
double second, value_1, value_2, value_3, value_4;
int line_index;
char output_buffer[2049]; // remember null character delimiter
char delimiter;

fflush(stdout);
p_stream = popen("/Library/Vvidget/Helpers/daq_command my_config.daqplot", "r");

if(p_stream == NULL)
{
fprintf(stderr, "Could not open process stream\n");
return 1;
}

printf("Started daq_command setup to read a maximum of 100 time steps.\n\n");

/*
A single-shot CLI will start daq_command and stop it with one line of data, whereas
continuous CLI will keep daq_command running and output data one line per time-step.
*/

/*
This test tool will sample 100 time steps and then stop daq_command and exit.
*/

for(line_index = 0; line_index < 100; line_index++)
{
number_read = fscanf(p_stream, "%2048[^\n]", output_buffer);

if(number_read == EOF)
{
break;
}

number_read = fscanf(p_stream, "\n"); // skip CR

if(number_read == EOF)
{
fprintf(stderr, "End of line delimiter not found.\n");
break;
}

second = 0.0;
value_1 = 0.0;
value_2 = 0.0;
value_3 = 0.0;
value_4 = 0.0;

/*
The following assumes that you turned on seconds and 4 channel values
for stdout output in the Export Preferences.
*/

sscanf(output_buffer, "%lf %lf %lf %lf %lf", &second, &value_1, &value_2, &value_3, &value_4);

printf("Line %d output from DAQ hardware:\n\n", line_index + 1);
printf(" %s\n", output_buffer);
printf(" Scanned seconds and first four data values:\n");
printf(" %20.4f %g %g %g %g\n", second, value_1, value_2, value_3, value_4);
printf("\n");

}

if(line_index == 0)
{
fprintf(stderr, "\nCould not read any output lines.\n");
return 1;
}
else
{
fprintf(stderr, "\nRead a total of %d lines.\n", line_index);
}

pclose(p_stream);

return 0;
}

The code above shows how to log data to your own program. To send commands to the DAQ hardware, in addition to logging, see the feedback project (Projects).


© Copyright 1993-2018 by VVimaging, Inc. (VVI); All Rights Reserved (Legal). Please email support@vvi.com with any comments you have concerning this documentation.