home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xaio1.exe / XAIOB.C < prev    next >
Text File  |  1994-09-07  |  12KB  |  417 lines

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