Problems while writing comedi - data to disk

Hello _at_ ALL!

I've got a little problem during the DAQ-process. My programm take samples of
two differnt (a)channels, averanges them (e.g. im taking samples with 4kHz and
averang them every 10 secons) the program (normaly) writes them directly to
disk. It is planned to do a continous acquisition but my program is writing the
data to disk after beeing stopped by /*cmd->stop_src = TRIG_COUNT;*/. So im am
not able to view the data during the whole progres. Breaking the program will
condemn the data.
What should I do? Has anybody an idea?

Thanks.

Mirko

//main
int main(int argc, char *argv[])
{
	//Mittelwertbildung aller X sekunden :
	int sec = 10; // anzahl der Sekunden
	FILE *fout=fopen("2_k_s.txt","w");
	//FILE *kanal_out=fopen("2_k_s_kanal.txt","w");
	comedi_t *dev;
	comedi_cmd c,*cmd=&c;
	int ret;
	int total=0;
	int i;
	struct timeval start,end;

	double kanal [n_chan] [240000];
	for (int c = 0; c < n_chan; c++)
	{
		for (int d = 0; d < 239999; d++)
		{
			kanal[c][d]=0.0;
		}
	}


	parse_options(argc,argv);

	dev = comedi_open(filename);
	if(!dev){
		comedi_perror(filename);
		exit(1);
	}

	for(i=0;i<n_chan;i++){
		chanlist[i]=CR_PACK(channel+i,range,aref);
	}

	prepare_cmd(dev,subdevice,cmd);

	fprintf(stderr,"command before testing:\n");
	dump_cmd(stderr,cmd);

	ret = comedi_command_test(dev,cmd);
	if(ret<0){
		comedi_perror("comedi_command_test");
		if(errno==EIO){
			fprintf(stderr,"Ummm... this subdevice doesn't support commands\n");
		}
		exit(1);
	}
	//fprintf(stderr,"first test returned %d (%s)\n",ret,
			//cmdtest_messages[ret]);
	dump_cmd(stderr,cmd);

	ret = comedi_command_test(dev,cmd);
	if(ret<0){
		comedi_perror("comedi_command_test");
		exit(1);
	}
	//fprintf(stderr,"second test returned %d (%s)\n",ret,
			//cmdtest_messages[ret]);
	if(ret!=0){
		dump_cmd(stderr,cmd);
		fprintf(stderr,"Error preparing command\n");
		exit(1);
	}

	gettimeofday(&start,NULL);
	//fprintf(stderr,"start time: %ld.%06ld\n",start.tv_sec,start.tv_usec);

		ret=comedi_command(dev,cmd);
	if(ret<0){
		comedi_perror("comedi_command");
		exit(1);
	}
	int m = 0;
	int z = 0;
	int n = 0;
	double mittelwert[n_chan];
	fprintf(fout,"Mittelwert Nr.  Kanal 0  	Kanal 1 \n");
	printf("\n\nMittelwert Nr.  Kanal 0  	Kanal 1 \n\n");
	//fprintf(kanal_out,"%10d",z);
	while(1){
		ret=read(comedi_fileno(dev),buf,BUFSZ);
		if(ret<0){
			/* some error occurred */
			perror("read");
			break;
		}else if(ret==0){
			/* reached stop condition */
			break;
		}else{
			static int col = 0;
			total+=ret;
			if(verbose)fprintf(stderr,"read %d %d\n",ret,total);
			for(i=0;i<ret/2;i++)
			{

				kanal[col][z] = ((sampl_t *)buf)[i];
				kanal[col][z] = ((kanal[col][z]-2048.0)/ 204.8);
				mittelwert[col] = mittelwert[col] + kanal[col][z];
				//fprintf(kanal_out, "\t%8.6f",kanal[col][z]);
				col++;
				if(col==n_chan)
				{
				//	fprintf(kanal_out, "\n%10d",z+1);
					col=0;

					z= z + 1;
					if (z > freq*sec-2)
					{
						m = m+1;
						fprintf(fout,"%12d",m);
					
fprintf(fout,"\t%8.6f\t%8.6f\n",(mittelwert[0]/(freq*sec)),(mittelwert[1]/freq*sec));

						mittelwert[0] = 0.0;
						mittelwert[1] = 0.0;
						z = 0;
					}
				}

			}
		}
	}

	gettimeofday(&end,NULL);
	fprintf(stderr,"end time: %ld.%06ld\n",end.tv_sec,end.tv_usec);

	end.tv_sec-=start.tv_sec;
	if(end.tv_usec<start.tv_usec){
		end.tv_sec--;
		end.tv_usec+=1000000;
	}
	end.tv_usec-=start.tv_usec;
	fprintf(stderr,"time: %ld.%06ld\n",end.tv_sec,end.tv_usec);

	return 0;
}

Received on 2003-08-18Z13:23:33