Article View: news.software.readers
Article #5245cnews posting
From: Francis Cheung
Date: Tue, 10 Aug 1993 23:33
Date: Tue, 10 Aug 1993 23:33
103 lines
3403 bytes
3403 bytes
Hi I am trying to write a device driver using C to access a 9600 baud modem
directly to connect to another site. This is the first time that I have
been given such an assignment so the company and I are quite unfamiliar
with the methode to access the modem. The initial step to this project
is to be able to access the modem by first receiving an OK, then dialing
a phone number, and then reading in prompts on the remote terminal.
Depending on what responses, the remote terminal returns, this part of the
device driver is supposed to send certain commands.
int portid;
char temp[5];
if((portid = open("/dev/ttyb", O_NOCTTY|O_RDWR))<0)
perror("cannot openserail port");
<stuff deleted>
/* serial control configuration */
if ((ioctl(portid,TCGETS, &port_struct))!=0)
return(-1);
port_struct.c_iflag=(IXON|IXOFF|ICRNL|INLCR);
port_struct.c_oflag=(OCRNL|ONLCR|ONLRET);
port_struct.c_cflag=(B2400|CS8|CREAD);
port_struct.c_lflag=(ECHO|ECHOK|ICANON);
if((ioctl(portid, TCSETSW, &port_struct))!=0)
return(-2);
if(write(portid, "atz\n",4)<=0)
return(-3); /*init modem*/
strcpy(temp,"");
while(!got_ok)
{
if((count=read(portid,temp,1))<0) /* read 1 byte from port */
return(-4);
else if(count==0)
printf("timeout\n");
else
{
if(strncmp(temp,"\n",1)!=0) /*if character store it*/
{
buf[Counter++]=temp[0];
}
}
if(strncmp(temp,"\n",1)==0)
{
if(strncmp(buf, "OK",2)==0) /*if got an ok from modem*/
{
got_ok=TRUE;
strcpy(buf,"");
}
else
{
strcpy(buf,"");
}
}
strcpy(temp,"");
}
-----------------------
<another function to dial the number after successfully receiving "ok">
write(portfd, "atdt 8938400\n",13);;
if ((count = read(portid, temp,1))<0)
return(-5);
else if(count==0)
printf("timeout in dialing\n");
else if(strncmp("CONNECT 2400", buf, 12)==0) #if got connect 2400 then
{ #stop loop
got_connect=TRUE;
Counter =0;
}
else if(strncmp("\n",temp,1)==0)
Counter=0;
else
buf[Counter++]=*temp;
}
. . .
When I insert printf statements to check the types of responses that
I am getting from the modem, sometimes I get what I have already read
from the port such as "ok" "atz" over and over again. This usually happens
the second time I read from the port. It seems to run in an infinite
loop but I am not continuously writing into the port.
Does this have to do with
the way I need to handle the carriage returns? After I receive the
ok from the modem, I cannot read from the port again.
francis cheung
cheung@sonatech.com
I would prefer email responses if it is not too much trouble.
Technical Details
Message-ID:
<249b7u$dq8@nectarine.ucsb.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!xlink.net!sol.ctr.columbia.edu!usc!cs.utexas.edu!swrinde!network.ucsd.edu!nntp.ucsb.edu!nntp.ucsb.edu!newsShow Full Headers
Complete Article Headers
Message-ID: <249b7u$dq8@nectarine.ucsb.edu> Subject: cnews posting Date: Tue, 10 Aug 1993 23:33:18 +0000 From: fcheung@ucsb.edu (Francis Cheung) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!xlink.net!sol.ctr.columbia.edu!usc!cs.utexas.edu!swrinde!network.ucsd.edu!nntp.ucsb.edu!nntp.ucsb.edu!news Newsgroups: news.software.readers Organization: University of California, Santa Barbara Lines: 103 Sender: fcheung@nectarine.ucsb.edu Distribution: world NNTP-Posting-Host: nectarine.ucsb.edu