The Open Command


The OPEN command, code 00, establishes a link between the RPD-95 and the device. It also enables you to specify various file and device options.


Information Needed for the Data Buffer

Before sending an Open command, you must place the following information into the data buffer.
  • Requested I/O buffer size (2 bytes, LSB first)
    Specifies the maximum length of any data you want to receive from the device. (You can specify 0000 to request the device's default value.)

  • Device attributes (1 byte )
    Specifies the access mode and the type of file you wanto to open. Refer to the next "Device Attributes" section below for information concerning device attributes and how to determine the correct value for this byte.

  • Device options (if any; length varies accordingly)
    Specifies any device-dependent options that may be available on your device.

Device Options

Some devices allow you to use various device options, which are usually given as a string of alphanumeric characters. To specify one of these options, use the ASCII code for each character.

On some printers, for example, the string "L=D" causes the printer to use double-spacing. The ASCII codes for these character are shown here as hex numbers.

Character :  L  =  D
Hex code  : 4C 3D 44

To specify this option, store 4C3D44 in the appropriate bytes of the data buffer (4C in the fourth byte, 3D in the fifth byte, and 44 in the sixth byte).

Device Attributes

To determine the value for the device attributes byte in the data buffer, you must first know the access mode and, if applicable, the type of file you want to open. You can then use the following table.

Bit #

Description


7,600-append mode (write only at end of file)
01-input mode (read only)
10-output mode (write only)
11-append mode (read or write)

50-sequential records
1-relative records

40-variable record length
1-fixed record length

30-display file
1-internal file

2,1,0always zero


For each bit, fill in the applicable digit, 0 or 1. Then determine the value of the byte. (If the device does not support files, specify only bits 7 and 6 and use zeros for bits 5-0.)

For example, the following device attributes byte would be used when opening a device for updating a file with the attributes display, variable, and sequential. The bit pattern ( 11000000 ) is equivalent to the hex value C0.
devattrib

Parameters in the PAB

The PAB for an Open command should include the following parameter values.
  • Buffer Size
    Enter a least 0004. (The device always returns four bytes of information in response to the command.)

  • Data Length
    Enter at least 003. If you are specifying any device options, be sure to increase this value accordingly.

After You Send the Command

After you send an Open command, the device compares the I/O buffer size you requested in your data with its own capabilities. It then responds to the command and returns four bytes of information to the data buffer, writing over the data you sent.
  • Accepted I/O buffer size ( 2 bytes )
  • Record number ( 2 bytes )

The accepted I/O buffer size is the device's response to your requested size. If the size you requested is acceptable, the device returns that value as confirmation. If you requested 0000, the device returns its default size. You can then use that value in the buffer-size field of PABs for other commands.

The record number specifies the current record in the device. (This is used only by devices that allow relative files; other devices always return 0000.)

If a condition such as a low battery or an unacceptable buffer size causes the device to return any error, the device is not opened. If the device was already open, it returns I/O error 5 (already open). In this case, the device remains open but ignores parameters and data you sent.

Back