Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

sendpage.c

Go to the documentation of this file.
00001 
00002 /*
00003  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
00004  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
00005  *
00006  *    $Id: sendpage_8c-source.html 2161 2006-05-19 16:55:03Z paulf $
00007  *
00008  *    Revision history:
00009  *     $Log$
00009  *     Revision 1.1  2006/05/19 16:55:02  paulf
00009  *     first inclusion
00009  *
00010  *     Revision 1.1  2000/02/14 18:53:30  lucky
00011  *     Initial revision
00012  *
00013  *
00014  */
00015 
00016   /**********************************************************************
00017    *                             sendpage.c                             *
00018    *                         Windows NT version                         *
00019    **********************************************************************/
00020 
00021 #include <windows.h>
00022 #include <stdio.h>
00023 #include <earthworm.h>
00024 
00025 
00026  /**********************************************************************
00027   *            Send a Pager Request to PAGEIT via Serial Port          *
00028   *                          SendPage( buff )                          *
00029   *                                                                    *
00030   *     Will time out after four seconds if anything caused a hang.    *
00031   *     buff = String to output to serial port                         *
00032   *                                                                    *
00033   * Returns:                                                           *
00034   *      0 => All went well                                            *
00035   *     -1 => Time out - not in os2 or nt versions                     *
00036   *     -2 => Error while writing to port                              *
00037   **********************************************************************/
00038 
00039 int SendPage( char *buff )
00040 {
00041    HANDLE     comHandle;
00042    BOOL       success;
00043    DCB        dcb;
00044    DWORD      numWritten;
00045 
00046 /* Set up the port with these parameters
00047    *************************************/
00048    const char SerialPort[] = "COM2";
00049    const DWORD baud        = 9600;
00050    const BYTE  parity      = EVENPARITY;
00051    const BYTE  databits    = 7;
00052    const BYTE  stopbits    = ONESTOPBIT;
00053 
00054 /* Open the com port
00055    *****************/
00056    comHandle = CreateFile( SerialPort, GENERIC_READ | GENERIC_WRITE,
00057                            0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
00058 
00059 /* Get the current settings of the COMM port
00060    *****************************************/
00061    success = GetCommState( comHandle, &dcb );
00062    if ( !success )
00063    {
00064       logit( "e", "sendpage error getting the COM settings: %d\n", GetLastError() );
00065       return -2;
00066    }
00067 
00068 /* Modify the COMM settings
00069    ************************/
00070    dcb.BaudRate = baud;
00071    dcb.Parity   = parity;
00072    dcb.ByteSize = databits;
00073    dcb.StopBits = stopbits;
00074 
00075 /* Apply the new COMM port settings
00076    ********************************/
00077    success = SetCommState( comHandle, &dcb );
00078    if ( !success )
00079    {
00080       logit( "e", "sendpage error applying the COM settings: %d\n", GetLastError() );
00081       return -2;
00082    }
00083 
00084 /* Send pager message to serial port
00085    *********************************/
00086    success = WriteFile( comHandle, buff, strlen(buff), &numWritten, 0 );
00087    if ( !success )
00088    {
00089       logit( "e", "sendpage error for port %s: %d\n", SerialPort, GetLastError() );
00090       CloseHandle( comHandle );
00091       return -2;
00092    }
00093 
00094    CloseHandle( comHandle );
00095    return 0;
00096 }

Generated on Tue May 6 09:16:09 2003 for Earthworm Libs by doxygen1.3-rc3