REM Very simple async terminal for Series 3x. REM you can test this with Windows terminal or similar. PROC terminal: GLOBAL buf$(255),text$(255),k%(2) GLOBAL sfg%,ser%,evnt%,rdser%,rdevnt% LOCAL ret%,c% TRAP LOPEN("TTY:A") IF ERR=-40 ret%=ALERT("Link in use.") REM you can put code here to close link before trying REM to open serial port again. STOP REM close link code not present! ELSEIF ERR<>0 ret%=ALERT("Serial Port problem:",ERR$(ERR)) STOP ENDIF set232:(15,0,8,0) REM 9600, no parity, 8bit, RTS/CTS REM you must not have more than 1 IOA to the same device outstanding, so REM rdevnt% and rdser% prevent this from happening. rdevnt%=1 REM set flag to allow event read to be set up. rdser%=1 REM likewise for serial read. text$="" buf$="" PRINT "Press Psion-X to quit." DO REM If no serial read is oustanding, REM queue an async read for 1 byte. c%=1 IF rdser%=1 IOA(-1,1,ser%,#UADD(ADDR(buf$),1),c%) rdser%=0 REM this flags a serial read has been set up. ENDIF REM If no event read is outstanding, REM set up an async read for one keyboard or system event. REM This is an async version of GETEVENT. IF rdevnt%=1 IOA(-2,14,evnt%,k%(1),#0) rdevnt%=0 REM this flags an event read has been set up. ENDIF IOWAIT REM wait for a serial, keyboard, or system event. REM ser% will remain at -46 until a byte has been received. REM So if it is not -46, at least one byte received. IF ser%<>-46 rdser%=1 REM set flag so that another serial read can be set up later. c%=1 REM number of bytes to read = 1 POKEB ADDR(buf$),c% REM set buf$ to 1 char length. PRINT buf$; IOW(-1,10,c%,#0) REM checks how many serial bytes waiting to be read. REM This next line limits the next IOW to read 80 chars REM c% should be less than the buf$ size. REM If you don't read all the bytes, the rest will be read next time round... IF c%>80 :c%=80 :ENDIF IF c%>0 REM If one or more bytes waiting... IOW(-1,1,#UADD(ADDR(buf$),1),c%) REM read c% bytes. POKEB ADDR(buf$),c% PRINT buf$; ENDIF ENDIF REM Now check if any keyboard or system events have been received. IF evnt%<>-46 REM not -46, therefore something has happened. rdevnt%=1 REM set flag to allow another read later. IF k%(1)=$404 REM shutdown from system screen. REM put tidy up code here. LCLOSE STOP ELSEIF k%(1)>512 REM Psion+key command pressed REM deal with command here like next line: docmd:(k%(1)-512) ELSEIF k%(1)<$400 REM normal key (or shifted or control) pressed. REM deal with keypress here, like next line: dotxt$:(k%(1)) ENDIF ENDIF UNTIL 0 ENDP PROC set232:(baud%,parity%,data%,hand%) REM This procedure (c/o Psion UK) is in the OPL programming manual. REM Sets up RS232 port. LOCAL srchar%(6),dummy%,r%,frame% frame%=data%-5 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 IOW(-1,7,srchar%(1),dummy%) ENDP PROC dotxt$:(char%) REM saves keys pressed into text$, and sends this REM to the serial port when Enter is pressed. REM NOTE that there is no check for overflow of text$ !! LOCAL c%,p% c%=1 CURSOR 1 IF char%=8 REM deal with delete key. ELSEIF char%=291 REM deal with help key. ELSEIF char%<>13 AND char%<256 REM ascii character. text$=text$+CHR$(char%) REM build up string to send... PRINT CHR$(char%); REM print character to screen ELSEIF char%=13 REM Enter pressed. REM send text$ to serial port. text$=text$+CHR$(13) REM add CR if necessary. sendtxt: ENDIF ENDP PROC sendtxt: REM sends text$ to serial port. LOCAL c% : rem holds length of text$ c%=LEN(text$) REM The following MAY be required. They will cancel REM an outstanding serial read, before a serial send. REM They MAY prevent corruption of echoed data, if this occurs. REM IOCANCEL(-1) REM rdser%=1 REM If sfg% is -46, then the last send has not yet completed. REM Probably something wrong!! IF sfg%<>-46 REM If it's not -46, we can send another string. IOA(-1,2,sfg%,#UADD(ADDR(text$),1),c%) : rem send bytes to RS232 text$="" REM clear string ELSE REM last string not sent yet... BEEP 1,1000 gIPRINT "TX Error!" ENDIF ENDP PROC docmd:(comd%) REM Deals with Psion modified keys... IF comd%=%x dINIT "Quit?" dBUTTONS "No",-27,"Yes",13 IF dIALOG LCLOSE STOP ENDIF ENDIF ENDP