🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
1 messages
1 total messages Started by Francis Cheung Tue, 10 Aug 1993 23:33
cnews posting
#5245
Author: Francis Cheung
Date: Tue, 10 Aug 1993 23:33
103 lines
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads