www.pudn.com > vxworks_networking.rar > nonBlockReadDemo.c
/* nonBlockReadDemo.c - This is an example of doing a nonBlocking read on a port in raw mode*/ /* modification history -------------------- 01a,23dec99,cmf written. */ /* DESCRIPTION: This library is provided by Wind River Systems Customer Support strictly as an educational example. It is unsupported and provided as-is. This is an example of doing a nonBlocking read on a port in raw mode. The first read blocks and waits for a character. It then checks to see if additional characters have been sent as a result of pressing a special key such as <- (left arrow) If so, a special case is invoked to handle this (printf in this case) What to do with the data is left up to the customer. */ /* includes */ #include#include #include #include #include #include #include #include /* defines */ #define DELAY_BETWEEN_WRITES 100 #define DELAY_BETWEEN_READS 10 #define NUMBER_OF_WRITES 15 #define NUMBER_OF_READS 25 /*globals*/ int fd1, fd2=0; SEM_ID syncSem; /* standard string should be about */ #define READ_BUFFER_SIZE 4 void readPort () { int j, bytesRecvd, bytesRead=0; char * tPtr; char * inputString; char inputChar; inputString = (char *) malloc(READ_BUFFER_SIZE); /* clear inputString */ tPtr = inputString; for (j=0; j < READ_BUFFER_SIZE ;j++) { *tPtr = '\0'; tPtr++; } /* block waiting for input one character - standard string should * one charachter. READ_BUFFER_SIZE allocated in case of special * characters */ bytesRead = fioRdString (fd1,(char *) inputString,1); taskDelay(10); /* do any string processing here */ if (*inputString == 0x1b) { /* check if more than one char was sent */ ioctl(fd1, FIONREAD, &bytesRecvd); if (bytesRecvd == 0) printf("read: esc\n"); else { for (j=0;j