Table Of Contents

DAQ PlotSupport ► Decoding Backup

Usually you will probably want to Export collected data. There are plenty of facilities to export data. This section deals with a much more efficient real-time exporting of data which operates while DAQ Plot is running.

If enabled (see Managing Backup), DAQ Plot writes real-time backup files. You can use another program to decode those files. The next section explains this process using conventional unix and C-language constructs, but you can also use any other system available for this purpose.

Decoding Backup Files

Backup files are encoded in this binary format. The linear backup can be decoded using this code:

#import <stdio.h>
#import <string.h>

{
FILE *a_stream;

int desired_read_byte_length;
int actual_read_byte_length;
char *read_buffer;
char *read_buffer_location;
double *sample_value_location;
double *sample_value_end;
unsigned sample_state;
unsigned number_of_amplitudes;
double current_sample_value_c_array[16];
double current_second;

a_path = "~/Library/VVI/DAQPlot/Backup/default_1.backup";

a_stream = fopen(a_path, "r");

if(a_stream == SAF_NULL)
{
printf("No backup file\n");
return;
}

number_of_amplitudes = 16;

desired_read_byte_length = (number_of_amplitudes + 1) * sizeof(double) + sizeof(unsigned);
sample_value_end = current_sample_value_c_array + number_of_amplitudes;

read_buffer = malloc(desired_read_byte_length);

actual_read_byte_length = desired_read_byte_length;

while(1)
{

/*
Poll read with a throttle
*/

actual_read_byte_length = 0;
while(actual_read_byte_length != desired_read_byte_length)
{
read_buffer_location = read_buffer + actual_read_byte_length;
actual_read_byte_length += fread(read_buffer, 1, desired_read_byte_length, a_stream);

if(actual_read_byte_length = 0) usleep(1);
}

/*
Decode a single-time-sample amount of 16 channel data
*/

read_buffer_location = read_buffer;
sample_value_location = current_sample_value_c_array;

memcpy(&sample_state, read_buffer_location, sizeof(unsigned));
read_buffer_location += sizeof(unsigned);

memcpy(&current_second, read_buffer_location, sizeof(double));
read_buffer_location += sizeof(double);

for(; sample_value_location < sample_value_end; sample_value_location++)
{
memcpy(sample_value_location, read_buffer_location, sizeof(double));
read_buffer_location += sizeof(double);
}

/*
Got some data, so now process it here using your own code.
current_sample_value_c_array : 16 element double array with channel data.
current_second: The second since 1970 of the samples.
sample_state: not documented
*/

}

free(read_buffer);

fclose(a_stream);
}


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