HPlogo Asynchronous Serial Communications Programmer's Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 6 Typeahead Mode

Programming for Typeahead Mode

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Glossary

 » Index

To programmatically set and control typeahead mode you use the FDEVICECONTROL intrinsic, specifying one of three control directives in the parm1 value.

  • A control directive of 51 is used to specify whether or not typeahead mode is on for the device. Use this call with the buffer parameter set to 1 to enable typeahead mode, or with the buffer parameter set to 0 to disable typeahead mode (parm2 set to 2 or 3).

  • A control directive of 60 allows you to discard any data in the typeahead buffer and read directly from the device.

  • A control directive of 61 allows you to bypass the typeahead buffer for the next read while saving the data already in the typeahead buffer.

  • A control directive of 63 is used to enable or disable single echo typeahead. Use this call with the buffer parameter set to 1 to enable typeahead mode, or with the buffer parameter set to 0 to disable single echo typeahead mode (parm2 set to 2 or 3).

The code fragments that follow illustrate how these calls might look in your program.

NOTE: When typeahead is enabled it is enabled for the device and not specifically for an application. It is a good practice to make sure that any program that enables typeahead mode also restores the terminal's previous typeahead setting before it terminates. To do so, your program should save the value of the device's current typeahead setting. This is obtained either through a separate call to FDEVICECONTROL with a control directive of 51 and parm2 set to 1 (Read access), or through the call which changes the setting, with parm2 set to 3 (Read/Write access). When your program is ready to end execution, it will be able to return the device to its original typeahead setting through another FDEVICECONTROL call, using the value of the previous setting obtained in the first call as the value of buffer.

Setting Typeahead Mode

The code fragment shown in Figure 6-1 “Program Fragment Setting Typeahead Mode” illustrates how you can use the FDEVICECONTROL intrinsic to allow typeahead processing for your program. A control directive of 51, set typeahead mode, is passed in parm1, and parm2 is set to 2 to specify Write access. The buffer parameter contains a variable called value, set to 1 in this example, which will cause typeahead mode to be enabled. (A value of 0 would disable typeahead mode.)

In this example, the Pascal/iX ccode function checks for errors that might occur during execution of the intrinsic. If an error occurs, the program reports the file system error number associated with the error. If no errors occur, the program informs the user that typeahead is now on.

Figure 6-1 Program Fragment Setting Typeahead Mode

Program Fragment Setting Typeahead Mode

Flushing the Typeahead Buffer

Figure 6-2 “Program Fragment to Flush Buffer” illustrates how FDEVICECONTROL can be used to flush the typeahead buffer. For example, the buffer can be flushed if an error is detected in the data that was typed ahead. This FDEVICECONTROL is only valid if type ahead is enabled. The default is not to flush the typeahead buffer.

An FDEVICECONTROL call with a control directive of 60 will cause the buffer to be flushed at the time of the next read. The read can then be satisfied by data entered directly from the device. The typeahead buffer is flushed for a single read only; normal typeahead mode processing will resume for any following reads.

In the example, the parm1 value is set to 60, flush typeahead buffer, and the buffer parameter (value) passes a value of 1. This specifies that all data currently in the typeahead buffer should be discarded, and the next read should access the device directly. Write access is specified in parm2, and the program checks for errors using the Pascal/iX ccode function.

Figure 6-2 Program Fragment to Flush Buffer

Program Fragment to Flush Buffer

Bypassing the Typeahead Buffer

Figure 6-3 “Program Fragment to Bypass Buffer” is an example of using FDEVICECONTROL to bypass the typeahead buffer. You could use this capability to send a status request and obtain a reply directly from a terminal without affecting the data already in the typeahead buffer. This FDEVICECONTROL is only valid if typeahead is enabled. The default is not to bypass the typeahead buffer.

This FDEVICECONTROL call will cause the typeahead buffer to be bypassed for a single read only; normal typeahead mode processing will resume for any following reads, and data will be taken from the typeahead buffer if data is present.

When you use this request, you call FDEVICECONTROL with parm1 set to 61, bypass typeahead mode, and pass a value of 1 in the buffer parameter (value :=1). As in the previous examples, Write access is specified in parm2, and the Pascal/iX ccode function is used for error checking.

NOTE: In cases where there is no read trigger (read trigger set to null) bypassing the typeahead buffer may have unexpected results. If, for example, your program is swapped out between the FWRITE and FREAD of a terminal status request, the terminal may appear to become "hung", since there is no read trigger to synchronize terminal response with the posting of the read.

To avoid this problem, instead of bypassing the typeahead buffer to send a status request when no read trigger is present, the following should be the sequence that occurs:

  1. = Disable typeahead mode

  2. = Post a 0 byte read

  3. = Enable typeahead mode

  4. = (Lock keyboard) (FWRITE) Send status request

  5. = FREAD of status

  6. = FWRITE (unlock keyboard)

Figure 6-3 Program Fragment to Bypass Buffer

Program Fragment to Bypass Buffer
Feedback to webmaster