Microsoft KB Archive/36024

CALL X“nn” for COBOL 3.0 Communications with COM1: and COM2:

PSS ID Number: Q36024 Article last modified on 04-20-1993

3.00 | 3.00 MS-DOS | OS/2

Summary: Sending and receiving bytes from the COM1: and COM2: serial communications ports can be done by calling the “Subprograms for Special Functions,” which are described in the “Microsoft COBOL Compiler Version 3.0: Operating Guide,” Page 8-7. Since COBOL Version 3.0 does not buffer communications, only 1 or 2 bytes can be sent or received at a time. The formats would be as follows: CALL X“87” USING port, data-value {input 1 byte} CALL X“96” USING port, data-value {input 2 bytes} CALL X“88” USING port, data-value {output 1 byte} CALL X“97” USING port, data-value {output 2 bytes}

More Information: Micro Focus has supplied the Microsoft COBOL Compiler Version 3.0 with several “Subprograms for Special Functions.” These subprograms are not guaranteed to be supported in future releases. They are designed to be used “as is.” Microsoft COBOL Compiler versions earlier than 3.0 do not support the CALL X“nn” subprograms. The code example below uses the following port addresses: COM1 port buffer address: 1016 Hex 3F8 COM1 line status register address: 1021 Hex 2FD COM2 port buffer address: 760 Hex 2F8 COM2 line status register address: 765 Hex 2FD Note: Don’t use CALL X“96” (read) or CALL X“97” (write) with the line status register address. If you do, you will not get a correct line status [or the line status will be 0 (zero)]. This occurs because the line status is a 1-byte value, and reading or writing 2 bytes to it may fail. Instead, use the CALL X“87” and CALL X“88” to obtain the 1-byte line status from the register. It’s okay to use CALL X“96” or CALL X“97” with the port buffer address, since the communications port buffer can contain more than 1 byte. The following is a code example:

************************************************************** *                                                            *  *  This example is designed to be a working program that     * * reads and sends bytes to and from COM1. * *  When using a HAYES 1200 or compatible unit, you must      * * be sure that the following switches are set:              * *                                                           *  *   Ignore DTR (switch 1 down)                               * *  Result codes sent (switch 3 down)                        * *  Characters not echoed in command state (switch 4 down)   * *  RS-232 Carrier detect off (switch 6 up)                  * *  Enable commands (switch 8 down)                          * *                                                           *  *  Prior to running, execute the DOS MODE command to set     * * the communications parameters. * **************************************************************   WORKING-STORAGE SECTION. * This is the COMM 1 buffer address 01 PORT                PIC 9(5) VALUE 1016. * This is the line status register address for COMM 1 01 STAT                PIC 9(5) VALUE 1021. * This is the character to be sent to the RS232 port 01 OUT-CHAR            PIC X.  * This is the character to be received from the RS232 port 01 IN-CHAR             PIC X.  * This is to hold the line status information. 01 LINE-STATUS         PIC 9(2) COMP-5. 01 CONSOLE-STATUS      PIC 9(2) COMP-X. * *****************************************************************  * This program will poll the keyboard waiting for the user to  *  enter a character. If a character is found, it will be sent * to the COM port. *****************************************************************  PROCEDURE DIVISION. MAIN SECTION. BEGIN. MOVE ZEROS TO CONSOLE-STATUS. CALL X&quot;D9&quot; USING CONSOLE-STATUS. IF CONSOLE-STATUS NOT = ZEROS CALL X&quot;83&quot; USING OUT-CHAR CALL X&quot;82&quot; USING OUT-CHAR PERFORM RS232-OUT. PERFORM RS232-IN. GO TO BEGIN. * *****************************************************************   RS232-IN SECTION. RS-IN. ****************************************************************** *  * The status register's least significant bit is set if there * is received data ready to be read. *      CALL X&quot;87&quot; USING STAT LINE-STATUS. DIVIDE LINE-STATUS BY 2 GIVING LINE-STATUS REMAINDER LINE-STATUS. IF LINE-STATUS = 1 CALL X&quot;87&quot; USING PORT IN-CHAR CALL X&quot;82&quot; USING IN-CHAR. * *****************************************************************   RS232-OUT SECTION. RS-OUT. ***************************************************************** *  * The status register's bit 5 is set if the transmitter buffer * is ready to accept another character. *      CALL X&quot;87&quot; USING STAT LINE-STATUS. DIVIDE 32 INTO LINE-STATUS. DIVIDE LINE-STATUS BY 2 GIVING LINE-STATUS REMAINDER LINE-STATUS. IF LINE-STATUS = 0 GO TO RS-OUT. CALL X&quot;88&quot; USING PORT OUT-CHAR. PGM-END. Additional reference words: 3.00 Copyright Microsoft Corporation 1993.