Operating Safety Precautions
Chapter 7 FILE INPUT/OUTPUT OPERATIONS
7.3 OPEN FILE STATEMENT
7.3.1 Setting File and Port Attributes
Attributes specify the details of operation of a serial port, or KAREL FILE variable. The SET_PORT_ATR and SET_FILE_ATR built-ins are used to set these attributes. SET_FILE_ATR must be called before the FILE is opened. SET_PORT_ATR can be called before or after the FILE that is using a serial port, is opened.
Table 7–2lists each attribute type, its function and whether the attribute is intended for use with teach pendant and CRT/KB devices, serial ports, data files, or pipes. Refer toAppendix Afor more information.
Table 7–2. Predefined Attribute Types
ATTRIBUTE TYPE FUNCTION SET_PORT_ATR OR SET_FILE_ATR
ATR_BAUD Baud rate SET_PORT_ATR not used valid not
used not used
not used
ATR_DBITS Data length SET_PORT_ATR not used valid not
used not used
not used
ATR_EOL End of line SET_FILE_ATR not used valid not
used
valid valid
ATR_FIELD Field SET_FILE_ATR valid valid valid valid valid
ATR_IA Interactively
write
SET_FILE_ATR valid valid valid valid valid
ATR_MODEM Modem line SET_PORT_ATR not used valid not
used not used
not used
ATR_PARITY Parity SET_PORT_ATR not used valid not
used not used
not used
ATR_PASSALL Passall SET_FILE_ATR valid valid not
used
valid valid
ATR_READAHD Read ahead buffer
SET_PORT_ATR not used valid not used
SET_FILE_ATR not used valid valid valid valid
ATR_SBITS Stop bits SET_PORT_ATR not used valid not
used not used
not used
ATR_TIMEOUT Timeout SET_FILE_ATR valid valid not
used
valid valid
ATR_UF Unformatted
transfer
SET_FILE_ATR not used valid valid valid valid
7. FILE INPUT/OUTPUT OPERATIONS MARRC75KR07091E Rev H
Table 7–2. Predefined Attribute Types (Cont’d)
ATTRIBUTE TYPE FUNCTION SET_PORT_ATR OR SET_FILE_ATR
ATR_XONOFF XON/XOFF SET_PORT_ATR not used valid not
used
SET_FILE_ATR not used not used
not used
valid valid
ATR_PIPWAIT Wait for data SET_FILE_ATR not used not used
not used
valid valid
Table 7–3contains detailed explanations of each attribute.
Table 7–3. Attribute Values
Attribute Type Description Valid Device Usage Mode Valid Values Default Value ATR_BAUD
Baud rate
The baud rate of a serial port can be changed to one of the valid attribute values.
PORT Read/ Write BAUD_9600:
9600 baud
If specified, the data length for a serial port is changed to the specified attribute values.
PORT Read/ Write DBITS_5: 5 bits DBITS_6: 6 bits
If specified, the serial port is changed to terminate read when the specified attribute value. Refer to Appendix D, for a listing of valid attribute values.
PORT Read/ Write Any ASCII character code
13 (carriage return)
ATR_FIELD Field
If specified, the amount of data read depends on the format specifier in the READ statement, or the default value of the data type being read. If not specified, the data is read until the terminator
TP/CRT, PORT, FILE
Read only Ignored Read data until terminator character (EOL) appears
MARRC75KR07091E Rev H 7. FILE INPUT/OUTPUT OPERATIONS
Table 7–3. Attribute Values (Cont’d)
Attribute Type Description Valid Device Usage Mode Valid Values Default Value ATR_IA
Interactively write
If specified, the contents of the buffer are output when each write operation to the buffer is complete.
(Interactive) If not specified, the contents of the buffer are output only when the buffer becomes full or when CR is specified.
The size of the output buffer is 256 bytes. (Not interactive)
TP/CRT, PORT, FILE
Write only Ignored TP/CRT is interactive, PORT, FILE are not interactive
ATR_MODEM Modem line
Refer to "Modem Line"
section that follows for information.
ATR_PARITY Parity
The parity for a serial port can be changed to one of the valid attribute values.
PORT Read/ Write PARITY_NONE:
No parity
If specified, input is read without interpretation or transaction. Since the terminator character (EOL) will not terminate the read, the field attribute automatically assumes the “field” option.
TP/CRT, PORT Read only Ignored Read only the displayable keys until enter key is pressed
ATR_PIPOVADV Configures the behavior of the read when an overflow occurs. By default the behavior is to signal an end of file (EOF) when the overflow occurs.
PIPE Read The value must
be between 0 and the total number of bytes in the pipe. The value will be number of bytes to advance when an overflow occurs.
7. FILE INPUT/OUTPUT OPERATIONS MARRC75KR07091E Rev H
Table 7–3. Attribute Values (Cont’d)
Attribute Type Description Valid Device Usage Mode Valid Values Default Value ATR_PIPWAIT The read operation waits
for data to arrive in the pipe.
PIPE Read WAIT_USED or
WAIT_NOTUSED
The default is snapshot which means that the system returns an EOF when all the data in the pipe has been read.
ATR_READAHD Read Ahead Buffer
The attribute value is specified in units of 128 bytes, and allocates a read ahead buffer of the indicated size.
PORT Read/ Write any positive integer 1=128 bytes 2=256 bytes 0=disable bytes
1 (128 byte buffer)
ATR_REVERSE Reverse transfer
The bytes will be swapped.
PORT, FILE Read/ Write Ignored Not reverse transfer
ATR_SBITS Stop bits
This specifies the number of stop bits for the serial port.
PORT Read/ Write SBITS_1:1 bit SBITS_15: 1.5
If specified, an error will be returned by IO_STATUS if the read takes longer than the specified attribute value.
TP/CRT, PORT Read only Any integer value (units are
If specified, a binary transfer is performed.
For read operations, the terminator character (EOL) will not terminate the read, and therefore automatically assumes the “field” option. If not specified, ASCII transfer is performed.
PORT, FILE Read/ Write Ignored ASCII transfer
ATR_XONOFF XON/XOFF
If specified, the XON/XOFF for a serial port is changed to the specified attribute value.
PORT Read/ Write XF_NOT_USED:
Not used XF_USED: Used
XF_USED
Modem line
MARRC75KR07091E Rev H 7. FILE INPUT/OUTPUT OPERATIONS
Usage mode : Read/Write
Default value : MD_NOT_USED: DSR, DTR, and RTS not used Valid attribute values : MD_NOT_USED: DSR, DTR, and RTS not used MD_USE_DSR: DSR used
MD_NOUSE_DSR: DSR not used MD_USE_DTR: DTR used MD_NOUSE_DTR: DTR not used MD_USE_RTS: RTS used
MD_NOUSE_RTS: RTS not used
• This attribute controls the operation of the modem line. The control is based on the following binary mask, where the flag bits are used to indicate what bit value you are changing.
RTS value DSR value DTR value RTS flag DSR flag DTR flag
— RTS (request to send) and DTR (data terminal ready) are both outputs.
— DSR (data set ready) is an input.
• Set the modem line attribute by doing the following.
— To indicate RTS is used (HIGH/ON): status = SET_PORT_ATR (port_name, ATR_MODEM, MD_USE_RTS)
— To indicate RTS is NOT used (LOW/OFF):status = SET_PORT_ATR (port_name, ATR_MODEM, MD_NOUSE_RTS)
— To indicate RTS is used (HIGH/ON) and DTR is not used (LOW/OFF):status = SET_PORT_ATR (port_name, ATR_MODEM, MD_USE_RTS or MD_NOUSE_DTR)
• The following examples demonstrate how to use the returned attribute value from the GET_PORT_ATR built-in.
status = GET_PORT_ATR (port, ATR_MODEM, atr_value)
— To determine if DTR is used:
IF ((atr_value AND MD_USE_DTR) = MD_USE_DTR) THEN write ('DTR is in use',cr)
ENDIF
7. FILE INPUT/OUTPUT OPERATIONS MARRC75KR07091E Rev H
— To determine if DTR is not used (LOW/OFF)
IF (atr_value AND MD_USE_DTR) = MD_NOUSE_DTR) THEN write ('DTR is not in use', cr) ENDIF
For more information on GET_PORT_ATR Built-in, refer toAppendix A.