home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / comos2.zip / TEST16.C < prev    next >
C/C++ Source or Header  |  1993-02-21  |  3KB  |  122 lines

  1. /**************************************************************************
  2.  *
  3.  *  TESTCOMM.C
  4.  *
  5.  *  This file contains a VERY simple test case for the COMMOS2 library.
  6.  *  Program assumes that a modem is connected to port 2 and is capable of
  7.  *  9600 baud transmission speed.  The program sends ATZ<CR><LF> to the
  8.  *  port and displays the text returned which is usually the ATZ string
  9.  *  and an OK string.
  10.  *_________________________________________________________________________
  11.  *
  12.  *  Copyright (c) 1992 by ASH Software, Inc.
  13.  *
  14.  *  Update History
  15.  *
  16.  *    12/17/1992 - Module created
  17.  *
  18.  **************************************************************************/
  19.  
  20. #define INCL_COMMOS2_16BIT
  21.  
  22. #include <os2.h>
  23. #include "commos2.h"
  24. #include <stdio.h>
  25.  
  26. #define CR   0x0D
  27. #define LF   0x0A
  28.  
  29. int main()
  30. {
  31. SHORT
  32.   sKeepReading;
  33.  
  34. ULONG
  35.   ulByte,
  36.   ulRC;
  37.  
  38. HCOMMPORT
  39.   hComm2;
  40.  
  41. CHAR
  42.   CharString[81];
  43.  
  44. if ((ulRC=CommStartSystem(4)) == COMM_ERROR_NOERROR)
  45.   {
  46.  
  47.   // Comm System has been initialized
  48.  
  49.   printf("\nCommStartSystem Successful");
  50.   if ((ulRC=CommOpen(2,&hComm2)) == COMM_ERROR_NOERROR)
  51.     {
  52.  
  53.     // Comm port is open
  54.  
  55.     printf("\nCommOpen Successful");
  56.     if ((ulRC=CommInit(hComm2,9600,PARITY_NONE,8,STOPBITS_1,
  57.           TRANSMIT_NO_BREAK)) == COMM_ERROR_NOERROR)
  58.       {
  59.  
  60.       // Comm port has been initialized to 9600,n,8,1
  61.  
  62.       printf("\nCommInit Successful");
  63.  
  64.       if ((ulRC=CommClear(hComm2)) != COMM_ERROR_NOERROR)
  65.         printf("\nCommClear Failed");
  66.  
  67.       CharString[0]='A';
  68.       CharString[1]='T';
  69.       CharString[2]='Z';
  70.       CharString[3]=CR;
  71.       CharString[4]=LF;
  72.  
  73.       // Write ATZ<CR><LF> to the modem
  74.  
  75.       if ((ulRC=CommWrite(hComm2,CharString,5,&ulByte)) != COMM_ERROR_NOERROR)
  76.         printf("\nCommWrite Failed");
  77.  
  78.       // Read the port until no more characters are returned
  79.  
  80.       sKeepReading=TRUE;
  81.       do
  82.         {
  83.  
  84.         // Read until 81 characters are received or the <LF> is read
  85.  
  86.         if ((ulRC=CommReadUntilByte(hComm2,CharString,81,&ulByte,LF,2000))
  87.              != COMM_ERROR_NOERROR)
  88.           {
  89.           if (ulRC == COMM_ERROR_TIMEOUTEXCEEDED)
  90.             printf("\nCommReadUntilByte Timed Out");
  91.           else
  92.             printf("\nCommReadUntilByte Failed");
  93.           sKeepReading=FALSE;
  94.           }
  95.       
  96.         // Print the data returned from the port
  97.  
  98.         if (ulByte > 0)
  99.           {
  100.           CharString[ulByte]='\0';
  101.           printf("\nReceived :%s",CharString);
  102.           }
  103.         else
  104.           sKeepReading=FALSE;
  105.         } while (sKeepReading);
  106.       }
  107.     else
  108.       printf("\nCommInit Failed");
  109.     CommClose(hComm2);
  110.     }
  111.   else
  112.     printf("\nCommOpen Failed");
  113.   CommStopSystem();
  114.   }  
  115. else
  116.   printf("\nCommStartSystem Failed");
  117.  
  118. printf("\nProgram Terminating\n");
  119. return 0;
  120. }
  121.  
  122.