📄 signal.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 : signal.c// Revision: 1.0 // Author : Edwin du // Date : 12/30/02 //// Description: Catch di interrupt signal of pci1762 card. // This is just an example for DI0 interrupt prompt,// you can also add your own interrupt handler.// //-------------------------------------------------------------------------#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>#include <signal.h>#include <sys/types.h>#define N_SAMPLE 2#define EVENT_IDI0 40#define EVENT_IDI1 41#define EVENT_DI0 42#define EVENT_DI1 43#define EVENT_IDI16 44#define EVENT_IDI17 45typedef unsigned short USHORT;typedef unsigned long ULONG;void DI0Handler(int signum);void DI1Handler(int signum);void IDI0Handler(int signum);void IDI1Handler(int signum);void IDI16Handler(int signum);void IDI17Handler(int signum);ULONG AddIntHandler(int Event, void *Handler); char *filename="/dev/comedi0";int verbose_flag;comedi_t *device;int channel =1;int range = 0;int subdev = 15; // PCI1730 FAKE DI deviceint main(void){ lsampl_t data[N_SAMPLE]; int save_errno; int ret,n_channels; comedi_insn insn; char nKey; pid_t sendpid[2]; // Step1. prompt case information: printf("************** signal.c****************\n"); printf("\n Comedi driver test program\n\n"); printf("****************************************\n"); // Step2. open device file device = comedi_open(filename); if(!device){ printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno)); return 1; } // Step3. clear buffer, fill in structures... memset(&insn,0,sizeof(insn)); memset(&data,0,sizeof(data)); n_channels = comedi_get_n_channels(device, subdev); insn.subdev = subdev; insn.insn = INSN_BITS; insn.n = N_SAMPLE; insn.data = data; // Step4. Tell the drvier of user case's pid, using comedi insn. sendpid[0] = getpid(); // get pid of itself data[0] = (lsampl_t)sendpid[0]; sendpid[1] = 2; // clear signal list on driver?? data[1] = 2; ret = comedi_do_insn(device,&insn); //write to device save_errno = errno; if(ret<0) { comedi_perror(filename); exit(0); } sendpid[1] = 1; // set pid to driver data[1] = 1; ret = comedi_do_insn(device,&insn); //write to device save_errno = errno; if(ret<0) { comedi_perror(filename); exit(0); } // Step5. Add Interrupt Handler AddIntHandler(EVENT_IDI0, IDI0Handler); AddIntHandler(EVENT_IDI1, IDI1Handler); AddIntHandler(EVENT_DI0, DI0Handler); AddIntHandler(EVENT_DI1, DI1Handler); AddIntHandler(EVENT_IDI16, IDI16Handler); AddIntHandler(EVENT_IDI17, IDI17Handler); // Step6. exit while pressing any key printf("\nInput single into IDI0,IDI1,IDI16,IDI17,DI0,DI1, let the system generates interrupt !!!"); printf("\nPress any 'q' to exit....\n"); while(1) { nKey = getchar(); if(nKey == 'q') break; } // Step6. Close device comedi_close(device); printf("complete input!\n"); return 1;}// Add a Event handler to the driver// Arguments:// Event: which event to be handled// it could be: EVENT_DI0// EVENT_DI8// Handler: the handler interface// it's format is: void Handler(int Event);//ULONG AddIntHandler(int Event, void *Handler){ struct sigaction new_action; new_action.sa_handler = Handler; sigemptyset(&new_action.sa_mask); new_action.sa_flags = 0; sigaction(Event, &new_action, NULL); return 0;}// IDI0 interrupt handlervoid IDI0Handler(int signum){ printf("Get IDI0 interrupt!\n");}void IDI1Handler(int signum){ printf("Get IDI1 interrupt!\n");}void DI0Handler(int signum){ printf("Get DI0 interrupt!\n");}void DI1Handler(int signum){ printf("Get DI1 interrupt!\n");}void IDI16Handler(int signum){ printf("Get IDI16 interrupt!\n");}void IDI17Handler(int signum){ printf("Get IDI17 interrupt!\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -