1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
import sys,os
import interpreter
import emccanon
if 'emctask' in sys.builtin_module_names:
import emctask
import task
from embedding import *
#define EMC_DEBUG_CONFIG 0x00000002
#define EMC_DEBUG_VERSIONS 0x00000008
#define EMC_DEBUG_TASK_ISSUE 0x00000010
#define EMC_DEBUG_NML 0x00000040
#define EMC_DEBUG_MOTION_TIME 0x00000080
#define EMC_DEBUG_INTERP 0x00000100
#define EMC_DEBUG_RCS 0x00000200
#define EMC_DEBUG_INTERP_LIST 0x00000800
#define EMC_DEBUG_IOCONTROL 0x00001000
#define EMC_DEBUG_OWORD 0x00002000
#define EMC_DEBUG_REMAP 0x00004000
#define EMC_DEBUG_PYTHON 0x00008000
#define EMC_DEBUG_NAMEDPARAM 0x00010000
#define EMC_DEBUG_GDBONSIGNAL 0x00020000
def debug():
return interpreter.this.debugmask & 0x00008000
# Demo Python O-word subroutine - call as:
# o<square> [5]
# (debug, #<_value>)
#
# len(args) always reflects the number of actual parameters passed
def square(self, *args):
return args[0]*args[0]
# a function taking a variable number of arguments
# o<multiply> [5] [7]
# (debug, #<_value>)
# o<multiply> [5] [7] [9] [16]
# (debug, #<_value>)
import operator
def multiply(self, *args):
return reduce(operator.mul, *args)
#---------------- queue calls for task-time execution ------------
# see userfuncs.py for the actual function definitions
# trivial demo: wiggle a user-defined HAL pin a few times
def qdemo(self,*args,**kwargs):
try:
task.pytask.enqueue.demo(*args,**kwargs)
if debug(): print "enqueueing demo()",args,kwargs
except Exception,e:
# self happens if called with the UI context - no task there: harmless
pass
# access emcStatus
# this is queued so it is done in-sequence at task time
def show_emcstat(self,*args,**kwargs):
try:
task.pytask.enqueue.show_emcstat(*args,**kwargs)
if debug(): print "enqueueing show_emcstat()",args
except Exception,e:
if debug(): print "show_emcstat:",e,"pid=",os.getpid()
pass
def set_named_pin(self,*args):
''' an uh, creative way to pass a string argument: use a trailing comment
usage example: o<set_named_pin> call [2.345] (component.pinname)
'''
try:
if (len(args) != 1):
self.set_errormsg("set_named_pin takes a single argument and a comment")
return -1
if len(self.blocks[0].comment) == 0:
self.set_errormsg("set_named_pin takes a comment, which is the HAL pin name")
return -1
task.pytask.enqueue.set_named_pin(args[0], self.blocks[0].comment)
if debug(): print "enqueuing set_named_pin()",args
except Exception,e:
if debug(): print "set_named_pin:",e,"pid=",os.getpid()
pass
def wait_for_named_pin(self,*args):
''' same trick to wait for a given named pin to show a certain value:
usage example: o<wait_for_named_pin> call [1] (component.boolpin)
NB: this will NOT stop readhead, and this is not a method to retrieve a named pin's value
'''
try:
if (len(args) != 1):
self.set_errormsg("wait_for_named_pin takes a single argument and a comment")
return -1
if len(self.blocks[0].comment) == 0:
self.set_errormsg("wait_for_named_pin takes a comment, which is the HAL pin name")
return -1
task.pytask.enqueue.wait_for_named_pin(args[0], self.blocks[0].comment)
if debug(): print "enqueuing wait_for_named_pin()",args
except Exception,e:
if debug(): print "wait_for_named_pin:",e,"pid=",os.getpid()
pass
|