You can use LPRINT in an OPL program to send information (for printing or otherwise) to any of these devices:
OPL does not provide access to the advanced page formatting and font control features of the Series 3a.
In your OPL program, set up the port with the statement "LOPEN "PAR:A"".
Provided the port is not already in use, the connection is now ready. LPRINT will send information down the parallel 3 Link lead for example, to an attached printer.
PROC prints: OPEN "clients",A,a$ LOPEN "PAR:A" PRINT "Printing..." DO IF LEN(A.a$) LPRINT A.a$ ENDIF NEXT UNTIL EOF LPRINT CHR$(12); :LCLOSE PRINT "Finished" :GET ENDP
In your OPL program, set up the port with the statement "LOPEN "TTY:A"".
Now LPRINT should send information down the serial 3 Link lead for example, to an attached printer. If it does not, the serial port settings are not correct.
"LOPEN "TTY:A"" opens the serial port with the following default characteristics:
9600 baud
no parity
8 data bits
1 stop bit
RTS handshaking.
Calling the procedure The "rsset:" procedure listed below provides a convenient way to set up the serial port.
Each time you use an "LOPEN "TTY: "" statement, follow it with a call to the "rsset:" procedure. Otherwise "the" LOPEN will use the default characteristics.
Passing values to the procedure Pass the procedure the values for the five port characteristics, like this:
rsset:(baud%,parity%,data%,stop%,hand%,&0)
Baud = 50 75 110 134 150 300 600 1200 value = 1 2 3 4 5 6 7 8The "rsset:" procedure:1800 2000 2400 3600 4800 7200 9600 19200 9 10 11 12 13 14 15 16
Parity = NONE EVEN ODD value = 0 1 2
Data bits = 5, 6, 7 or 8
Stop bits = 2 or 1
Handshaking = ALL NONE XON RTS XON+RTS DSR XON+DSR RTS+DSR value = 11 4 7 0 3 12 15 8
PROC rsset:(baud%,parity%,data%,stop%,hand%,term&) LOCAL frame%,srchar%(6),dummy%,err% frame%=data%-5 IF stop%=2 :frame%=frame% OR 16 :ENDIF IF parity% :frame%=frame% OR 32 :ENDIF srchar%(1)=baud% OR (baud%*256) srchar%(2)=frame% OR (parity%*256) srchar%(3)=(hand% AND 255) OR $1100 srchar%(4)=$13 POKEL ADDR(srchar%(5)),term& err%=IOW(-1,7,srchar%(1),dummy%) IF err% :RAISE err% :ENDIF ENDP
Take care to type this program in exactly as it appears here.
Example of calling the procedure
PROC test: PRINT "Testing port settings" LOPEN "TTY:A" LOADM "rsset" rsset:(8,0,8,1,0,&0) LPRINT "Port OK" :LPRINT PRINT "Finished" :GET LCLOSE ENDP
"rsset:(8,0,8,1,0,&0)" sets 1200 Baud, no parity, 8 data bits, 1 stop bit, and RTS/CTS handshaking.
Advanced use
The section of the "rsset:" procedure which actually sets the
port is this:
srchar%(1)=baud% OR (baud%*256) srchar%(2)=frame% OR (parity%*256) srchar%(3)=(hand% AND 255) OR $1100 srchar%(4)=$13 POKEL ADDR(srchar%(5)),term& err%=IOW(-1,7,srchar%(1),dummy%) IF err% :RAISE err% :ENDIFThe elements of the array "srchar%" contain the values specifying the port characteristics. If you want to write a shorter procedure, you could work out what these values need to be for a particular setup you want, assign these values to the elements of the array, and then use the IOW function (followed by the error check) exactly as above.
If you need to read from the serial port, you must also pass a parameter specifying terminating mask for the read function. If "term&" is not supplied, the read operation terminates only after reading exactly the number of bytes requested. In practice, however, you may not know exactly how many bytes to expect and you would therefore request a large maximum number of bytes. If the sender sends less than this number of bytes altogether, the read will never complete.
The extra parameter, "term&" , allows you to specify that one or more characters should be treated as terminating characters. The terminating character itself is read into your buffer too allowing your program to act differently depending on its value.
The 32 bits of "term&" each represent the corresponding ASCII character that should terminate the read. This allows any of the ASCII charcaters 1 to 31 to terminate the read.
For example, to terminate the read when Control-Z (ie. ASCII 26) is
received, set bit 26 of "term&". To terminate on Control-Z or
"
0000 0100 0000 0000 0010 0100 0000 0000
Converting to a long integer gives &04002400 and this is the value
to be passed in "term&" for this case.
This example assumes that each line sent has maximum length 255 characters
and is terminated by a "
As if you were going to transfer a file:
LOPEN "REM::C:\BACKUP\PRINTOUT\MEMO.TXT"
Any subsequent LPRINT would go to the file "MEMO.TXT" in
the directory "\BACKUP\PRINTOUT" on the PC's drive "C:".
With a Macintosh, you might use a file specification like this:
LOPEN "REM::HD40:MY BACKUP:PRINTED:MEMO5"
An LPRINT would now go to the file "MEMO5" in the "PRINTED"
folder, itself in the "MY BACKUP" folder on the hard drive "HD40".
Note that colons are used to separate the various parts of the file
specification.
In your OPL program, specify the destination file with an LOPEN
statement like this:
LOPEN "B:\PRINT\MEMO.TXT"
This would send each subsequent LPRINT to the file "MEMO.TXT"
in the "\PRINT\" directory on an SSD in drive B:.
Example reading from serial port
PROC testread:
LOCAL ret%,pbuf%,buf$(255),end%,len%
PRINT "Test reading from serial port"
LOPEN "TTY:A"
LOADM "rsset"
REM receive at 2400 without h/shake
rsset:(11,0,8,1,0,&04002000) REM Control-Z or CR
pBuf%=ADDR(buf$)
DO
REM read max 255 bytes, after leading count byte
len%=255
ret%=IOW(-1,1,#UADD(pbuf%,1),len%)
POKEB pbuf%,len% REM len% = length actually read
REM including terminator char
end%=LOC(buf$,CHR$(26)) REM non-zero for Control-Z
IF ret%<0 and ret%<>-43
BEEP 3,500
PRINT
PRINT "Serial read error: ";ERR$(ret%)
ENDIF
IF ret%<>-43 REM if received with terminator
POKEB pbuf%,len%-1 REM remove terminator
PRINT buf$ REM echo with CRLF
ELSE
PRINT buf$; REM echo without CRLF
ENDIF
UNTIL end%
PRINT "End of session" :PAUSE -30 :KEY
ENDP
Printing to a file
Printing to a file on a PC or Apple Macintosh
In your OPL program, specify the destination file with an LOPEN
statement. For example, to a PC:
Printing to a file on the SERIES 3a
Return to the Index