home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xaio1.exe
/
XAIOA.C
< prev
next >
Wrap
Text File
|
1994-09-07
|
11KB
|
393 lines
/****************************************************************************
** File: XAIOA.C
**
** Desc: Sample AIO code for NetWare NLM platform. Assumes that there is a
** Hayes compatable modem connected to the (first available) AIO port.
** Sends an 'AT' to the modem and expects the Hayes 'OK' acknoledgement.
**
** Disclaimer:
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** QMK386 options used:
**
** /ia - AIO support
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** ABJ Adam B. Jerome Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 08-04-94 ABJ Updated to Jerome Standard.
*/
/****************************************************************************
** Include headers, function prototypes, macros, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <string.h>
/*------------------------------------------------------------------------
** NetWare NLM
*/
#include <aio.h>
/*------------------------------------------------------------------------
** This module.
*/
#define BUFFER_SIZE 128
/****************************************************************************
** Program start.
*/
void main(void)
{
int cCode;
int portHandle;
LONG count;
WORD state;
char buffer[BUFFER_SIZE];
AIOPORTCAPABILITIES portCaps;
int hardwareType;
int boardNumber;
int portNumber;
/*------------------------------------------------------------------------
** Acquire any available ports from COMx driver only
*/
hardwareType = AIO_HARDWARE_TYPE_WILDCARD /* AIO_COMX_TYPE */;
boardNumber = AIO_BOARD_NUMBER_WILDCARD;
portNumber = AIO_PORT_NUMBER_WILDCARD;
cCode=AIOAcquirePort(
/* IO hardwareType */ &hardwareType,
/* IO boardNumber */ &boardNumber,
/* IO portNumber */ &portNumber,
/* -O portHandle */ &portHandle
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_FAILURE:
printf("ERROR: AIOAcquirePort() failed.\n");
break;
case AIO_PORT_NOT_AVAILABLE:
printf("ERROR: AIOAcquirePort() reported: No ports available.\n");
goto END;
case AIO_TYPE_NUMBER_INVALID:
printf("ERROR: AIOAcquirePort() reported: Invalid hardware type specified.\n");
goto END;
case AIO_BOARD_NUMBER_INVALID:
printf("ERROR: AIOAcquirePort() reported: Invalid board number specified.\n");
goto END;
case AIO_PORT_NUMBER_INVALID:
printf("ERROR: AIOAcquirePort() reported: Invalid port number specified.\n");
goto END;
default:
printf("ERROR: AIOAcquirePort() reported unknown error: %d.\n", cCode);
goto END;
}
printf("Acquired port for driver %d, board %d, port %d.\n",
hardwareType, boardNumber, portNumber);
/*------------------------------------------------------------------------
** Get the high-level capabilities of the acquired port, not driver caps
*/
cCode=AIOGetPortCapability(
/* I- portHandle */ portHandle,
/* IO capabilities */ &portCaps,
/* IO dvrCapabilities*/ NULL /* NULL means we don't need this. */
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOGetPortCapability() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOGetPortCapability() failed.\n");
break;
case AIO_PORT_GONE:
printf("ERROR: AIOGetPortCapability() reported: Port is gone.\n");
goto END;
default:
printf("ERROR: AIOGetPortCapability() reported unknown error: %d.\n", cCode);
goto END;
}
/*------------------------------------------------------------------------
** Verify that the structures are current or newer
*/
if(portCaps.returnLength < sizeof(portCaps))
printf("WARNING: Obsolete structures in use!\n");
else
{
/*---------------------------------------------------------------------
** Verify that the port can handle 2400 baud
*/
if((portCaps.minBitRate > AIO_BAUD_2400) || (portCaps.maxBitRate < AIO_BAUD_2400))
printf("WARNING: Port cannot be configured for 2400bps rate requirement.\n");
}
/*------------------------------------------------------------------------
** Configure the port for use
*/
cCode=AIOConfigurePort(
/* I- portHandle */ portHandle,
/* I- bitRate */ AIO_BAUD_2400,
/* I- dataBits */ AIO_DATA_BITS_8,
/* I- stopBits */ AIO_STOP_BITS_1,
/* I- parityMode */ AIO_PARITY_NONE,
/* I- flowCtrlMode */ AIO_SOFTWARE_FLOW_CONTROL_ON
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOConfigurePort() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOConfigurePort() failed.\n");
break;
case AIO_QUALIFIED_SUCCESS:
printf("ERROR: AIOConfigurePort() reported: Couldn't configure port exactly as requested.\n");
break;
case AIO_PORT_GONE:
printf("ERROR: AIOConfigurePort() reported: Port is gone.\n");
goto END;
default:
printf("ERROR: AIOConfigurePort() reported unknown error: %d.\n", cCode);
goto END;
}
/*------------------------------------------------------------------------
** Set DTR and RTS on
*/
cCode=AIOSetExternalControl(
/* I- portHandle */ portHandle,
/* I- requestType */ AIO_EXTERNAL_CONTROL,
/* I- requestValue */ AIO_EXTCTRL_DTR|AIO_EXTCTRL_RTS
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOSetExternalControl() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOSetExternalControl() failed.\n");
break;
case AIO_FUNC_NOT_SUPPORTED:
printf("ERROR: AIOSetExternalControl() reported: Function not supported.\n");
break;
case AIO_INVALID_PARAMETER:
printf("ERROR: AIOSetExternalControl() reported: Invalid parameter.\n");
break;
case AIO_BAD_REQUEST_TYPE:
printf("ERROR: AIOSetExternalControl() reported: Bad request type.\n");
break;
case AIO_PORT_GONE:
printf("ERROR: AIOSetExternalControl() reported: Port is gone.\n");
goto END;
default:
printf("ERROR: AIOSetExternalControl() reported unknown error: %d.\n", cCode);
goto END;
}
/*------------------------------------------------------------------------
** Send an AT attention string to the modem
*/
strcpy(buffer, "AT\r");
cCode=AIOWriteData(
/* I- portHandle */ portHandle,
/* I- buffer */ buffer,
/* I- lengthOfBuffer */ strlen(buffer),
/* -O numberOfBytesWritten */ &count
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOWriteData() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOWriteData() failed.\n");
break;
case AIO_PORT_GONE:
printf("ERROR: AIOWriteData() reported: Port is gone.\n");
goto END;
default:
printf("ERROR: AIOWriteData() reported unknown error: %d.\n", cCode);
goto END;
}
/*------------------------------------------------------------------------
** Make sure that everything was sent.
*/
if(count < strlen(buffer))
{
printf("ERROR: AIOWriteData() indicated: incomplete write, only %d bytes written.\n", count );
goto END;
}
/*------------------------------------------------------------------------
** Poll until there are at least three characters [OK<cr>] to be read
*/
do {
cCode=AIOReadStatus(
/* I- portHandle */ portHandle,
/* I- count */ &count,
/* -O state */ &state
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOReadStatus() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOReadStatus() failed.\n");
break;
case AIO_PORT_GONE:
printf("ERROR: AIOReadStatus() reported: Port is gone.\n");
goto END;
default:
printf("ERROR: AIOReadStatus() reported unknown error: %d.\n", cCode);
goto END;
}
ThreadSwitch();
} while(count < 3);
/*------------------------------------------------------------------------
** Read the input buffer
*/
cCode=AIOReadData(
/* I- portHandle */ portHandle,
/* I- buffer */ buffer,
/* I- lengthOfBuffer */ BUFFER_SIZE,
/* -O numberOfBytesRead */ &count
);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOReadData() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOReadData() failed.\n");
break;
case AIO_PORT_GONE:
printf("ERROR: AIOReadData() reported: Port is gone.\n");
goto END;
default:
printf("ERROR: AIOReadData() reported unknown error: %d.\n", cCode);
goto END;
}
/*------------------------------------------------------------------------
** Verify that the attention string was echoed back by the modem
*/
if(strncmp(buffer, "AT\r", 3) != 0)
printf("ERROR: Modem did not echo, saw \"%c%c%c\".\n",
buffer[0], buffer[1], buffer[2]);
else
printf("SUCCESS: Modem echo confirmed.\n");
/*------------------------------------------------------------------------
** Release the port
*/
if(portHandle != (-1))
{
cCode=AIOReleasePort(portHandle);
switch(cCode)
{
case AIO_SUCCESS:
break;
case AIO_BAD_HANDLE:
printf("ERROR: AIOReleasePort() reported: Bad handle specified.\n");
break;
case AIO_FAILURE:
printf("ERROR: AIOReleasePort() failed.\n");
break;
default:
printf("ERROR: AIOReleasePort() reported unknown error: %d.\n", cCode);
goto END;
}
}
END:
return;
}