⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ailoop_cmd.c

📁 安装comedi板卡驱动之后的测试程序
💻 C
字号:
//************************************************************************//			//	         Copyright (c) 2001 IAG Software Team, ////		           Beijing R&D Center //	//		           Advantech Co., Ltd.////	      User program for Linux comedi device driver//// This is An Unpublished Work Containing Confidential  And Proprietary//    Information Which Is The Property Of Advantech  Automation Corp.//// Any Disclosure, Use, Or Reproduction, Without Written Authorization From//           Advantech Automation Corp., Is Strictly Prohibit.//////*************************************************************************// Program :    ailoop_cmd.c// Revision:    1.0                                        // Author  :    jingang, Edwin                                             // Date    :    09/20/01                                              //// Description:  Perform analog input of comedi driver with cmd mode.                             //                                                  //-------------------------------------------------------------------------#include <stdio.h>#include <stdlib.h>#include <comedilib.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <getopt.h>#include <ctype.h>#include <string.h>#define N_SCANS		10	#define N_CHANS		16//#define REQUEST  (1024*120)//#define REQUEST  (4096*30) //(1024*20)unsigned long REQUEST;char *filename="/dev/comedi0";int subdevice = 0;int chan=0;int range = 0;int aref = AREF_GROUND;int n_chan = 1;double freq = 1000;#define BUFSZ 2048char buf[BUFSZ];sampl_t capdata[100];unsigned int chanlist[N_CHANS];void prepare_cmd_1(comedi_t *dev,comedi_cmd *cmd);void do_cmd(comedi_t *dev,comedi_cmd *cmd);void dump_cmd(comedi_cmd *cmd);int main(int argc, char *argv[]){	comedi_t *dev;	comedi_cmd cmd;	int i;		printf("************** ailoop_cmd.c****************\n");        printf("\n     Comedi driver test program\n\n");        printf("****************************************\n");	if(argc ==3)		REQUEST=atoi(argv[1])*atoi(argv[2]);	else		REQUEST=1024*100;	dev = comedi_open(filename);	if(!dev){		perror(filename);		exit(1);	}	for(i=0; i<100; i++)		capdata[i] = 0;		prepare_cmd_1(dev,&cmd);	do_cmd(dev,&cmd);		comedi_cancel(dev,subdevice);
	comedi_close(dev);	return 0;}void do_cmd(comedi_t *dev,comedi_cmd *cmd){	comedi_range *srange[N_CHANS];	lsampl_t maxdata[N_CHANS];	unsigned long total=0;	int ret, i;	int go;	ret=comedi_command(dev,cmd);		if(ret<0){		printf("errno=%d\n",errno);		comedi_perror("comedi_command");		printf("has error\n");		exit(0);	}		for(i=0; i<n_chan; i++) {		srange[i] = comedi_get_range(dev, subdevice, CR_CHAN(chanlist[i]), range);		maxdata[i] = comedi_get_maxdata(dev, subdevice, i);	}	for(i=0; i<n_chan; i++)                printf("Chan %2d\t\t\t|\t", CR_CHAN(chanlist[i]));	printf("\n");        for(i=0; i<n_chan; i++)	        printf("Raw data  Physical value|\t ");        printf("\n");	go=1;	while(go && total<REQUEST){		ret=read(comedi_fileno(dev),buf,BUFSZ);		if(ret<0){			printf("ret <0\n");			go = 0;			perror("read");		}else if(ret==0){			printf("ret==0\n");			go = 0;		}else{			total+=ret;		}	}	for(i=0;i<10;i++){			printf("0x%x\t\t",((sampl_t *)buf)[i]&0x0fff);			printf("%f |\n ",(comedi_to_phys((float)(((sampl_t *)buf)[i]&0x0fff), srange[0], maxdata[0])));	}	printf("\n");}/* * This part of the demo measures channels 1, 2, 3, 4 at a rate of * 10 khz, with the inter-sample time at 10 us (100 khz).  The number * of scans measured is 10.  This is analogous to the old mode2 * acquisition. */void prepare_cmd_1(comedi_t *dev,comedi_cmd *cmd){	memset(cmd,0,sizeof(cmd));	/* the subdevice that the command is sent to */	cmd->subdev =	subdevice;	/* flags */	cmd->flags =	TRIG_WAKE_EOS;	//cmd.flags =	0;	/* each event requires a trigger, which is specified	   by a source and an argument.  For example, to specify	   an external digital line 3 as a source, you would use	   src=TRIG_EXT and arg=3. */	/* In this case, we specify using TRIG_NOW to start	 * acquisition immediately when the command is issued.  	 * The argument of TRIG_NOW is "number of nsec after	 * NOW", but no driver supports it yet.  Also, no driver	 * currently supports using a start_src other than	 * TRIG_NOW.  */	cmd->start_src =		TRIG_NOW;	cmd->start_arg =		0;	/*The scan_begin_arg is the acquisition mode of the A/D or in D/A.	 *when in A/D function:	 *1=the pacer mode	 *2=the post Trigger Acquistion mode	 *3=the delay Trigger mode	 *4=the about Trigger mode  	 *when in D/A function	 *1= ch0 continuous output mode,ch1 single value mode.	 *2= ch1 continuous output mode,ch0 single value mode.	 *3= ch0 and ch1 both continuous output.		  */	cmd->scan_begin_src =	TRIG_FOLLOW;	cmd->scan_begin_arg =	0;	/* The timing between each sample in a scan is controlled	 * by convert.  Like above, TRIG_TIMER specifies that	 * convert events occur periodically at a rate of convert_arg	 * nanoseconds between scans. */	cmd->convert_src =	TRIG_TIMER;	cmd->convert_arg =	10000;	/* The end of each scan is almost always specified using	 * TRIG_COUNT, with the argument being the same as the	 * number of channels in the chanlist.  You could probably	 * find a device that allows something else, but it would	 * be strange. */	cmd->scan_end_src =	TRIG_COUNT;	cmd->scan_end_arg =	n_chan;		/* number of channels */	/* The end of acquisition is controlled by stop_src and	 * stop_arg.  The src will typically be TRIG_COUNT or	 * TRIG_NONE.  Specifying TRIG_COUNT will stop acquisition	 * after stop_arg number of scans, or TRIG_NONE will	 * cause acquisition to continue until stopped using	 * comedi_cancel(). */	cmd->stop_src =		TRIG_NONE;//TRIG_TIME;	cmd->stop_arg =		0;	/* the channel list determined which channels are sampled.	   In general, chanlist_len is the same as scan_end_arg.  Most	   boards require this.  */	cmd->chanlist =		chanlist;	cmd->chanlist_len =	n_chan;		cmd->data = capdata;	cmd->data_len = sizeof(capdata)/2;//100*sizeof(sampl_t);			chanlist[0]=CR_PACK(chan+0,range,aref);	chanlist[1]=CR_PACK(chan+1,range,aref);	chanlist[2]=CR_PACK(chan+2,range,aref);	chanlist[3]=CR_PACK(chan+3,range,aref);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -