Receive

PURPOSE:  The RECEIVE command is used to accept special device responses and controls from the terminal.  Such responses could be status information sent automatically by video display terminals when asked to identify themselves, or special sequences transmitted by devices when operating.  This command can also be used as a statement in a Process Module.  The ACCEPT command (or statement) should be used for normal terminal input.

A carriage return on OpenVMS generates just a carriage return.  No line feed character is included.  For applications that RECEIVE terminal input and test for a carriage return, note that the character after a carriage return is valid input.

Syntax

RECEIVE {NORMAL;ASCII;BYTE} [ECHO] TO dest1

[WAIT ae1/SECOND/S//;COUNT TO dest2;MAX ae2{/CHARS/; /CHARACTERS/; /BYTES/}]]

NORMAL

permits the receipt of only the 95 printing ASCII characters and the codes Control-M (return), Control-J (line feed), Control-I (tab), Control-P (backspace), Control G (bell), Control-Shift-K (escape), and Delete.

The following characters are unaffected by RECEIVE: Control-C, Control-O, Control-Q, Control-S, and Control-T.

All other characters are discarded on input.

ASCII

permits the receipt of all ASCII codes except a null.

BYTE

receives all 8-bit numeric codes (including a null).

ECHO

causes received characters to be sent back to the sending terminal.  This clause is not recommended for use because such characters reflected back to the originator may cause device problems.  BYTE mode is cannot be ECHOed.

TO dest1

specifies where the terminal responses are to be stored.  It may be a character data field defined without an OCCURS clause, or a binary integer or bit data field optionally defined with a single dimension OCCURS clause.  A subscript may not be specified on dest1; data objects input are stored at the beginning of a character field from left to right, and are stored in the rightmost 7 (or 8 if BYTE mode) bits of a binary integer or bit data element.  A bit element size must be at least 7 bits.  BYTE mode may not be used for input to a character field.

WAIT ae1

specifies the maximum time that RECEIVE will input from the terminal line.  The expiration of the wait time, which is partitioned into 34 millisecond segments, completes the execution of the statement.  Thus, with judicious use of the WAIT clause, an application can be assured of not hanging due to an insufficient amount of data input.  The default time is machine infinity (i.e., RECEIVE will wait until some other terminating condition occurs, such as fulfillment of the specified number of data objects input).  The wait time can be a single number or a fraction such as .25 or 1./4.

COUNT TO dest2

specifies where the count of the number of data objects input is to be placed.  The value in dest2 can easily be used with various string functions to delimit the received data; it also ideally serves as an upper loop limit for examining data received to a binary integer or bit single-dimensional array.  Note that if no data was received, due to the expiration of a WAIT time, the value will be zero.  Thus, it is best to always use a COUNT TO clause with a WAIT clause.

MAX ae2

specifies the maximum number of integer ae2 data objects that will be accepted and placed into dest1.  The default number of objects is one of the following:

The declared length of a character field.  Such a character field cannot be defined with an OCCURS clause.  Only as many characters will be stored in the field as were received, which is again why a COUNT TO clause should always be used.

One object is stored per binary I data word occurrence.  Each object received will be placed in the rightmost 7 (or 8 if BYTE mode) bits of each machine word.

One object is stored per bit element.  A bit element size must be at least 7 bits.

EXAMPLE

This example allows the user to check if the terminal can use VT300 cursor codes.

10  DECLARE SECTION
20    ATTEXT, INT, 2, OCCURS 14
30    RCVCNT, INT, 3
40  DETAILS SECTION
50    TRANSMIT ASCII FROM @ESC + "[" + "c"
60    RECEIVE ASCII TO ATTEXT WAIT 1 SECOND COUNT TO RCVCNT
70    TYPE "VT300 Terminal" IF (ATTEXT(3) = 62 OR ATTEXT(3)=63)
80    TYPE "VT100 Terminal" IF ATTEXT(3) = 61

Sending a CSI (Control Sequence Introduce) followed by a "c" (or 0 and "c") causes the terminal to respond with a terminal type identification.

Primary Device Attributes

RESPONSE

TERMINAL TYPE

Operating level:

61

Level 1 - VT100 family

62, 63

Level 3 - VT300 family

Attribute extensions are also given - see terminal manual for meanings.

Alias Primary DA Responses from VT300.

Response

Terminal Type

ESC [ ? 1; 2 c

VT100 DA

ESC [ ? 1; 0 c

VT101 DA

ESC [ ? 6 c

VT102 DA

ESC [ ? 12; 7; 1; 10; 102 c

VT125 DA

ESC [ ? 7 c

VT131 DA

CSI ? 62; 1; 2; 6; 7; 8; 9 c

VT220 DA

CSI ? 62; 1; 2; 3; 4; 6; 7; 8; 9 c [

VT240 DA

Secondary device attributes - in response to sending CSI > c (or) CSI > 0 c

Response            Terminal Type

Id Code (firmware version and ROM cartridge registration is sent, too.)

18 VT330

19 VT340

NOTES:  A data field destined to receive input from the RECEIVE command should be large enough to contain any possible expected transmission from a device.  The completion of a given RECEIVE (due to either time expiring or the maximum number of data objects already accepted) will cause additional input to be left in the terminal input buffer, which may confuse either another RECEIVE or an ACCEPT.

If the MAX ae2 evaluates to a zero or negative value, nothing will be received.  If the MAX ae2 evaluates to a value greater than the length of dest1, the default length of dest1 will be used instead.

In NORMAL and ASCII modes, if only a sole carriage return is physically received, the monitor will return a carriage return and a line feed irrespective of whether ECHO was specified or not.  The best way to RECEIVE is with BYTE (for which echoing can be simulated by a TRANSMIT immediately following the RECEIVE).  (See note below about carriage returns in BYTE mode.)

In ASCII mode, a null cannot be input, as the monitor does not accept it.  In NORMAL mode a null is not a valid character, so there is no problem.  Use BYTE mode if nulls are required (null = ASCII code 000).

A carriage return on OpenVMS generates just a carriage return.  No line feed character is included.  For applications that RECEIVE terminal input and test for a carriage return, note that the character after a carriage return is valid input.

For either NORMAL or ASCII modes with ECHO, if a Control-Z (ASCII code 32 octal, 26 decimal, 1A hexadecimal) is input, the Control-Z echoed back may cause serious problems with certain terminals and/or devices, since it is the CAN character.  This is another reason why ECHO should not be specified on a RECEIVE.

SEE ALSO:  VT330/VT340 Programmer Pocket Guide