13 Asynchronous Devices

TIO Statements

The ON INPUT # Statement

The ON INPUT # statement is similar to the ON KEY # statement, in that the program continues execution until a preset condition occurs. When that condition occurs, the program branches to a specified routine.

Before an ON INPUT # statement is executed, the program must have exclusive use of the device. This is done with the REQUEST statement which is described later in this chapter.

The ON INPUT # statement explicitly enables input from a terminal and informs the system of the desired action to be taken when a complete input line is received. Syntax for this statement is as follows:

ON INPUT #port no [branching statement]

The branching statement can be a GOTO, GOSUB, or CALL statement. Here is a description of each:

GOTO
When an interrupt occurs, the program branches to the specified line and continues execution. The program cannot return to the line where the interrupt occurred. The GOTO statement does not store a return address, while the GOSUB and CALL statements do.
GOSUB
When an interrupt occurs, the program branches to the subroutine. After the subroutine has been executed, the program returns to the line where the interrupt occurred.
CALL
When an interrupt occurs, the program branches to the subprogram. After the subprogram has been executed, the program returns to the line where the interrupt occurred. Parameters cannot be passed.
Subprograms create a new environment during their execution. If an interrupt condition occurs during a subprogram and the action is another CALL, then the interrupt is serviced. If the action is a GOTO or GOSUB, the interrupt is not serviced until the subprogram exits with a SUBEXIT or SUBEND.

An interrupt generally occurs after execution of the current line. However, if an interrupt occurs during execution of a WAIT or INPUT statement, execution of the statement is suspended while the interrupt is serviced.

To prevent interrupts during critical portions of a program, use DISABLE statements to enclose the lines. Once the DISABLE statement is executed, no interrupts occur until the ENABLE statement is executed.

The ON INPUT # statement remains in effect until input is received or an OFF INPUT # statement is executed.

If the branching statement is omitted, TIO assumes that an ON INPUT # statement specifying a branch was previously executed.

For example, assume the subroutine Txy is called whenever input is available. The first ON INPUT # statement would have a branching statement of GOSUB Txy. When input is received from the terminal an interrupt occurs and program execution continues in the Txy subroutine. Before the subroutine is ended with a RETURN, the ON INPUT # statement with no branch is executed. When input is received from the terminal, an interrupt occurs and the action statement in the previous ON INPUT # statement, GOSUB Txy, is executed.

Handling of input data:

         +--------------+     +--------------+     +--------------+
         | remote       |     | HP-UX        |     | Eloquence |
         | terminal     |---->| tty device   |---->| program      |
         |              |     | driver       |     |              |
         +--------------+     +--------------+     +--------------+
HP-UX tty device driver collects data from the remote terminal. The behaviour and transmission parameters (e.g. baud rate, echo) depend on the configuration of tty device driver (via stty). Whenever the tty device driver signals that data is available, Eloquence will read data into an internal 512 byte buffer. If ON INPUT # is active an interrupt will be generated.

It is possible to configure the HP-UX device driver characteristics from an Eloquence program. MAPPNTR$ (port number) will return the name of the HP-UX device file which is mapped to that port number.

(For more detailed information see references to stty and termio(7).)

   Port = 15
   REQUEST Port
   COMMAND "!stty 2400 icanon icrnl <"&MAPPNTR$(Port)
   ...
   RELEASE Port

The AREAD$ Function

The string function AREAD$ transfers data from the input buffer to a string variable. Syntax is as follows:

Variable$ = AREAD$(port number)

If the AREAD$ function is attempted when no terminal input line is present in the input buffer, an empty string is returned. The carriage return character is not transferred to the string variable.

When the program has completed processing the input, the program explicitly re-enables further terminal input by means of the ON INPUT # statement.

Examples:

             REQUEST 12,Status
             IF Status=1 THEN Queue
             ON INPUT #12,3 GOSUB In_12
             .
             .
        In_12:  Next_line$=AREAD$(12)
             .
             .
             RELEASE 12
             RETURN
        Queue:  !
             REQUEST 12
             ON INPUT #12 GOSUB Input
             .
             .
        Input:  Next_line$=AREAD$(12)
             IF Next_line$="EXIT" THEN GOTO Stop_now
             .
             .
530          ON INPUT #12
540          RETURN
550  Stop_now:  RELEASE 12
560          RETURN

The OFF INPUT # Statement

This cancels a previous ON INPUT # statement. The syntax is as follows:

OFF INPUT #port number

Data remains in the buffer and can be read with AREAD$. No further interrupts are created if data arrives from that port.

Examples:

OFF INPUT #12
.
.
.
Device=12
.
.
OFF INPUT #Device

The AOVFL function

AOVFL (port number)

returns 1 if the TIO buffer has overflowed, otherwise 0. AREAD$ resets the buffer flag.


Eloquence Language Manual - 19 DEC 2002