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

  1. /**************************************************************************
  2.  *
  3.  *  TESTCOMM.CPP
  4.  *
  5.  *  This file contains a VERY simple C++ 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.  *  This file was compiled with the IBM C/C++ beta compiler using the
  12.  *  following flags:
  13.  *
  14.  *      /Fd /Tdp /G3m+s-d-e+ /O /Re /C /W3gen+ppc+enu+par+
  15.  *_________________________________________________________________________
  16.  *
  17.  *  Copyright (c) 1992 by ASH Software, Inc.
  18.  *
  19.  *  Update History
  20.  *
  21.  *    12/17/1992 - Module created
  22.  *
  23.  **************************************************************************/
  24.  
  25. #define INCL_DOS
  26. #define INCL_ERRORS
  27. #define INCL_DOSDEVIOCTL
  28. #define INCL_DOSDEVICES
  29.  
  30. #include <os2.h>
  31. #include "commos2.hpp"
  32. #include <stdio.h>
  33.  
  34. #define CR   0x0D
  35. #define LF   0x0A
  36.  
  37. int main()
  38. {
  39. SHORT
  40.   sKeepReading;
  41.  
  42. ULONG
  43.   ulByte,
  44.   ulRC;
  45.  
  46. HFILE
  47.   hComm2;
  48.  
  49. UCHAR
  50.   CharString[81];
  51.  
  52. CommPort
  53.   COM2;
  54.  
  55. printf("\nProgram Starting");
  56.  
  57. if ((ulRC=COM2.Open(2)) == COMM_ERROR_NOERROR)
  58.   {
  59.  
  60.   // Comm port is open
  61.  
  62.   printf("\nOpen Successful");
  63.   if ((ulRC=COM2.Initialize()) == COMM_ERROR_NOERROR)
  64.     {
  65.  
  66.     // Comm port has been initialized to the default of 9600,n,8,1
  67.  
  68.     printf("\nInitialize Successful");
  69.  
  70.     if ((ulRC=COM2.ClearBuffers()) != COMM_ERROR_NOERROR)
  71.       printf("\nClear Failed");
  72.  
  73.     CharString[0]='A';
  74.     CharString[1]='T';
  75.     CharString[2]='Z';
  76.     CharString[3]=CR;
  77.     CharString[4]=LF;
  78.  
  79.     // Write ATZ<CR><LF> to the modem
  80.  
  81.     if ((ulRC=COM2.Write(CharString,5,&ulByte)) != COMM_ERROR_NOERROR)
  82.       printf("\nWrite Failed");
  83.  
  84.     // Read the port until no more characters are returned
  85.  
  86.     sKeepReading=TRUE;
  87.     do
  88.       {
  89.  
  90.       // Read until 81 characters are received or the <LF> is read
  91.  
  92.       if ((ulRC=COM2.ReadUntilByte(CharString,81,&ulByte,LF,2000))
  93.            != COMM_ERROR_NOERROR)
  94.         {
  95.         if (ulRC == COMM_ERROR_TIMEOUTEXCEEDED)
  96.           printf("\nReadUntilByte Timed Out");
  97.         else
  98.           printf("\nReadUntilByte Failed");
  99.         sKeepReading=FALSE;
  100.         }
  101.     
  102.       // Print the data returned from the port
  103.  
  104.       if (ulByte > 0)
  105.         {
  106.         CharString[ulByte]='\0';
  107.         printf("\nReceived :%s",CharString);
  108.         }
  109.       else
  110.         sKeepReading=FALSE;
  111.       } while (sKeepReading);
  112.     }
  113.   else
  114.     printf("\nInitialize Failed");
  115.   COM2.Close();
  116.   }
  117. else
  118.   printf("\nOpen Failed");
  119.  
  120. printf("\nProgram Terminating\n");
  121. return 0;
  122. }
  123.  
  124.