#include <string.h> // Check to be sure we need this #include <stdlib.h> // below are the includes for raw I/O #include <fcntl.h> #include <unistd.h> //#include "configsym.h" #define PORT "/dev/ttyS1" #include <stdio.h> //#include "curses.h" #include <stdlib.h> #include <fcntl.h> #include "termio.h" #include <string.h> #include <time.h> int portfd; struct termio newio,oldio; int SetPort() { if ( portfd < 0 ) return -1; if ( ioctl(portfd, TCGETA, &oldio) < 0 ) return -1; if ( ioctl(portfd, TCGETA, &newio) < 0 ) return -1; newio.c_cflag &= ~CBAUD; newio.c_cflag &= ~CSIZE; newio.c_cflag |= B115200; newio.c_cflag |= CS8; newio.c_cflag |= (CLOCAL | CREAD); newio.c_cflag &= ~(PARENB | CSTOPB);
newio.c_iflag &= ~( INLCR |ISTRIP |IXON |ICRNL |IGNCR | IGNPAR); newio.c_oflag &= ~OPOST; newio.c_lflag &= ~( ISIG |ECHO |ICANON | NOFLSH); newio.c_cc[VMIN] = 1; newio.c_cc[VTIME] = 0; newio.c_cc[VQUIT] = 0x7f;
if ( ioctl(portfd, TCSETAW, &newio) ) return -1; return 0; }
main() { int ch; static int n;
#if defined(O_NDELAY) && defined(F_SETFL) portfd = open(PORT, O_RDWR|O_NDELAY); if (portfd >= 0){ /* Cancel the O_NDELAY flag. */ n = fcntl(portfd, F_GETFL, 0); (void) fcntl(portfd, F_SETFL, n & ~O_NDELAY); } #else portfd = open(PORT, O_RDWR); #endif if (portfd >= 0) { printf("return value is %d",SetPort()); } n='0'; for(;;){ if (n>('0'+30)) n='\n'; printf("write %d characte:%c\n",write(portfd,&n,1),n); n++; } }
|