📄 readcp.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 : readcp.c// Revision: 1.0 // Author : Edwin // Date : 3/15/03 //// Description: read the counter compare register.// the objective subdevice would be the subdevice 7.// //-------------------------------------------------------------------------#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 2 char *filename="/dev/comedi0";int verbose_flag;comedi_t *device;int channel =1;int range = 0;int subdev = 7;int main(void){ lsampl_t data[N_SAMPLE]; int save_errno, ret; long compare; int UserInput; comedi_insn insn; printf("************** readcp.c****************\n"); printf("\n Comedi driver test program\n\n"); printf("****************************************\n"); // Acquire counter channel while (1) { printf("Counter channel: (0--3)\t"); 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"); } } device = comedi_open(filename); if(!device){ printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno)); return 1; } memset(&insn,0,sizeof(insn)); insn.subdev = subdev; insn.insn = INSN_READ; insn.n = N_SAMPLE; insn.data = data; 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); } compare = data[0]; printf("Counter %d compare value:%ld\n", channel, compare); comedi_close(device); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -