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

📄 do_indicated.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 :    do_indicated.c// Revision:    1.0                                        // Author  :    Edwin                                             // Date    :    04/28/03                                              //// Description:  Perform analog input 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 2char *filename="/dev/comedi0";int verbose_flag;comedi_t *device;int channel =1;int range = 0;int subdev = 3;int main(void){        lsampl_t data[N_SAMPLE];        int save_errno;        int ret,n_channels;	int UserInput, dm, le, uc, oc,Reg=0;	comedi_insn insn;		printf("************** do_indicated.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, subdev);	insn.subdev = subdev;        insn.insn = INSN_WRITE;        insn.n = N_SAMPLE;        insn.data = data;	// Get do channel	while (1)	  {	    printf("please select channel(0--3):\n");	    if ((UserInput = getchar()) != '\n')	      while(!getchar());      // read '\n'	    if (UserInput >= 0x30 && UserInput <=0x33)	      {		channel = UserInput - '0';		break;	      }else{		printf("\nInvalid Channel, please reinput!\n\n");	      }	  }        // Confirm overcompare output	printf("\nEnable counter overcompare do?(y/N)\n");	if ((UserInput = getchar()) != '\n')	  while(!getchar());      // read '\n'	if (UserInput == 'Y' || UserInput == 'y')	  {	    oc = 1;	    Reg |= oc << channel;	  }else{	    oc = 0;	  }        // Confirm undercompare output        printf("\nEnable counter undercompare do?(y/N)\n");        if ((UserInput = getchar()) != '\n')          while(!getchar());      // read '\n'        if (UserInput == 'Y' || UserInput == 'y')          {            uc = 1;	    Reg |= (uc << channel) << 4;          }else {            uc = 0;          }        // DO level control	while(1)	  {	    printf("\ndo level control:\n");	    printf("1. Pulse with counter clock.\n2. Level with clear interrupt.\n");	    if ((UserInput = getchar()) != '\n')	      while(!getchar());	    if (UserInput > 0x30 && UserInput < 0x33)	      {		switch (UserInput)		  {		  case 0x31:		    le = 1;		    break;		  case 0x32:		    le = 2;		    Reg |= (1 << channel)<<8;		    break;		  default:		    break;		  }		break;	      }else{		printf("\nINVALID SELECTION, PLEASE RESELECT!\n\n");	      }	  }        // DO mode control	while(1)	  {	    printf("\ndo mode control:\n");	    printf("1. Normal.\n2. Indicated.\n");	    if ((UserInput = getchar()) != '\n')	      while(!getchar());	    if (UserInput > 0x30 && UserInput < 0x33)	      {                switch (UserInput)		  {		  case 0x31:		    dm = 1;		    break;		  case 0x32:		    dm = 2;		    Reg |= (1 << channel)<<12;		    break;		  default:		    break;		  }		break;	      }else{                printf("\nINVALID SELECTION, PLEASE RESELECT!\n\n");	      }	  }	data[1] = 0xffff0000;	data[0] = Reg << 16;	  	ret = comedi_do_insn(device,&insn);     //sample data	save_errno = errno;	if(ret<0){	  comedi_perror(filename);	  exit(0);	}		printf("Execute counter.c to continue! \n");	printf("By default, counter is set as 2 pulse input, software latch mode on channel 0.\n");	printf("Do you wish to continue? (Y/n)");        if ((UserInput = getchar()) != '\n')           while(!getchar());      // read '\n'        if (UserInput == 'N' || UserInput == 'n')        {        	exit(0);	}	data[0] = 0x104;	data[1] = 0;	insn.subdev = 6;		// counter sub device	insn.chanspec = CR_PACK(0, range, 0);	insn.data = data;	ret = comedi_do_insn(device, &insn);	save_errno = errno;	if(ret<0)	{	comedi_perror(filename);		exit(0);	}	printf("Counter 0 executing...done.\n");	comedi_close(device);		return 1;}

⌨️ 快捷键说明

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