home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_02.ZIP / AUTODIAL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-16  |  2.6 KB  |  80 lines

  1. /* AUTODIAL.C - From page 500 of "Microsoft C Programming for   */
  2. /* the IBM" by Robert Lafore. This program dials a number that  */
  3. /* can be inserted by editing the program. Dial with program,   */
  4. /* pick up the phone and wait for answer. At this point, pres-  */
  5. /* sing any key will hang up modem and let the call continue    */
  6. /* by voice.                                                    */
  7. /****************************************************************/
  8.  
  9. #include "dos.h"           /*initialize port*/
  10. #define COM 1              /*serial port no. (0 = COM1, 1 = COM2)*/
  11. #define CONF 0x43          /*300 bpi, no par, 1 stop, 8 bits*/
  12. #define RS232 0x14         /*RS232 serial port int number*/
  13. #define DATAR 0x100        /*data ready bit in status word*/
  14. union REGS inregs, outregs;   /*for ROM BIOS calls*/
  15.  
  16. main()
  17. {
  18.    init();
  19.    command("AT D T 883-7045;\r");      /*dial phone*/
  20.    /*** (Semicolon after phone # returns modem to command mode) ***/
  21.    printf("\nPress any key to hang up: \n");
  22.    getche();               /*await char*/
  23.    command("AT H0\r");     /*hang up*/
  24. }
  25.  
  26. /* command() */   /* sends commands to modem */
  27. command(comstr)
  28. char *comstr;
  29. {
  30. int j, k;
  31. char ch, receive();
  32.  
  33.    for(j = 0; (ch = *(comstr + j)) != '\0'; j++)  { /*send command*/
  34.       send(ch);            /*send char to modem*/
  35.       for(k = 0; k < 500 && !ready(); k++)   /*wait for echo*/
  36.          ;
  37.       ch = receive();            /*get echo*/
  38.       putch(ch);
  39.    }
  40. }
  41.  
  42. /* init() */      /* initialize serial port */
  43. init(conf)
  44. char conf;        /*addr of configuration code*/
  45. {
  46.    inregs.h.ah = 0;        /* 'initialize port' service */
  47.    inregs.x.dx = COM;      /*port number*/
  48.    inregs.h.al = CONF;     /*configuration*/
  49.    int86(RS232, &inregs, &outregs);
  50. }
  51.  
  52. /* send() */      /* send char to serial port */
  53. send(c)
  54. char c;
  55. {
  56.    inregs.h.ah = 1;        /* 'send char' service */
  57.    inregs.x.dx = COM;      /*port number*/
  58.    inregs.h.al = c;        /*character*/
  59.    int86(RS232, &inregs, &outregs);
  60. }
  61.  
  62. /* ready */    /* get serial port ready status */
  63. ready()
  64. {
  65.    inregs.h.ah = 3;        /* 'get status' service */
  66.    inregs.x.dx = COM;      /*port number*/
  67.    int86(RS232, &inregs, &outregs);
  68.    return(outregs.x.ax & DATAR);    /*return 'data ready' status*/
  69. }
  70.  
  71. /* receive */     /* get character from serial port */
  72. char receive()
  73. {
  74.    inregs.h.ah = 2;        /* 'receive char' service */
  75.    inregs.x.dx = COM;      /*port number*/
  76.    int86(RS232, &inregs, &outregs);
  77.    return(outregs.h.al & 0x7F);     /*return character*/
  78.                                     /* (AND off 8th bit*/
  79. }
  80.