[comp.sys.ibm.pc] Help sending text to com2:

mlm@homxc.UUCP (M.MILLIMAN) (08/10/88)

I have been trying to write a simple C program to accept a telephone number
on the command line then send the appropriate modem commands with the tele-
phone number to com2 where my modem is connected.  The following program
goes off-hook then on-hook when the program terminates, but does not dial the
number.  It must be seeing the ATDT command but not the number.  I have tried
the more primitive open and write commands with no success.  This is the
first program I have written for my PC in a while, but it should not be
that hard.  I could spend the time pondering this question, but I am sure
someone else has already figured this out.

Thanks for the help,
Mark L. Milliman
mlm@homxc.att.com

/* dial.c - This simple program reads the telephone number from the command
	line and commands any Hayes compatible modem to dial the number then
	prompt the user to answer the phone.
	
	Version 1.0:  May 18, 1988  Mark Milliman
*/

#include <stdio.h>

main(argc, argv)
    int argc;
    char *argv[];
{
    char *com_port,*phno;
    FILE *modem;
    
    com_port = "com2";
    phno = argv[1];
    if ((modem = fopen(com_port,"w")) == NULL)  {
    	fprintf(stderr,"%s couldn't open file %s\n",argv[0],com_port);
    	exit(1);
}
    printf("Phone Number:  %s\n", phno);   /* debug */
    fprintf(modem,"ATDT %s\n", phno);
    printf("\nHit any key to exit\n");     /* debug */
    while(kbhit() == 0)  {}                /* debug */
    exit(0);
}
	

danno@microsoft.UUCP (Daniel A. Norton) (08/12/88)

In article <3012@homxc.UUCP>, mlm@homxc.UUCP (M.MILLIMAN) writes:
>                                                ... The following program
> goes off-hook then on-hook when the program terminates, but does not dial the
> number.
 . . .
>     fprintf(modem,"ATDT %s\n", phno);

You've opened up file 'modem' in text mode.  The 'fprintf' function
doesn't know that the modem knows the difference between CR and CR/LF,
so it's sending CR/LF, since you're in text mode.

Change your open mode on the 'fopen' from "w" to "wb", and change the
above line to:

      fprintf(modem,"ATDT %s\r", phno);

Otherwise, it would end the line in LF (you probably want CR).

Why does the phone go off hook but it does not dial?  Well, the
modem sees your command, followed by the CR, starts its dialing
procedure and then sees the LF come by.  You may already know
that the SmartModem aborts its dialing procedure whenever it
sees anything come from the terminal.

I presume you've already intialized the port with the DOS "MODE"
command, otherwise the modem would not have gone off hook.
-- 
Any opinions expressed are mine, not my employer's.
nortond@microsof.beaver.washington.EDU nortond%microsof@uw-beaver.ARPA
{decvax,decwrl,sco,sun,trsvax,uunet,uw-beaver}!microsof!nortond