Serial Line I/O .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 $buffer = "" ;Initialize buffer to empty done = FALSE ;Assert not done DO CLEAR.EVENT c = GETC(line,1) ;Read byte from the ser. line eV+Language User's Guide, v2.x, 18318-000 Rev A Page 154