Performing an I/O Operation from a Program


In most cases, you need to perform an I/O operation from within a program. This section describes the steps involved in using CIO in a program.


General Program Sequence

The steps generally required for a program that performs an I/O operation are:
  1. Build the PAB and, if necessary, load the data buffer.
  2. Execute the CIO function to send the command.
  3. Test the returned status and, if applicable, read the data from the data buffer.

Choosing Data Registers

Before writing the program, you should decide which data registers you want to use for the PAB, the data buffer, and any variables needed by the program.
  • The PAB requires two consecutive data registers.
    Because the program uses only one PAB at a time, you can build the PAB for each command using the same two registers.
  • The data buffer must be large enough to store the largest piece of information that you want to send to or receive from the device. For convenience, you should begin the buffer at the beginning of a register.
  • The variables in the program can use any data registers that are not used by the PAB or the data buffer.

Although you can use any data registers for the information used by the program, you may want to use a sequence of registers. One possible way of arranging the information is shown below.

pabchoose

Building the PAB

You must begin a PAB in the first byte of a register. Because a PAB contains 12 bytes of information, you need to store it in two consecutive registers.

When entering values into a PAB, you should follow two general rules.
  • If the device ignores a particular parameter, enter zeros for that parameter.
  • If a parameter occupies two bytes, enter the LSB first.
    For example, the parameter value 0050 should be entered as 5000.

To build the PAB, use the following procedure.
  1. Select the unformatted display mode.
  2. Enter the first eight bytes (16 hex digits) of the PAB into the display.
  3. Use the [ STO ] key to store the first eight bytes.
  4. Enter the remaining four bytes into the display. (The last four bytes of the second register are ignored.)
  5. Use the [ STO ] key to store the last four bytes of the PAB in the next consecutive register.
    For example, in the illustration above, the first eight bytes of the PAB are in register G, while the last four bytes are in register H.

Using the CIO Function

After building the PAB and storing any applicable information in the data buffer, you can then use the CIO function to send your I/O command to the device.
  1. Press [ I/O ] to display the INPUT/OUTPUT menu.
    D_yraFMd
  2. Press { CIO }.
  3. Enter the register number that contains the first eight bytes of the PAB.

The calculator then sends the I/O command to the device.

Testing the Returned Status

There are several ways you can determine the success or failure of an I/O command after sending it. The method depends on whether you issued the command from the keyboard, or from within a program.
  • When you use CIO from the keyboard, any I/O error causes the calculator to display an error message specifying the error code.
  • When you use CIO from within a program, no error message is displayed unless you halt or pause the program. The calculator does, however, place the returned status byte in the numeric display register. Your program can read this value to determine if an error occurred.
  • Regardless of whether you use CIO from the keyboard or from within a program, your PAB will contain the returned status byte. You can use the RCB function to recall the byte. (Keep in mind that you can use the RCB function only after removing system protection.)


Back