home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / windows / winterm / modem_io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-30  |  1.8 KB  |  76 lines

  1. /*** MODEM_IO.C ***/
  2.  
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include "windows.h"
  6. #include "pcl4w.h"
  7. #include "ascii.h"
  8. #include "modem_io.h"
  9. #include "term_io.h"
  10. #include "paint.h"
  11.  
  12. extern HWND hMainWnd;
  13. extern int  OnLineFlag;
  14.  
  15. #define MAXSTRING    64
  16. #define CHARSPACING 200
  17.  
  18. static char ModemText[MAXSTRING+1]; /* string to send */
  19. static int  ModemLength = 0;        /* length of above string */
  20. static int  ModemIndex = 0;         /* current index into ModemText */
  21. static int  ModemPort = 0;          /* Port number */
  22. static long ModemTime = 0L;         /* time used to time SendTo */
  23. /*
  24. **  Initialization for SendToModem().
  25. */
  26.  
  27. void InitModem(int Port,char *String)
  28. {int i;
  29.  ModemPort = Port;
  30.  ModemLength = strlen(String);
  31.  if(ModemLength>=MAXSTRING) ModemLength = MAXSTRING;
  32.  for(i=0;i<ModemLength;i++) ModemText[i] = String[i];
  33.  ModemText[ModemLength] = '\0';
  34.  ModemIndex = 0;
  35.  ModemTime = 0L;
  36.  SioRxFlush(ModemPort);
  37. } /* end InitModem */
  38.  
  39. /*
  40. **  Send string character. Call until it
  41. **  returns TRUE (which indicates 'idle').
  42. */
  43.  
  44. int SendToModem(void)
  45. {
  46.  char c;
  47.  int Code;
  48.  int Delay = CHARSPACING;
  49.  /* transmit string sent ? */
  50.  if(ModemIndex==ModemLength) return TRUE;
  51.  /* echo any incoming */
  52.  Code = GetChar(ModemPort);
  53.  if(Code>=0)
  54.    {c = (char)Code;
  55.     WriteTheString(&c,1);
  56.    }
  57.  /* time to process next char ? */
  58.  if(GetTickCount() < ModemTime) return FALSE;
  59.  /* fetch character */
  60.  c = toupper( ModemText[ModemIndex++] );
  61.  switch(c)
  62.    {case '!':
  63.       /* replace ! with carriage return */
  64.       c = CR;
  65.       break;
  66.     case '~':
  67.       /* delay 1/2 second */
  68.       Delay = 500;
  69.       c = ' ';
  70.       break;
  71.    } /* end switch */
  72.  /* transmit as 7 bit character */
  73.  PutChar(ModemPort,(char)(0x7f & c));
  74.  ModemTime = GetTickCount() + (long)Delay;
  75.  return FALSE;
  76. } /* end SendToModem */