13 Asynchronous Devices
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:
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
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.
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
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.
OFF INPUT #12 . . . Device=12 . . OFF INPUT #Device
returns 1 if the TIO buffer has overflowed, otherwise 0. AREAD$ resets the buffer flag.