'**************************************************************************** '*** Protocol Version 4 Driver for STAMP-1, STAMP-2, and PIC using PBASIC *** '*** Written by Gerald Rutherford *** '***----------------------------------------------------------------------*** '*** Version 4.00 June 1998 For use with VER3 and VER4 Devices. *** '*** Default is COM-2 at 9600 Baud.( Auto-baud-detect not yet avalable. ) *** '*** Format is: CMD [Command #] [VAR-1] [VAR-2] [VAR-3] [VAR-4] *** '*** Data is compressed into 9 BYTES for Send/Recieve. *** '**************************************************************************** ' DECLARE SUB keypress () ' Wait for a keypress. DECLARE SUB cmd (DS1%, ds2%, ds3%, ds4%) ' CMD I/O routine. DECLARE SUB pause (SEC!) ' Allow program pauses. DEFINT A-Z ' Default to integers. DIM SHARED info$, pointer ' CMD recovery. DIM SHARED dr1, dr2, dr3, dr4 ' CMD recieve storage. DIM SHARED xmax, ymax ' Graphics max points. xmax = 639: ymax = 479 ' Screen 12 resoultion. '---------------------------------------------------------------------- PORT$ = "COM2:" ' COM port. BAUD$ = "9600" ' BAUD rate. RS232$ = PORT$ + BAUD$ + ",N,8,1,BIN,CD 0,CS 0,DS 0,OP 0,RB,RS,TB" '---------------------------------------------------------------------- COM(2) ON ' Activate interupt routine. ON COM(2) GOSUB talkback ' Define [ talkback ] as the ' ' interupt subroutine. OPEN RS232$ FOR RANDOM AS #1 ' Open the COM port for input/output. '---------------------------------------------------------------------- GOTO start ' jump to start of user program. '---------------------------------------------------------------------- talkback: ' Port data colletion routine. DO ' This will gather data from the info$ = info$ + INPUT$(LOC(1), #1) ' COM port from the MINIBOT. pause .1 ' It will monitor until the port LOOP UNTIL LOC(1) = 0 ' has nothing left to recieve. RETURN ' When completed, it returns. '---------------------------------------------------------------------- start: SCREEN 12: CLS : cmd 0, 0, 0, 0 ' Remote device has been reset. '**************************************************************************** ' ' Your program goes here. ' ' Sample program FOR x = 1 TO 5 PRINT x; " "; cmd 1, 0, 0, 0 NEXT x PRINT ' ' Your program ends here. '**************************************************************************** DONE: cmd 0, 0, 0, 0: SCREEN 0 ' Remote device reset and exit. SYSTEM '**************************************************************************** ' -------------------------------------------------------------------------- ' Pass commands via 9 byte string to device. ' -------------------------------------------------------------------------- SUB cmd (DS1, ds2, ds3, ds4) LINE (xmax - 6, ymax - 16)-(xmax, ymax), 7, B CMD1: IF DS1 = 0 THEN SOUND 2000, 1 'Reset alert tone. c = 9 '[Send Reset ] color. ELSE c = 14 '[Send Normal ] color. END IF ' IF RST <> 0 THEN 'Signal a reset recovery send. c = 12 '[Send Recovery] color. END IF ' info$ = "" MINIBOT$ = "CMD" + CHR$(DS1) + CHR$(ds2) + MKI$(ds3) + MKI$(ds4) FOR send = 1 TO LEN(MINIBOT$) PRINT #1, MID$(MINIBOT$, send, 1); NEXT send pointer = 0: RST = 0 LINE (xmax - 5, ymax - 15)-(xmax - 1, ymax - 1), c, BF WHILE pointer = 0 AND RST = 0 pointer = INSTR(info$, "RDY") RST = INSTR(info$, "RST") WEND ' IF RST <> 0 THEN ' Assume a hard reset occured. GOTO CMD1 END IF ' MINIBOT$ = MID$(info$, pointer, 9) dr1 = ASC(MID$(MINIBOT$, 4, 1)) dr2 = ASC(MID$(MINIBOT$, 5, 1)) dr3 = CVI(MID$(MINIBOT$, 6, 2)) dr4 = CVI(MID$(MINIBOT$, 8, 2)) c = 2 '[ Send IDLE ] color. LINE (xmax - 5, ymax - 15)-(xmax - 1, ymax - 1), c, BF END SUB ' -------------------------------------------------------------------------- ' Simply wait for a key to be pressed, then wait for you to release. ' -------------------------------------------------------------------------- SUB keypress WHILE INKEY$ = "" WEND WHILE INKEY$ <> "" WEND END SUB ' -------------------------------------------------------------------------- ' Allows you to specify a time delay in 0.1 second increments ' -------------------------------------------------------------------------- SUB pause (SEC!) t1! = TIMER WHILE TIMER < (t1! + SEC!) WEND END SUB