Written by Dana Kirsch and Solomon Assefa #include #include #include #include #include #include #include #include #include #include #include #include int OpenPort() { struct termios t; int fd= open("/dev/cua1", O_RDWR); if (fd < 0) { perror("opening com1 port"); } else { tcgetattr(fd, &t); cfsetispeed(&t, B2400); cfsetospeed(&t, B2400); cfmakeraw(&t); tcsetattr(fd, TCSANOW, &t); } return(fd); } void main(int argc, char *argv[]) { int port; int out; port = OpenPort(); switch (argc) { case 1: perror("You need to put an argument"); break; case 2: out = atoi(argv[1]); if ((2 <= out) && (out < 10)) { /* 0 and VALUES 2 through 9 ONLY VALID !!!! */ write(port, &out, 1); printf(" %d \n", out); break; } perror("not valid, try again"); break; default: perror("You have too many arguments"); } }