PROGRAM 'Program 1. This is the parser. PBOOT 'Initial Setup 'Clear temporary variables, set the killmotion flags, enable the stall error, and dimension temporary variables. 'Then set the drive motion program run bit and run the other programs clear set bKillAxisZero set bKillAllMovesZero set bEnablePosErrResp dim lv(3) dim $v(3,80) dwl .1 ' Start the motion and E-stop listener programs set bDriveMotionProgram run prog0 run prog2 'Note lv0 is unused 'lv1 is whether we're handling the input stream 'Make sure file ID #1 is closed close #1 dwl 1 'Talk to the user over stream2 open "stream1:" as #1 while(BIT bDriveMotionProgram) ' Print the command prompt if (BIT bMaxPosErrExceeded) $v2 = "Shutter stalled" else if (BIT bAxisZeroJogActive OR BIT bAxisZeroInMotion) $v2 = "Shutter in motion" else if (NOT BIT bNegLimitClear) $v2 = "Shutter Open" else if (NOT BIT bPosLimitClear) $v2 = "Shutter Closed" else $v2 = "Shutter Stopped" endif endif endif endif if (NOT BIT bEStopClear) $v2 = $v2+", Manual Stop Pressed" endif if (BIT bClosedIndicator) $v2 = $v2+", External Switch Closed" endif $v2 = $v2+"> " print #1, $v2; $v0="" lv1 = 1 'This is the main command parser loop while(lv1) if (kbhit(1)) $v1 = getch(1) 'Keystroke handling. Process on CR, Backup if BS, add char otherwise if (asc($v1)=13) lv1=0 else if ((asc($v1)=8) or (asc($v1)=127)) if (len($v0)<=1) if (len($v0)=1) print #1, chr$(8);" ";chr$(8); endif $v0="" else $v0 = left$($v0,len($v0)-1) print #1, chr$(8);" ";chr$(8); endif else $v0 = $v0+$v1 print #1, $v1; endif endif 'If prog2 is down, kill all motion, because it's the watchdog. Then attempt to restart it. if (NOT BIT bProgTwoRunning) set bDisableDriveOnKill set bKillAxisZero set bKillAllMovesZero if (BIT bAxisZeroJogActive) dwl 0.2 jog off axis0 endif if (BIT bEnableAxisZero) dwl 0.2 clr bEnableAxisZero endif clr bActuatorMove run prog2 dwl 1 endif wend print #1, 'print #1, $v0 'This is the command parser 'So we hit CR and want to process the command 'Put everything in upper case to make comparisons easier $v0 = ucase$($v0) 'Process EXIT/QUIT command first if (instr($v0,"EXIT") or instr($v0,"QUIT")) print #1, "Exiting..." set bDisableDriveOnKill set bKillAxisZero set bKillAllMovesZero if (BIT bAxisZeroJogActive) dwl 0.2 jog off axis0 endif if (BIT bEnableAxisZero) dwl 0.2 clr bEnableAxisZero endif clr bActuatorMove clr bDriveMotionProgram else 'Is there an OPEN command here? If so, send to the open position if (instr($v0,"OPEN")) if (BIT bEStopClear) clr bKillAxisZero clr bKillAllMovesZero set bOpenCmd set bActuatorMove dwl 0.1 ' else ' print #1, "Must clear E-Stop First" endif else if (instr($v0,"CLOSE")) if (BIT bEStopClear) clr bKillAxisZero clr bKillAllMovesZero clr bOpenCmd set bActuatorMove dwl 0.1 ' else ' print #1, "Must clear E-Stop First" endif else if (instr($v0,"STOP")) set bKillAxisZero set bKillAllMovesZero clr bActuatorMove dwl 0.1 else if (instr($v0,"HELP")) print #1, print #1, "The only commands are OPEN, CLOSE, STOP, EXIT, QUIT, and HELP." dwl 0.1 print #1, "One command per line. Commands are not case sensitive" dwl 0.1 print #1, dwl 0.1 print #1, "Command List:" dwl 0.1 print #1, dwl 0.1 print #1, "HELP: This list" dwl 0.1 print #1, "OPEN: Open the shutter" dwl 0.1 print #1, "CLOSE: Close the shutter" dwl 0.1 print #1, "STOP: Stop the shutter at its present location" dwl 0.1 print #1, "EXIT/QUIT: Halt motion and end this program" dwl 0.1 print #1, endif endif endif endif endif 'End of command parser 'Debounce the input stream while(KBHIT(1)) $v0 = inkey$(1) 'print #1, $v0 wend wend 'If we get here, make sure the other programs die, too. clr bDriveMotionProgram halt prog0 halt prog2 close #1 'Shut down the drive, just in case set bDisableDriveOnKill set bKillAxisZero set bKillAllMovesZero dwl 0.2 jog off axis0 dwl 0.2 clr bEnableAxisZero ENDP