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

📄 ao_insn.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 :    ao_insn.c// Revision:    1.0                                        // Author  :    jingang                                             // Date    :    09/20/01                                              //// Description:  Perform analog output of comedi driver with insn mode.                             // 		 This program reads N_SAMPLES samples from an analog//		 input each time and return the time it's used.//                                                  //-------------------------------------------------------------------------#include <stdio.h>#include <stdlib.h>#include <comedilib.h>#include <fcntl.h>#include <unistd.h>#include <sys/ioctl.h>#include <errno.h>#include <getopt.h>#include <ctype.h>#include <math.h>#include <sys/time.h>#include <string.h>#define N_SAMPLE 256 char *filename="/dev/comedi0";int verbose_flag;comedi_t *device;int subdevice = 1;int channel = 3;int aref;int range = 0;int main(void){        lsampl_t data[N_SAMPLE];        int save_errno;        int ret, i, n_channels;	comedi_insn insn;	comedi_range *srange;	float v;	char inputchar[10], argument;		printf("************** ao_insn.c****************\n");        printf("\n     Comedi driver test program\n\n");        printf("****************************************\n");        device = comedi_open(filename);        if(!device){                printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno));		return 1;        }        memset(&insn,0,sizeof(insn));        n_channels = comedi_get_n_channels(device, subdevice);        	insn.subdev = 1;        insn.insn = INSN_WRITE;        insn.n = N_SAMPLE;//        insn.chanspec = CR_PACK(channel, range, 0);        insn.data = data;	while(1) {		printf("subdevice: %d\n", subdevice);				while(1) {			printf("Please key in the Channel number:");			scanf("%s",inputchar);			channel = atoi(inputchar);			if(channel >= 0 && channel <= n_channels)				break;			printf("Bad channel number!\n");		}				while(1) {			srange = comedi_get_range(device, subdevice, channel, 0);			printf("Please key in the Voltage [%f, %f]:", srange->min, srange->max);			scanf("%s",inputchar);			v = atof(inputchar);			if(v >= srange->min && v <= srange->max) {				for(i=0; i<N_SAMPLE; i++)					data[i] = v/srange->max*4095;					break;			}			printf("Bad Voltage!\n");		}							insn.chanspec = CR_PACK(channel, range, 0);        	ret = comedi_do_insn(device, &insn);	//sample data		save_errno = errno;	        if(ret<0){	        	comedi_perror(filename);			exit(0);        	}   		         	printf("the voltage output!\n");                printf("Press 'Q' to quit,  press other key to continue...\n");                argument=getchar();                if(argument == 'Q' || argument == 'q')                	break;	}	return 1;}

⌨️ 快捷键说明

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