Skip to main content

Occasionally, it is beneficial to create a user-defined command set that can be received over the serial port and interpreted at an application program (.dmc) level.  The code below uses the "Communication Interrupt" feature of the Galil controller to accept characters over the serial port, parse them, and process specific parts of an on-board dmc program.  The code uses a modified "prompt" that is shown as a "$:" on the terminal to let the user know they are in a different mode compared to the standard Galil prompt ":".  In this case, the user can enter "GO" and the motor will start jogging at the predefined speed.  Entering the string "STOP" will cause the motor to stop.  Note - there is a max of six characters when received in the P1ST variable as a string, the P1NM variable is for numeric values and can go up to a 32bit number.  An error handling routine is included such that if an error occurs the code is displayed and the program is restarted.

In the output below, the motor was intentionally shut off using an MO command to cause an error to occur and then turned back on using an SH via Ethernet.  Here is the output from the terminal:
$:
$:GO
Motion Starting
$:STOP
Motion Stopping
$:GO
ERROR  20.0000
$:GO
Motion Starting
$:STOP
Motion Stopping

Here is the .dmc code:

#Main

CI 1,1; 'interrupt on c/r

CW2; 'ASCII readable MG output

#Loop

JP#Loop

EN

#COMINT

JS#PARSE

EN1,1

#PARSE

'routine to parse input

str=P1ST;

IF (str="GO")

JS#GO

ENDIF

IF (str="STOP")

JS#STOP

ENDIF

MG{P1}"$:"{N}

EN

#GO

JG 1000; BGA;

MG{P1}"Motion Starting"

EN

#STOP
STX;

MG{P1}"Motion Stopping"

EN

#CMDERR

MG{P1}"ERROR ",_TC1

ZS

JP#Main

RE