Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

read file

/*write data to file*/
int CVICALLBACK DAQThread(void *functionData)
{
....
//tpTyroProject->EnabledChNum the number of aquired channels
//tpTyroProject->Acq.BufferSize buffer of every aquired channel
buffSize=tpTyroProject->EnabledChNum*tpTyroProject->Acq.BufferSize;
if ((pBuffer = (double*)malloc(buffSize*sizeof(double)))==NULL)
return -1;

datFileHdl = OpenFile ("data.bin", VAL_WRITE_ONLY, VAL_APPEND, VAL_BINARY);

/* Acquire data indefinitely into circular buffer */
iStatus = AIStartAcquisition (iDevice, AcqChLabel,buffSize*sizeof(double) ,
tpTyroProject->Acq.AcqRate, 0.0, 0.0, &dActScanRate, &taskId);


/* Main loop that reads data from the buffer */
while ((iLoopCount*buffSize/4Acq.AcqLength*tpTyroProject->EnabledChNum)
&&(iStatus==0)&& (!daqStopFlag))
{
/* Checks the backlog in the buffer */

iStatus = AICheckAcquisition (taskId, &scanBkLog);

if ((scanBkLog >= buffSize/4) && (iStatus == 0))
{
/* Transfers data from the double-buffer */
iStatus = AIReadAcquisition (taskId,tpTyroProject->Acq.BufferSize/4 ,
CONSECUTIVE_MODE,&scanBkLog, GROUP_BY_SCAN, pBuffer);

WriteFile (datFileHdl,(char *)pBuffer ,sizeof(double)*buffSize/4 );

iLoopCount++;
....
}
ProcessSystemEvents();
}
....
free(pBuffer);
}


/*read data from file*/
double arr[100] ;//globle variable

int CVICALLBACK opnFile (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
....
fileHdl = OpenFile (pathName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);
SetCtrlAttribute (panel, PANEL_TIMER, ATTR_ENABLED, 1);//Enable timer
....
}

int CVICALLBACK timerTick (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
...
ReadFile(fileHdl,(char*)arr,100*sizeof(double));
plot = PlotY (panelHandle, PANEL_GRAPH, arr, 100, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
...
}

I got wrong result from the graph when I run my program to read data from "data.bin",anyone help me!
thanks a lot
0 Kudos
Message 1 of 2
(2,373 Views)
All I can tell from this code section is that you are doing an analog input and displaying it to a plot. This is not enough information to help you in any way. I would suggest trying one of the shipping examples that is installed on your hard drive.

Please do not just post code. Tell us about you application, what hardware you are using. What does "I got wrong result" mean? Are your readings off by a scale factor or an offset and what is "AcqChLabel"? What happens if you do not write it to a file and just plot it?

I would really like to help you, but you need to give us more information.

Joshua
0 Kudos
Message 2 of 2
(2,373 Views)