Exemplo n.º 1
0
Arquivo: WDplot.c Projeto: bianle/daq
unsigned int __stdcall PlotThread(void* data)
{
	uint32_t retVal= 0;
	WDPlot_t *plotData= (WDPlot_t *)data;
	int i, s=0, ntr, comma=0, c, npts=0, WaitTime;
	FILE *fplot;

	SetPlotOptions(plotData);
	fplot = fopen(PLOT_DATA_FILE, "w");
	if (fplot == NULL) {
		retVal= -1;
		goto exitPoint;
	}
	ntr = plotData->NumTraces;
	while(ntr > 0) {
		fprintf(fplot, "%d\t", s);
		for(i=0; i<plotData->NumTraces; i++) {
			if (s < plotData->TraceSize[i]) {
				fprintf(fplot, "%d\t", plotData->TraceData[i][s]);
				npts++;
			}
			if (plotData->TraceSize[i] == (s-1))
				ntr--;
		}
		s++;
		fprintf(fplot, "\n");
	}
	fclose(fplot);

	/* str contains the plot command for gnuplot */
	fprintf(gnuplot, "plot ");
	c = 2; /* first column of data */
	for(i=0; i<plotData->NumTraces; i++) {
		if (comma)
			fprintf(gnuplot, ", ");
		fprintf(gnuplot, "'%s' using ($1*%f):($%d*%f) title 'ch%d' with lines %d", PLOT_DATA_FILE, plotData->Xscale, c++, plotData->Yscale, i, i+1);
		comma = 1;
	}
	fprintf(gnuplot, "\n"); 
	fflush(gnuplot);

	/* wait for gnuplot to finish */
	// TODO verificare documentazione gnuPlot per vedere se c'è modo di capire quando gnuPlot ha finito
	WaitTime = npts/100;
	if (WaitTime < 100)
		WaitTime = 100;
	Sleep(WaitTime);

exitPoint:
	// Free the traces storage
	for(i=0; i<plotData->NumTraces; i++)
		free( plotData->TraceData[i]);
	plotData->NumTraces= 0;
	_endthreadex( retVal );
    return retVal;
}
Exemplo n.º 2
0
Arquivo: WDplot.c Projeto: bianle/daq
void *PlotThread(void* data)
#endif
{
	volatile WDPlot_t *plotData= (volatile WDPlot_t *)data;
	while( !plotData->Exit) {
		int i, s=0, ntr, comma=0, c, npts=0, WaitTime;
		FILE *fplot;
		while( !plotData->DataReady) {
			if( plotData->Exit) {
				goto exitPoint;
			}
			Sleep( 10);
		}
		plotData->DataReady= 0;

		SetPlotOptions(plotData);
		fplot = fopen(PLOT_DATA_FILE, "w");
		if (fplot == NULL) {
			goto exitPoint;
		}
		ntr = plotData->NumTraces;
		while(ntr > 0) {
			fprintf(fplot, "%d\t", s);
			for(i=0; i<plotData->NumTraces; i++) {
				if (s < plotData->TraceSize[i]) {
					fprintf(fplot, "%d\t", plotData->TraceData[i][s]);
					npts++;
				}
				if (plotData->TraceSize[i] == (s-1))
					ntr--;
			}
			s++;
			fprintf(fplot, "\n");
		}
		fclose(fplot);

		/* str contains the plot command for gnuplot */
		fprintf(gnuplot, "plot ");
		c = 2; /* first column of data */
		for(i=0; i<plotData->NumTraces; i++) {
			if (comma)
				fprintf(gnuplot, ", ");
			fprintf(gnuplot, "'%s' using ($1*%f):($%d*%f) title '%s' with lines %d ", PLOT_DATA_FILE, plotData->Xscale, c++, plotData->Yscale, plotData->TraceName[i], i+1);
			comma = 1;
		}
		fprintf(gnuplot, "\n"); 
		fflush(gnuplot);

		/* wait for gnuplot to finish */
		WaitTime = npts/100;
		if (WaitTime < 100)
			WaitTime = 100;
		Sleep(WaitTime);

	exitPoint:
		// Free the traces storage
		for(i=0; i<plotData->NumTraces; i++)
			free( plotData->TraceData[i]);
		plotData->NumTraces= 0;
		plotData->Busy= 0;
	}
#ifdef WIN32
	_endthreadex( 0 );
    return 0;
#else
	return (void*)0;
#endif
}
Exemplo n.º 3
0
int PlotWaveforms(void)
{
	int i, s=0, ntr, comma=0, c, npts=0, WaitTime;
	FILE *fplot;

	Busy = 1;	
    if (SetOption)
	    SetPlotOptions();
	fplot = fopen(PLOT_DATA_FILE, "w");
    if (fplot == NULL) {
        Busy = 0;
		return -1;
    }

	ntr = PlotVar.NumTraces;
	while(ntr > 0) {
		fprintf(fplot, "%d\t", s);
		for(i=0; i<PlotVar.NumTraces; i++) {
			if (s < PlotVar.TraceSize[i]) {
                if (PlotVar.DataType == PLOT_DATA_UINT8) {
                    uint8_t *data = (uint8_t *)PlotVar.TraceData[i];
				    fprintf(fplot, "%d\t", data[s]);
                } else if (PlotVar.DataType == PLOT_DATA_UINT16) {
                    uint16_t *data = (uint16_t *)PlotVar.TraceData[i];
				    fprintf(fplot, "%d\t", data[s]);
                } else if (PlotVar.DataType == PLOT_DATA_UINT32) {
                    uint32_t *data = (uint32_t *)PlotVar.TraceData[i];
				    fprintf(fplot, "%d\t", data[s]);
                } else if (PlotVar.DataType == PLOT_DATA_DOUBLE) {
                    double *data = (double *)PlotVar.TraceData[i];
                    fprintf(fplot, "%f\t", data[s]);
               } else if (PlotVar.DataType == PLOT_DATA_FLOAT) {
                    float *data = (float *)PlotVar.TraceData[i];
                    fprintf(fplot, "%f\t", data[s]);
                }
				npts++;
			}
			if (PlotVar.TraceSize[i] == (s-1))
				ntr--;
		}
		s++;
		fprintf(fplot, "\n");
	}
	fclose(fplot);

	/* str contains the plot command for gnuplot */
	fprintf(gnuplot, "plot ");
	c = 2; /* first column of data */
	for(i=0; i<PlotVar.NumTraces; i++) {
		if (comma)
			fprintf(gnuplot, ", ");
		fprintf(gnuplot, "'%s' using ($1*%f):($%d*%f) title '%s' with step linecolor %d ", PLOT_DATA_FILE, PlotVar.Xscale, c++, PlotVar.Yscale, PlotVar.TraceName[i], i+1);
		comma = 1;
	}
	fprintf(gnuplot, "\n"); 
	fflush(gnuplot);

	/* set the time gnuplot will have finished */
	WaitTime = npts/20;
	if (WaitTime < 100)
		WaitTime = 100;
	Tfinish = get_time() + WaitTime;
	return 0;
}