/***************************************************************** bike.c Univerisity of Massachusetts Senior Design Project 2004 *****************************************************************/ #include #include #include #include #include #include #include #include #define BAUDRATE B9600 #define MODEMDEVICE "/dev/ttyUSB0" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define BUFF_SIZE 1000 #define COUNT 5 int main(int argc, char **argv) { int mask = 255; int fd; int retval = 1; int i; char F = 'a'; struct termios oldtios, newtios; char *buf; char *inport; inport = malloc(6); buf = malloc(127); memset(inport, 0, 5); // open the serial port fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY); // get the old port settings tcgetattr(fd, &oldtios); // setup new port settings memset(&newtios, 0, sizeof(newtios)); newtios.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newtios.c_iflag = 0; // no input processing newtios.c_oflag = 0; // no output processing newtios.c_lflag = 0; newtios.c_cc[VTIME] = 0; // timer is not used newtios.c_cc[VMIN] = 0; // no blocking on read // flush and set parameters tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &newtios); //sync retval = write(fd, &F, 1); //main receiving loop while(retval > 0){ i=0; while(i<1) i = read(fd, &F, 1); retval = sprintf(buf, "%u\n", mask & (int)F); write(1, buf, retval); } tcsetattr(fd, TCSANOW, &oldtios); close(fd); return 0; }