User`s guide

Serial I/O Examples
The first example attaches to a serial line and performs simple WRITEs and READs on the
line:
.PROGRAM serial.io()
; ABSTRACT: Example program to write and read lines of
; text to and from serial port 1 on the SIO module.
AUTO slun ;Logical unit to communicate to serial port
AUTO $text
; Attach to a logical unit(open communications path
; to serial port)
ATTACH (slun, 4) "SERIAL:1"
IF IOSTAT(slun) < 0 GOTO 100
; Write text out to the serial port
WRITE (slun) "Hello there! "
IF IOSTAT(slun) < 0 GOTO 100
; Read a line of text from the serial port. The incoming
; line of text must be terminated by a carriage return and
; line feed. The READ instruction will wait until a line of
; text is received.
READ (slun) $text
IF IOSTAT(slun) < 0 GOTO 100
; Display any errors
100 IF (IOSTAT(slun) < 0) THEN
TYPE IOSTAT(slun), " ", $ERROR(IOSTAT(slun))
END
DETACH (slun) ;Detach from logical unit
.END
The next example reads data from a serial line using the GETC function with no-wait mode.
Records that are received are displayed on the terminal. In this program, data records on the
serial line are assumed to be terminated by an ETX character, which is not displayed. An
empty record terminates the program.
.PROGRAM display()
; ABSTRACT: Monitor a serial line and read data when
; available
AUTO $buffer, c, done, etx, ienod, line
etx = 3 ;ASCII code for ETX character
ienod = -526 ;Error code for no data
ATTACH (line, 4) "SERIAL:1"
IF IOSTAT(line) < 0 GOTO 90 ;Check for errors
Serial Line I/O
(Undefined variable: Primary.Product_Name_V)Language User's Guide, version
17.x
Page 225