#include #include #include #include #include #include #include #include #define STIME 3000000 void SetRTS(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); currstat |= TIOCM_RTS; ioctl(fd, TIOCMSET, &currstat); } void ResetRTS(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); currstat &= ~TIOCM_RTS; ioctl(fd, TIOCMSET, &currstat); } void SetDTR(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); currstat |= TIOCM_DTR; ioctl(fd, TIOCMSET, &currstat); } void ResetDTR(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); currstat &= ~TIOCM_DTR; ioctl(fd, TIOCMSET, &currstat); } void ClearSerPins(int fd) { int currstat = 0; ioctl(fd, TIOCMSET, &currstat); } int GetRI(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); return((currstat & TIOCM_RNG)?1:0); } int GetCD(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); return((currstat & TIOCM_CAR)?1:0); } int GetDSR(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); return((currstat & TIOCM_DSR)?1:0); } int GetCTS(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); return((currstat & TIOCM_CTS)?1:0); } int GetSerStat(int fd) { int currstat; ioctl(fd, TIOCMGET, &currstat); return(currstat); } int main (int argc, char** argv) { int i, stat; int fd = 0; if ( argc != 2 ) { printf("usage: %s device\n",argv[0]); exit(1); } if (( fd = open(argv[1], O_RDWR | O_NDELAY )) < 0 ) { printf("can't open device '%s'\n",argv[1]); exit(2); } SetRTS(fd); stat = GetSerStat(fd); if ( stat & TIOCM_DSR) puts("DSR "); printf("\n"); /* debug for (;;) { usleep(100000); stat = GetSerStat(fd); if ( stat & TIOCM_RNG) puts("RI "); if ( stat & TIOCM_CAR) puts("CAR "); if ( stat & TIOCM_DSR) puts("DSR "); if ( stat & TIOCM_CTS) puts("CTS "); printf("\n"); } */ close(fd); return(0); }