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 >
Text File  |  1994-09-07  |  11KB  |  393 lines

  1. /****************************************************************************
  2. **    File:    XAIOA.C
  3. **
  4. **    Desc: Sample AIO code for NetWare NLM platform.     Assumes that there is a
  5. **            Hayes compatable modem connected to the (first available) AIO port.
  6. **            Sends an 'AT' to the modem and expects the Hayes 'OK' acknoledgement.
  7. **
  8. **    Disclaimer:
  9. **
  10. **        Novell, Inc. makes no representations or warranties with respect to
  11. **        any NetWare software, and specifically disclaims any express or
  12. **        implied warranties of merchantability, title, or fitness for a
  13. **        particular purpose.  
  14. **
  15. **        Distribution of any NetWare software is forbidden without the
  16. **        express written consent of Novell, Inc.  Further, Novell reserves
  17. **        the right to discontinue distribution of any NetWare software.
  18. **
  19. **        Novell is not responsible for lost profits or revenue, loss of use
  20. **        of the software, loss of data, costs of re-creating lost data, the
  21. **        cost of any substitute equipment or program, or claims by any party
  22. **        other than you.  Novell strongly recommends a backup be made before
  23. **        any software is installed.   Technical support for this software
  24. **        may be provided at the discretion of Novell.
  25. **
  26. **    QMK386 options used:
  27. **
  28. **        /ia - AIO support
  29. **
  30. **    Programmers:
  31. **
  32. **        Ini    Who                    Firm
  33. **        -----------------------------------------------------------------------
  34. **        ABJ    Adam B. Jerome        Novell Developer Support.
  35. **
  36. **    History:
  37. **
  38. **        When        Who    What
  39. **        -----------------------------------------------------------------------
  40. **        08-04-94    ABJ    Updated to Jerome Standard.
  41. */
  42.  
  43. /****************************************************************************
  44. **    Include headers, function prototypes, macros, etc.
  45. */
  46.     /*------------------------------------------------------------------------
  47.     **    ANSI
  48.     */
  49.     #include <stdio.h>
  50.     #include <stdlib.h>
  51.     #include <process.h>
  52.     #include <string.h>
  53.  
  54.     /*------------------------------------------------------------------------
  55.     **    NetWare NLM
  56.     */
  57.     #include <aio.h>
  58.  
  59.     /*------------------------------------------------------------------------
  60.     **    This module.
  61.     */
  62.     #define BUFFER_SIZE     128
  63.  
  64. /****************************************************************************
  65. **    Program start.
  66. */
  67. void main(void)
  68.     {
  69.    int                 cCode;
  70.    int                 portHandle;
  71.    LONG                count;
  72.    WORD                state;
  73.    char                buffer[BUFFER_SIZE];
  74.    AIOPORTCAPABILITIES portCaps;
  75.    int                 hardwareType;
  76.    int                 boardNumber;
  77.    int                 portNumber;
  78.  
  79.    /*------------------------------------------------------------------------
  80.     **    Acquire any available ports from COMx driver only
  81.     */
  82.    hardwareType  = AIO_HARDWARE_TYPE_WILDCARD /* AIO_COMX_TYPE */;
  83.    boardNumber   = AIO_BOARD_NUMBER_WILDCARD;
  84.    portNumber    = AIO_PORT_NUMBER_WILDCARD;
  85.  
  86.    cCode=AIOAcquirePort(
  87.         /* IO    hardwareType    */    &hardwareType,
  88.         /*    IO    boardNumber        */    &boardNumber,
  89.         /*    IO    portNumber        */    &portNumber,
  90.         /*    -O    portHandle        */    &portHandle
  91.         );
  92.     switch(cCode)
  93.         {
  94.         case AIO_SUCCESS:
  95.             break;
  96.  
  97.         case AIO_FAILURE:
  98.           printf("ERROR:  AIOAcquirePort() failed.\n");
  99.             break;
  100.  
  101.         case AIO_PORT_NOT_AVAILABLE:
  102.           printf("ERROR:  AIOAcquirePort() reported: No ports available.\n");
  103.           goto END;
  104.     
  105.         case AIO_TYPE_NUMBER_INVALID:
  106.           printf("ERROR:  AIOAcquirePort() reported: Invalid hardware type specified.\n");
  107.           goto END;
  108.  
  109.         case AIO_BOARD_NUMBER_INVALID:
  110.           printf("ERROR:  AIOAcquirePort() reported: Invalid board number specified.\n");
  111.           goto END;
  112.  
  113.         case AIO_PORT_NUMBER_INVALID:
  114.           printf("ERROR:  AIOAcquirePort() reported: Invalid port number specified.\n");
  115.           goto END;
  116.  
  117.         default:
  118.           printf("ERROR:  AIOAcquirePort() reported unknown error: %d.\n", cCode);
  119.           goto END;
  120.         }
  121.  
  122.    printf("Acquired port for driver %d, board %d, port %d.\n",
  123.         hardwareType, boardNumber, portNumber);
  124.  
  125.    /*------------------------------------------------------------------------
  126.     ** Get the high-level capabilities of the acquired port, not driver caps
  127.     */
  128.    cCode=AIOGetPortCapability(
  129.         /* I- portHandle        */    portHandle,
  130.         /*    IO    capabilities    */    &portCaps,
  131.         /*    IO    dvrCapabilities*/    NULL             /* NULL means we don't need this. */
  132.         );
  133.     switch(cCode)
  134.         {
  135.         case AIO_SUCCESS:
  136.             break;
  137.  
  138.         case AIO_BAD_HANDLE:
  139.           printf("ERROR:  AIOGetPortCapability() reported: Bad handle specified.\n");
  140.             break;
  141.  
  142.         case AIO_FAILURE:
  143.           printf("ERROR:  AIOGetPortCapability() failed.\n");
  144.             break;
  145.  
  146.         case AIO_PORT_GONE:
  147.           printf("ERROR:  AIOGetPortCapability() reported: Port is gone.\n");
  148.           goto END;
  149.     
  150.         default:
  151.           printf("ERROR:  AIOGetPortCapability() reported unknown error: %d.\n", cCode);
  152.           goto END;
  153.         }
  154.  
  155.    /*------------------------------------------------------------------------
  156.     **    Verify that the structures are current or newer
  157.     */
  158.    if(portCaps.returnLength < sizeof(portCaps))
  159.       printf("WARNING:  Obsolete structures in use!\n");
  160.       else
  161.         {
  162.        /*---------------------------------------------------------------------
  163.         **    Verify that the port can handle 2400 baud
  164.         */
  165.        if((portCaps.minBitRate > AIO_BAUD_2400) || (portCaps.maxBitRate < AIO_BAUD_2400))
  166.           printf("WARNING:  Port cannot be configured for 2400bps rate requirement.\n");
  167.         }
  168.  
  169.    /*------------------------------------------------------------------------
  170.     **    Configure the port for use
  171.     */
  172.    cCode=AIOConfigurePort(
  173.         /*    I-    portHandle        */    portHandle,
  174.         /*    I-    bitRate            */    AIO_BAUD_2400,
  175.         /*    I- dataBits            */    AIO_DATA_BITS_8,
  176.       /*    I- stopBits            */    AIO_STOP_BITS_1,
  177.         /*    I- parityMode        */    AIO_PARITY_NONE,
  178.         /*    I- flowCtrlMode    */    AIO_SOFTWARE_FLOW_CONTROL_ON
  179.         );
  180.     switch(cCode)
  181.         {
  182.         case AIO_SUCCESS:
  183.             break;
  184.  
  185.         case AIO_BAD_HANDLE:
  186.           printf("ERROR:  AIOConfigurePort() reported: Bad handle specified.\n");
  187.             break;
  188.  
  189.         case AIO_FAILURE:
  190.           printf("ERROR:  AIOConfigurePort() failed.\n");
  191.             break;
  192.  
  193.         case AIO_QUALIFIED_SUCCESS:
  194.           printf("ERROR:  AIOConfigurePort() reported: Couldn't configure port exactly as requested.\n");
  195.           break;
  196.     
  197.         case AIO_PORT_GONE:
  198.           printf("ERROR:  AIOConfigurePort() reported: Port is gone.\n");
  199.           goto END;
  200.     
  201.         default:
  202.           printf("ERROR:  AIOConfigurePort() reported unknown error: %d.\n", cCode);
  203.           goto END;
  204.         }
  205.  
  206.    /*------------------------------------------------------------------------
  207.     **    Set DTR and RTS on
  208.     */
  209.    cCode=AIOSetExternalControl(
  210.         /*    I-    portHandle        */    portHandle,
  211.         /* I-    requestType        */    AIO_EXTERNAL_CONTROL,
  212.       /*    I- requestValue    */    AIO_EXTCTRL_DTR|AIO_EXTCTRL_RTS
  213.         );
  214.     switch(cCode)
  215.         {
  216.         case AIO_SUCCESS:
  217.             break;
  218.  
  219.         case AIO_BAD_HANDLE:
  220.           printf("ERROR:  AIOSetExternalControl() reported: Bad handle specified.\n");
  221.             break;
  222.  
  223.         case AIO_FAILURE:
  224.           printf("ERROR:  AIOSetExternalControl() failed.\n");
  225.             break;
  226.  
  227.         case AIO_FUNC_NOT_SUPPORTED:
  228.           printf("ERROR:  AIOSetExternalControl() reported: Function not supported.\n");
  229.           break;
  230.     
  231.         case AIO_INVALID_PARAMETER:
  232.           printf("ERROR:  AIOSetExternalControl() reported: Invalid parameter.\n");
  233.           break;
  234.     
  235.         case AIO_BAD_REQUEST_TYPE:
  236.           printf("ERROR:  AIOSetExternalControl() reported: Bad request type.\n");
  237.           break;
  238.     
  239.         case AIO_PORT_GONE:
  240.           printf("ERROR:  AIOSetExternalControl() reported: Port is gone.\n");
  241.           goto END;
  242.     
  243.         default:
  244.           printf("ERROR:  AIOSetExternalControl() reported unknown error: %d.\n", cCode);
  245.           goto END;
  246.         }
  247.  
  248.    /*------------------------------------------------------------------------
  249.     **    Send an AT attention string to the modem
  250.     */
  251.    strcpy(buffer, "AT\r");
  252.    cCode=AIOWriteData(
  253.         /*    I-    portHandle                */    portHandle,
  254.         /* I-    buffer                    */    buffer,
  255.         /*    I-    lengthOfBuffer            */    strlen(buffer),
  256.         /*    -O    numberOfBytesWritten    */    &count
  257.         );
  258.     switch(cCode)
  259.         {
  260.         case AIO_SUCCESS:
  261.             break;
  262.  
  263.         case AIO_BAD_HANDLE:
  264.           printf("ERROR:  AIOWriteData() reported: Bad handle specified.\n");
  265.             break;
  266.  
  267.         case AIO_FAILURE:
  268.           printf("ERROR:  AIOWriteData() failed.\n");
  269.             break;
  270.  
  271.         case AIO_PORT_GONE:
  272.           printf("ERROR:  AIOWriteData() reported: Port is gone.\n");
  273.           goto END;
  274.  
  275.         default:
  276.           printf("ERROR:  AIOWriteData() reported unknown error: %d.\n", cCode);
  277.           goto END;
  278.         }
  279.  
  280.    /*------------------------------------------------------------------------
  281.     **    Make sure that everything was sent.
  282.     */
  283.    if(count < strlen(buffer))
  284.         {
  285.       printf("ERROR: AIOWriteData() indicated: incomplete write, only %d bytes written.\n", count );
  286.         goto END;
  287.         }
  288.  
  289.    /*------------------------------------------------------------------------
  290.     **    Poll until there are at least three characters [OK<cr>] to be read
  291.     */
  292.    do    {
  293.       cCode=AIOReadStatus(
  294.             /* I-    portHandle    */    portHandle,
  295.             /*    I-    count            */    &count,
  296.             /*    -O    state            */    &state
  297.             );
  298.         switch(cCode)
  299.             {
  300.             case AIO_SUCCESS:
  301.                 break;
  302.  
  303.             case AIO_BAD_HANDLE:
  304.               printf("ERROR:  AIOReadStatus() reported: Bad handle specified.\n");
  305.                 break;
  306.  
  307.             case AIO_FAILURE:
  308.               printf("ERROR:  AIOReadStatus() failed.\n");
  309.                 break;
  310.  
  311.             case AIO_PORT_GONE:
  312.               printf("ERROR:  AIOReadStatus() reported: Port is gone.\n");
  313.               goto END;
  314.     
  315.             default:
  316.               printf("ERROR:  AIOReadStatus() reported unknown error: %d.\n", cCode);
  317.               goto END;
  318.             }
  319.       ThreadSwitch();
  320.        } while(count < 3);
  321.  
  322.    /*------------------------------------------------------------------------
  323.     **    Read the input buffer
  324.     */
  325.    cCode=AIOReadData(
  326.         /*    I-    portHandle            */    portHandle,
  327.         /*    I-    buffer                */    buffer,
  328.         /*    I-    lengthOfBuffer        */    BUFFER_SIZE,
  329.         /*    -O    numberOfBytesRead    */    &count
  330.         );
  331.     switch(cCode)
  332.         {
  333.         case AIO_SUCCESS:
  334.             break;
  335.  
  336.         case AIO_BAD_HANDLE:
  337.           printf("ERROR:  AIOReadData() reported: Bad handle specified.\n");
  338.             break;
  339.  
  340.         case AIO_FAILURE:
  341.           printf("ERROR:  AIOReadData() failed.\n");
  342.             break;
  343.  
  344.         case AIO_PORT_GONE:
  345.           printf("ERROR:  AIOReadData() reported: Port is gone.\n");
  346.           goto END;
  347.  
  348.         default:
  349.           printf("ERROR:  AIOReadData() reported unknown error: %d.\n", cCode);
  350.           goto END;
  351.         }
  352.  
  353.    /*------------------------------------------------------------------------
  354.     **    Verify that the attention string was echoed back by the modem
  355.     */
  356.    if(strncmp(buffer, "AT\r", 3) != 0)
  357.       printf("ERROR:  Modem did not echo, saw \"%c%c%c\".\n",
  358.             buffer[0], buffer[1], buffer[2]);
  359.    else
  360.       printf("SUCCESS:  Modem echo confirmed.\n");
  361.  
  362.    /*------------------------------------------------------------------------
  363.     **    Release the port
  364.     */
  365.     if(portHandle != (-1))
  366.         {
  367.        cCode=AIOReleasePort(portHandle);
  368.         switch(cCode)
  369.             {
  370.             case AIO_SUCCESS:
  371.                 break;
  372.  
  373.             case AIO_BAD_HANDLE:
  374.               printf("ERROR:  AIOReleasePort() reported: Bad handle specified.\n");
  375.                 break;
  376.  
  377.             case AIO_FAILURE:
  378.               printf("ERROR:  AIOReleasePort() failed.\n");
  379.                 break;
  380.  
  381.             default:
  382.               printf("ERROR:  AIOReleasePort() reported unknown error: %d.\n", cCode);
  383.               goto END;
  384.             }
  385.         }
  386.  
  387. END:
  388.  
  389.    return;
  390.     }
  391.  
  392.  
  393.