home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-4.ZIP / GSAMP / GSAMP.ZIP / EXAMP49.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-09  |  1.9 KB  |  78 lines

  1. /*
  2.  *  EXAMP49.C
  3.  *
  4.  *  The Greenleaf Comm Library
  5.  *
  6.  *  Copyright (C) 1989 Greenleaf Software Inc.  All Rights Reserved.
  7.  *
  8.  *  This example program demonstrates the use of the HMSetEscapeCode()
  9.  *  and HMSetEscapeCodeGuardTime() functions.  It sets the two parameters
  10.  *  up, then allows the user to enter the escape sequence by pressing
  11.  *  the F1 key.  It sets both parameters to their defaults, with the
  12.  *  character '+' and the guard time of 1 second.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "asiports.h"
  19. #include "ibmkeys.h"
  20. #include "gf.h"
  21.  
  22. void my_putc( char c );
  23. void disconnect( void );
  24. void main( void );
  25.  
  26. void main()
  27. {
  28.     int status;
  29.     int c;
  30.  
  31.     status = asiopen( COM1, ASINOUT | BINARY | NORMALRX, 100, 100,
  32.                       1200L, P_NONE, 1, 8, ON, ON);
  33.     if ( status < ASSUCCESS ) {
  34.         printf( "Failed to open the port.  Status = %d\n", status );
  35.         exit( 1 );
  36.     }
  37.  
  38.     HMWaitForOK( TICKS_PER_SECOND, NULL );
  39.     HMSetUpEchoRoutine( my_putc );
  40.  
  41.     HMReset(COM1);
  42.     HMSetEscapeCode( COM1, '+' );
  43.     HMSetEscapeCodeGuardTime( COM1, 50 );
  44.  
  45.     for ( ; ; ) {
  46.         if ( gfkbhit() ) {
  47.             c = getkey();
  48.             if ( c == ESC )
  49.                 exit( 0 );
  50.             else if ( c == F1 )
  51.                 HMDial( COM1, "250-3778" );
  52.             else if ( c == F2 )
  53.                 disconnect();
  54.             else
  55.                 asiputc( COM1, c );
  56.         }
  57.         c = asigetc( COM1 );
  58.         if ( c >= ASSUCCESS )
  59.             putc( c, stdout );
  60.    }
  61. }
  62.  
  63. void my_putc( char c )
  64. {
  65.     putc( c, stdout );
  66. }
  67.  
  68. void disconnect()
  69. {
  70.     printf( "\nDisconnecting...\n");
  71.     while ( !istxempty( COM1 ) ) ;
  72.     timer( TICKS_PER_SECOND + 1 );
  73.     asiputs( COM1, "+++", -1 );
  74.     while ( !istxempty( COM1 ) ) ;
  75.     timer( TICKS_PER_SECOND * 2 );
  76.     HMSetHookSwitch( COM1, 0 );
  77. }
  78.