summaryrefslogtreecommitdiff
path: root/configs/sim/axis/remap/iocontrol-removed/python/userfuncs.py
blob: 46ea9ae8d504b978883894df439db5c31dc99cdc (plain)
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
import hal
import emctask

class UserFuncs(object):
    ''' additional user-defined methods for Task() which may be called through
    the IO_PLUGIN_CALL mechanism
    a mixin class to CustomTask

    methods  are expected to return a emctask,
    '''
    def __init__(self):
        print "UserFuncs.__init__()"
        myhal = hal.component("myhal")
        myhal.newpin("bit", hal.HAL_BIT, hal.HAL_OUT)
        myhal.newpin("float", hal.HAL_FLOAT, hal.HAL_OUT)
        myhal.newpin("int", hal.HAL_S32, hal.HAL_OUT)
        myhal.ready()
        self.myhal = myhal #FIXME
        self.components["myhal"] = myhal

    def demo(self,*args, **kwargs):
        print "TASK: demo(%s,%s)" % (args,kwargs)
        for i in range(int(args[0])):
            self.myhal['bit'] = not  self.myhal['bit']
        return emctask.RCS_STATUS.RCS_DONE


    def show_emcstat(self,args):
        '''
        snapshot some of emcstat to stdout
        '''
        e = emctask.emcstat
        print "mode=",e.task.mode
        print "state=",e.task.state
        print "file=",e.task.file
        print "toolOffset=",str(e.task.toolOffset)
        print "tooltable[0]=",e.io.tool.toolTable[0]
        print "g5x_offset=", e.task.g5x_offset, "system=",e.task.g5x_index
        return emctask.RCS_STATUS.RCS_DONE

    def set_named_pin(self,value,name):
        print "set_named_pin ",value,name
        (component,pin) = name.rsplit('.',1)
        comp = self.components[component]

        if type(comp[pin]).__name__ == 'float':
            comp[pin] = value

        if type(comp[pin]).__name__ == 'int':
            comp[pin] = int(value)

        if type(comp[pin]).__name__ == 'bool':
            comp[pin] = bool(int(value))

        return emctask.RCS_STATUS.RCS_DONE