Date: Fri, 25 Feb 2000 16:41:03 -0800 From: "Ptacek" <ptacek@dashmail.net> To: <freebsd-hackers@FreeBSD.ORG>, <freebsd-questions@FreeBSD.ORG> Subject: Re: modem program... Help continued... Message-ID: <01e301bf7ff2$2aa60600$0301a8c0@Ptacek> References: <Pine.BSF.4.21.0002241741310.17368-100000@boris.netgate.net> <200002252012.VAA04133@saturn.kn-bremen.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Well thanks to some examples I seem to have access to the modem signals. Unfortunately when I drop the DTR nothing happens. I have played with setting the &Dn and other values but nothing seems to work. Also it seems that the carrier detect signal is always high, even after a NO CARRIER. I have also tried clearing the CLOCAL flag to see if I get a signal (HUP), but I am not getting one. I have also tried to get the HUP signal by using the +++<delay>ATH<CR> command with no success. Currently I have a test program that I will include below, and it is dialing my other PC (hyperterminal) just to see if I can get the connection to work. If I am missing something please let me know. Maybe I just have a bad modem, I will try to look for a different one (it is internal, but that shouldn't matter, should it?) ; - Chris #include <stdio.h> #include <sys/ioctl.h> #include <stdlib.h> #include <termios.h> #include <fcntl.h> int serial_open( char *device, int baudrate, struct termios *old_tty ) ; int read_modem_resp(int sdev, char *buf, int max_len, int to ) ; int debug_lvl = 1; int main() { int dev1 ; int baudr = 9600 ; time_t tcur, tstart ; int iocval, csta, ctmp ; char out_buf[32] ; char mdm_str[] = "ATE0V1X4&C1&D0&Q1S0=0S2=43S7=45\r" ; char in_buf[128] ; int rlen ; struct termios oldtty1; struct termios oldtty2; /* use the device names for the serial connection, /dev/cuaa0 for serial port A * /dev/cuaa1 for serial port B (or whichever you are using) */ /* internal modem, port 4 (cuaa3) */ dev1 = serial_open("/dev/cuaa3", baudr, &oldtty1) ; if( dev1 == -1 ) { fprintf(stderr,"Failed to open dev1\n") ; exit(-1) ; } sprintf(out_buf,"AT\r") ; write(dev1, "ATZ\r", 4) ; if((rlen = read_modem_resp(dev1, in_buf, 128, 2 )) >= 0) { in_buf[rlen] = '\0' ; printf("READ:%s \n", in_buf ) ; fflush(stdout) ; } write(dev1, "ATE0\r", 5) ; write(dev1, mdm_str, strlen(mdm_str) ) ; write(dev1, out_buf, strlen(out_buf) ) ; if((rlen = read_modem_resp(dev1, in_buf, 128, 2 )) >= 0) { in_buf[rlen] = '\0' ; printf("READ:%s \n", in_buf ) ; fflush(stdout) ; } if((iocval=ioctl(dev1, TIOCMGET, &csta)) == -1) { printf("Couldn't read serial port info\n") ; } else { printf("Modem control lines (Register contents=0x%x)\n", csta) ; printf(" Carrier %spresent\n", (csta & TIOCM_CAR) ? "" : "not "); printf(" DTR line is %sactive\n", (csta & TIOCM_DTR) ? "" : "not "); printf(" DSR line is %sactive\n", (csta & TIOCM_DSR) ? "" : "not "); printf(" CTS line is %sactive\n", (csta & TIOCM_CTS) ? "" : "not "); printf(" RTS line is %sactive\n", (csta & TIOCM_RTS) ? "" : "not "); } sleep(2) ; write(dev1, "ATDT6176828\r", 12) ; printf("\nReading...\n") ; /* this is non-blocking so just loop */ tstart = time(NULL) ; tcur = tstart ; while( (tcur-tstart) < 80 ) { if((iocval=ioctl(dev1, TIOCMGET, &csta)) == -1) { printf("Couldn't read serial port info\n") ; } else { printf("Modem control lines (Register contents=0x%x)\n", csta) ; printf(" Carrier %spresent\n", (csta & TIOCM_CAR) ? "" : "not "); printf(" DTR line is %sactive\n", (csta & TIOCM_DTR) ? "" : "not "); printf(" DSR line is %sactive\n", (csta & TIOCM_DSR) ? "" : "not "); printf(" CTS line is %sactive\n", (csta & TIOCM_CTS) ? "" : "not "); printf(" RTS line is %sactive\n", (csta & TIOCM_RTS) ? "" : "not "); } tcur = time(NULL) ; if((rlen = read_modem_resp(dev1, in_buf, 128, 2 )) >= 0) { in_buf[rlen] = '\0' ; printf("READ:%s \n", in_buf ) ; fflush(stdout) ; } } /* write(dev1, "+++", 3) ; sleep(3) ; write(dev1, "ATH\r", 4) ; */ sleep(3) ; if((iocval=ioctl(dev1, TIOCMGET, &csta)) == -1) { printf("Couldn't read serial port info\n") ; } else { ctmp = csta ; ctmp &= ~TIOCM_DTR ; if((iocval=ioctl(dev1, TIOCMSET, &ctmp)) == -1) { printf("Couldn't set serial port info\n") ; } } tstart = time(NULL) ; tcur = tstart ; while( (tcur-tstart) < 20 ) { if((iocval=ioctl(dev1, TIOCMGET, &csta)) == -1) { printf("Couldn't read serial port info\n") ; } else { printf("Modem control lines (Register contents=0x%x)\n", csta) ; printf(" Carrier %spresent\n", (csta & TIOCM_CAR) ? "" : "not "); printf(" DTR line is %sactive\n", (csta & TIOCM_DTR) ? "" : "not "); printf(" DSR line is %sactive\n", (csta & TIOCM_DSR) ? "" : "not "); printf(" CTS line is %sactive\n", (csta & TIOCM_CTS) ? "" : "not "); printf(" RTS line is %sactive\n", (csta & TIOCM_RTS) ? "" : "not "); } tcur = time(NULL) ; if((rlen = read_modem_resp(dev1, in_buf, 128, 2 )) >= 0) { in_buf[rlen] = '\0' ; printf("READ:%s \n", in_buf ) ; fflush(stdout) ; } } exit(0) ; } /*----------------------- serial_open() --------------------------- * * Def: This function is the function that is used to open the * serial port used to communicate to the site. The old_tty * will be used to restore the original port settings when * the port is closed. * * Ret: handle to the device. * * Rev: * 1999/09/09 CP * *----------------------------------------------------------------- */ int serial_open( char *device, int baudrate, struct termios *old_tty ) { int tfd ; int flags ; struct termios tty ; if(debug_lvl >= 1) { fprintf(stderr,"OPEN: %s at %d\n", device, baudrate) ; } /* Open serial port for input */ /*tfd = open( device, O_RDWR | O_NOCTTY | O_NDELAY ) ;*/ tfd = open( device, O_RDWR | O_NDELAY ) ; if( tfd == -1 ) { perror("open_port") ; return(-1) ; } /* save old configuration */ if( tcgetattr( tfd, old_tty) < 0 ) { perror("tcgetattr") ; return(-1) ; } /* Configure device */ tty.c_iflag = 0 ; tty.c_oflag = 0 ; tty.c_lflag = 0 ; /*tty.c_cflag = (CS8 | CREAD) ; */ tty.c_cflag = (CS8 | CLOCAL | CREAD) ; tty.c_cc[VTIME] = 0 ; tty.c_cc[VMIN] = 0 ; /* set the speed */ cfsetispeed(&tty, baudrate) ; cfsetospeed(&tty, baudrate) ; printf( "in: %d Out: %d \n", tty.c_ispeed, tty.c_ospeed ) ; /* write out the settings */ if( tcsetattr(tfd, TCSANOW, &tty) < 0 ) { perror("tcsetattr") ; return(-1) ; } flags = fcntl(tfd, F_GETFL, 0) ; fcntl(tfd, F_SETFL, flags | FNDELAY) ; return(tfd) ; } int read_modem_resp(int sdev, char *buf, int max_len, int tmout ) { int i = 0 ; int tlen ; time_t tstart = time(NULL) ; time_t tcur ; do tlen = read(sdev, &buf[i], 1) ; if( tlen > 0) { if( buf[i] == '\r' ) { return(i) ; } i++ ; if( i >= max_len ) { return(i) ; } } tcur = time(NULL) ; }while( (tcur-tstart) < tmout ) ; return(i) ; } ----- Original Message ----- From: Juergen Lock <nox@jelal.kn-bremen.de> To: <ptacek@dashmail.net> Cc: <freebsd-hackers@FreeBSD.ORG>; <freebsd-questions@FreeBSD.ORG> Sent: Friday, February 25, 2000 12:12 PM Subject: Re: modem program... Help > (hmm a crosspost to -hackers and -questions, is that good?) > > In article <015201bf7f4d$ac963e00$0301a8c0@Ptacek> you write: > >Thanks to all that replied... I have the +++ <2sec. delay>ATH<CR> working. > > > >I guess my only question now is how do I access the DTR, CD, etc signals > >from my code. Is there an example somewhere? I have looked through the > >termios man file but couldn't find anything? > > Well the normal `unix' way to watch for CD is to turn off CLOCAL, > then you'll get a SIGHUP when the modem loses its connection. > (thats where that signal's name comes from, hangup. people have > dialed into unix boxes over modems long before the internet got > popular...) and to drop DTR you just do the equivalent of a `stty 0'. > > simple, eh? :) (once you know it...) > > HTH, > -- > Juergen Lock <nox.foo@jelal.kn-bremen.de> > (remove dot foo from address to reply) > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01e301bf7ff2$2aa60600$0301a8c0>