You're here: Snippet Directory » C/C++ (495)
Language:

kbdcheck.c

Language: English
Programming Language: C
Published by: ike [not registered]
Last Update: 5/15/2006
Views: 153


Description

Matlab MEX file to check for pending keyboardinput. Runs under linux.

Code

1 /* 2 3 File: kbdcheck.c 4 Date: 31-Jan-00 5 Author: I. Chuang <ike@alum.mit.edu> 6 7 MEX file for matlab to check if there is pending input on stdin 8 9 $Id: kbdcheck.c,v 1.2 2000/02/25 06:17:32 ike Exp $ 10 11 $Log: kbdcheck.c,v $ 12 Revision 1.2 2000/02/25 06:17:32 ike 13 checkin 14 15 16 */ 17 18 #include <stdio.h> 19 #include <unistd.h> 20 #include <sys/stat.h> 21 #include <signal.h> 22 #include <sys/types.h> 23 #include <string.h> 24 #include <sys/wait.h> 25 #include <ctype.h> 26 #include <sys/time.h> 27 28 #include "mex.h" /**/ 29 30 int kbdcheck(int fd) 31 { 32 fd_set rfds; 33 struct timeval tv; 34 int retval; 35 36 FD_ZERO(&rfds); 37 FD_SET(fd,&rfds); 38 39 tv.tv_sec = 0; 40 tv.tv_usec = 10; 41 42 retval = select(fd+1,&rfds,NULL,NULL,&tv); 43 if (retval<0){ 44 return(-1); 45 perror("select"); 46 } 47 48 if(!retval) return(0); 49 50 if(FD_ISSET(fd,&rfds)){ /* data available from serial line */ 51 return(1); 52 } 53 54 return(0); 55 } 56 57 /*****************************************************************************/ 58 /* MAIN ENTRY POINT */ 59 60 void 61 mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) 62 { 63 double *p; 64 65 plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); 66 p = mxGetPr(plhs[0]); 67 p[0] = kbdcheck(fileno(stdin)); 68 } 69

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS