10 REM *** 20 REM Use F4-CP128-1 as a Simple Optomux Master 30 REM 40 REM Use command M to Read 16 Discrete Inputs from address 0 and put in C0-C17 50 REM Use command L to Read 4 Analog Inputs from address 1 and put in V1400-V1403 60 REM Use command J to Write 16 Discrete Outputs to address 2 from C20-C37 70 REM 80 REM 90 REM Baud Rate = 1200 (BAUD) 100 REM Wait for First = 100 ms (WFF) 110 REM Wait for Last = 3.5 Character Times ((1/BAUD)*10*3.5) 120 REM Optomux Master Port = 2 125 REM ND=On Delay, FD=Off Delay, For Radio Communications 130 REM 140 REM *** 150 REM Allocate String Space and Configure Port 2 160 STRING 2561,255 162 RA=1 : BAUD=9600 : WFF=100 : WFL=30 170 SETPORT 2,BAUD,N,8,1,N 175 SETPORT 1,9600,N,8,1,N 180 REM *** 190 REM Initialize Request Strings 200 REM Read Input Status Request String - Addr 0 / M 202 $(1)=">00M" 205 REM Read Analog Inputs Request String - Addr 1 / L 207 $(2)=">01LF" 210 REM Write Output Status Request String - Addr 2 / J 212 $(3)=">02J" 230 REM *** 240 REM Configure INPUT statement 245 IF WFL<10 THEN WFL=10 : REM WFL Must be 10 or greater 250 SETINPUT 1,1,0,255,WFF,WFL 260 REM *** 262 REM Send Power Up Clear to Address 0, 1, 2 264 $(4)=">00A" : S=4 : GOSUB 1000 266 IF ERR<>0 THEN GOTO 264 : REM Continuous Retry 268 $(4)=">01A" : S=4 : GOSUB 1000 270 IF ERR<>0 THEN GOTO 268 : REM Continuous Retry 272 $(4)=">02A" : S=4 : GOSUB 1000 274 IF ERR<>0 THEN GOTO 272 : REM Continuous Retry 300 REM *** 310 REM Read Input from Addr 0 and Copy to C0-17 320 S=1 : GOSUB 1000 330 IF ERR<>0 THEN GOTO 300 : REM Continuous Retry 340 DPORT(0)=VAL("0"+MID$($(0),2,4)+"H") 342 BMOVE W,C(0),C(17) 400 REM *** 410 REM Read Four Analog Inputs from Addr 1 and Copy to V1400-1403 420 S=2 : GOSUB 1000 430 IF ERR<>0 THEN GOTO 400 : REM Continuous Retry 440 DPORT(0)=VAL("0"+MID$($(0),2,4)+"H")-01000H 442 DPORT(2)=VAL("0"+MID$($(0),6,4)+"H")-01000H 446 DPORT(4)=VAL("0"+MID$($(0),10,4)+"H")-01000H 448 DPORT(6)=VAL("0"+MID$($(0),14,4)+"H")-01000H 460 BMOVE W,VH(1400),VH(1404) 500 REM *** 510 REM Read C20-37 and write to 16 Point Discrete Output at Addr 2 520 IF S405_C(1) THEN ASC($(3),5)=255 ELSE ASC($(3),5)=0 530 S=3 : GOSUB 1000 540 GOTO 300 1000 REM *** 1010 REM Send Request in $(S) and Get Response in $(0) 1020 $(0)="" : INLEN2=0 1030 PRINT1 $(S),"??" 1040 DTR2=1 : DELAY ND 1042 REM Wildcard Checksum of ?? is used 1050 PRINT2 $(S),"??",CR; 1060 DELAY FD : DTR2=0 1070 INPUT2 ,$(0) 1082 PRINT1 $(0) 1089 ERR=0 1090 IF INPLEN=0 THEN PRINT1 "NO RESPONSE" : ERR=NOT(0) : RETURN 1110 RETURN