LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Replay data acquried by DAQ card

Hi,
I meet a problem about replay data acquried by my DAQ card NI PCI-6014
I save the data acquried by 6014 with ArrayToFile function ,the data are saved in ASCII format
but now I want to replay the data in a StripChart control ,just like being accquried
the data was saved in a *.dat file ,its size is about 100MB,
At first I thought of using the FileToArray and then PlotStripChart,but the data is too large
for example :100MB,and can't be loaded to the buffer all at one time.

SO ,MY Questions are here:

1. Is there a way to reliaze my program :Replay the data just as they are being acquried.and how?
2. Is there any function can read the data stream from a large data file instead of load them
to the buffer in one sigle time ,and how?

Please help
Thanks a lot
Regard Guan

Windows XP sp2
NI PCI-6014
LW/CVI 7.1
DAQmx 7.4
0 Kudos
Message 1 of 5
(3,330 Views)
Unfortunately there is not a simple function that can read only part of a large file and transfer to an array in memory: while ArrayToFile can append data to an existing file (so that you are permitted to work with relatively small blocks of data at a time), FileToArray pretends to treat the whole file at a time, so that you may get some error with very large blocks of data.

In that case, you could try to separate your acquisition into different physical files according to criteria omogeneus with your application, permitting with this to read back them in blocks and plot test results as you want.

In case this option is not possible, in my opinion you will need to open and read the file one line at a time using for example ReadLine() function and scan the single lines with sscanf() or Scan() functions, but I'm afraid you will have some surprise about program efficiency and speed... This solution will need to be carefully trimmed for speed and efficiency: for example it seems to me that sscanf is a bit faster than Scan but I'm not exactly sure: since you will use these functions for thousands and thousands of times, it's better that you test each solution to search for the fastest one.

Another approach could be to read large blocks of data from the file using fread() and scan them in memory: if your file is stored with fixed width columns, it's easy to calculate block dimension that's equal to some given number of rows; this approach could be relatively more efficient than the preceding one, but you'll have to deal with the possibility of a row longer or shorter than expected (you must check that every block ends with a CR LF pair and in case it does not, hold the partial line read and append the next block to it).


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?
Message 2 of 5
(3,322 Views)
Hi,
Thanks a lot for your help
I'll try .
Regard.
Guan.
0 Kudos
Message 3 of 5
(3,316 Views)
Hi .Roberto
Thanks for your help,
I'm very new to CVI
Hope some other questions may not bother you:
I can't find fread() ,sscanf() in CVI
and If the ReadFile() can be a solution?
//////////////////////////
ReadFile():

Reads up to count bytes of data from a file or the Standard Input into buffer. Reading starts at the current position of the file pointer. When ReadFile completes, the file pointer points to the next unread character in the file.
/////////////////////////
Since the file pointer points to the next unread character in the file when ReadFile() completes,
So use the statement time after time until the file is finished.
I don't know if it can works 'cause I 'm not familiar with ReadFile()

Here is some of my code ,just test if my idea is feasible
but it doesn't work correctly

////////////////
static char proj_dir[MAX_PATHNAME_LEN];
static char file_name[MAX_PATHNAME_LEN];
static double wave[100];
static int handle;


static int err;
static char temp[50];
static int fileHandle;
static byteRead=100;
...
...
...
if (FileSelectPopup ("", "*.dat", "*.dat", "Name of File to Read",
VAL_OK_BUTTON, 0, 1, 1, 0, file_name) > 0)
{
GetCtrlVal (handle, Examp1_InputType, &fileType);

fileHandle = OpenFile (file_name, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
byteRead = ReadFile (fileHandle, temp, 50);
DeleteGraphPlot (handle, Examp1_Graph2, -1, 1);
PlotY (handle, Examp1_Graph2, temp, 50, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_RED);
....
...
temp[50] is the buffer into which I read data
should I allocate for the buffer first?
in the PlotY(), temp is Char[], but is need to be numeric array,how can I make a transform?


Regard
Guan

帖子被GuanXuefei在06-19-2005 09:54 PM时编辑过了

0 Kudos
Message 4 of 5
(3,319 Views)
fread() and sscanf() functions are both located in ANSI C library, which is standard and included in all CVI projects. To determine if some particular function is present included in your environment you can let the system locate it for you: open a source file, next execute View >> Find function panel... menu item and in the dialog box that appears type the desired function (or part of its neme): the system will either open the function panel or show you a list of functions that include the string you typed, among which you can choose your function.

ReadFile function can be used, the same as ReadLine. The latter one is more confortable in that it automatically reads only one line at a time, but as I told you it can be *slow*.

In every case, these functions return a string that needs to be divided into separate items (doubles) using appropriate scanning functions (Scan() or sscanf(), as I already told you). You must become familiar with these functions to complete this part of your application, since there are several ways to scan a string: you must find the best compromise between easiness in use and speed / efficiency. I suggest you locate in the CVI help the section regarding the Formatting and I/O Library to study the possibilities of Scan () function. As per the sscanf () function you will need a standard manual of C language.


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?
Message 5 of 5
(3,305 Views)