Exemplo n.º 1
0
    def linacts_start(self, devid, value=None):
        log.debug("Axis %d start" % devid)

        def fxn():
            self.status.linact_stats[devid].clearInPosition()
            self.status.linact_stats[devid].setMoving()

            while not (self.status.LinearActuators[devid]['position'] == self.status.LinearActuators[devid]['requested_position']):
                print 'linacts_start() running: pos = ' + str(self.status.LinearActuators[devid]['position']) #debug

                # If our error less than 5mm set them equal
                if abs(self.status.LinearActuators[devid]['position'] - self.status.LinearActuators[devid]['requested_position']) < 500 :
                    self.status.LinearActuators[devid]['position'] = self.status.LinearActuators[devid]['requested_position']
                    break;

                # If position is greater than req position deincrement
                if (self.status.LinearActuators[devid]['position']  > self.status.LinearActuators[devid]['requested_position']):
                    step = -100

                # Else increment
                else:
                    step = 100

                self.status.LinearActuators[devid]['position'] += step
                time.sleep(0.01)

            self.status.linact_stats[devid].clearMoving()
            self.status.linact_stats[devid].setInPosition()

        #Timer(0.5, fxn).start()
        time.sleep(0.5) #added
        fxn()#added
Exemplo n.º 2
0
    def run_callback(self, cmdpkt):
        """
        When a command comes in from the user/host
        this fxn is used to properly parse
        the packet and execute the proper callback
        """

        log.debug("Execute PKT: %s",repr(cmdpkt))

        # Determine callback to exectue
        cmdfxn, dev_id, param = self.parse_cmd(cmdpkt)
        # Execute the callback
        cmdfxn(dev_id, *param)
Exemplo n.º 3
0
    def run_callback(self, cmdpkt):
        """
        When a command comes in from the user/host
        this fxn is used to properly parse
        the packet and execute the proper callback
        """

        log.debug("Execute PKT: %s",repr(cmdpkt))

        # Determine callback to exectue
        cmdfxn, dev_id, param = self.parse_cmd(cmdpkt)
        # Execute the callback
        cmdfxn(dev_id, *param)
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        log.debug("Creating a controlbox simulator")
        self.hwsim = hwsim
        self.out_buffer = StringIO("CBOX")

        self.dacval0 = 0
        self.dacval1 = 0
        self.adcval0 = 0
        self.adcval1 = 0

        self.cbs = dict()
        self.cbs['DAC'] = self.cb_dac
        self.cbs['ADC'] = self.cb_adc
        self.cbs['SSR'] = self.cb_ssr
Exemplo n.º 5
0
    def write(self, msg):
        """ Write message to the control box simulator """
        log.debug("CBOXSIM Command: %s" % msg)
        params = msg.split('/')
        cmd = params[1]
        param = params[2]

        param = param.split(" ")

        if len(param) == 3:
            param0 = param[1]
            param1 = param[2]
            params = (param0, param1)
        elif len(param) == 2:
            params = param[1]
        else:
            params = None

        self.cbs[cmd](params)
Exemplo n.º 6
0
    def linacts_home_axis(self, devid, value=None):
        """ Linear Actuator home axis """
        log.debug("Home the linear actuator %d", devid)
        self.status.LinearActuators[devid]['requested_position'] = 0 #Added 5/7/2014 by [email protected]

        def fxn():
            self.status.linact_stats[devid].clearHome()
            self.status.linact_stats[devid].setMoving()
            time.sleep(1.0)
            while not self.status.LinearActuators[devid]['position'] <= 0:
                self.status.LinearActuators[devid]['position'] -= 10
                if self.status.LinearActuators[devid]['position'] < 0:
                    self.status.LinearActuators[devid]['position'] = 0
                time.sleep(0.1)

            self.status.linact_stats[devid].clear()

        #Timer(0.5, fxn).start() #taken out 5/8/2014 by [email protected]
        time.sleep(0.5) #added
        fxn()#added
Exemplo n.º 7
0
    def parse_cmd(self, cmd_pkt):
        """
        Parse the cmd sent from the host
        Expect little endian
        -first integer is the cmd_id
        -second integer is the device_id
            You can think of this as a 2 integer
            long register we are writing too
        - the parameter type is variable,
            so we look it up and get the callback fxn that will change
            the proper state variable (or start a thread that will simulate
            some HW change)
        """
        # Create struct for unpacking the cmd_id and dev_id
        cmd_id_struct = struct.Struct("<ii")

        # Length of the packet
        len_cmd_id = cmd_id_struct.size

        # Extract cmd_id and dev_id
        cmd_id, dev_id = cmd_id_struct.unpack(cmd_pkt[:len_cmd_id])
        log.debug("CMDID:#%d|DEVID:#%d", cmd_id, dev_id)

        # Look up callback and parameter type
        cb, param_fmt_str = self.cb_map[cmd_id]

        # Create struct to unpack the parameter
        param_struct = struct.Struct(param_fmt_str)

        # Unpack paramter depending on expected type
        param = param_struct.unpack(cmd_pkt[len_cmd_id:])
        log.debug("PARAM:%s", param)

        # Return the cb fxn, the dev_id and the param
        # Something else can pass the dev_id and param in to callback
        # This simulates some HW action as a result of a user/host command
        return (cb, dev_id, param)
Exemplo n.º 8
0
    def parse_cmd(self, cmd_pkt):
        """
        Parse the cmd sent from the host
        Expect little endian
        -first integer is the cmd_id
        -second integer is the device_id
            You can think of this as a 2 integer
            long register we are writing too
        - the parameter type is variable,
            so we look it up and get the callback fxn that will change
            the proper state variable (or start a thread that will simulate
            some HW change)
        """
        # Create struct for unpacking the cmd_id and dev_id
        cmd_id_struct = struct.Struct("<ii")

        # Length of the packet
        len_cmd_id = cmd_id_struct.size

        # Extract cmd_id and dev_id
        cmd_id, dev_id = cmd_id_struct.unpack(cmd_pkt[:len_cmd_id])
        log.debug("CMDID:#%d|DEVID:#%d", cmd_id, dev_id)

        # Look up callback and parameter type
        cb, param_fmt_str = self.cb_map[cmd_id]

        # Create struct to unpack the parameter
        param_struct = struct.Struct(param_fmt_str)

        # Unpack paramter depending on expected type
        param = param_struct.unpack(cmd_pkt[len_cmd_id:])
        log.debug("PARAM:%s", param)

        # Return the cb fxn, the dev_id and the param
        # Something else can pass the dev_id and param in to callback
        # This simulates some HW action as a result of a user/host command
        return (cb, dev_id, param)
Exemplo n.º 9
0
 def cb_adc(self, param):
     """ Callback for the ADC """
     log.debug("ADC CB %s", param)
     if param is None:
         self.out_buffer = StringIO("ADC %X, %X\n"
                 % (self.adcval0, self.adcval0))
Exemplo n.º 10
0
 def fans_turn_off(self, devid, value=None):
     """ Fans turn off """
     log.debug("Turn off Fan %d", devid)
Exemplo n.º 11
0
 def linacts_home_axis(self, devid, value=None):
     """ Linear Actuator home axis """
     log.debug("Home the linear actuator %d", devid)
Exemplo n.º 12
0
 def tempctrl_turn_on(self, devid, value=None):
     """ Turn temperature controller on """
     log.debug("Turn on temperture controller %d", devid)
     self.status.TemperatureControllers[devid]['error_code'] = '\x01'
Exemplo n.º 13
0
 def smcinterfaces_set_analog_out(self, devid, value):
     """ SMC Interface set analog out """
     log.debug(" SMC Interface %d set analog out = %f", devid, value)
Exemplo n.º 14
0
 def linacts_home_axis(self, devid, value=None):
     """ Linear Actuator home axis """
     log.debug("Home the linear actuator %d", devid)
Exemplo n.º 15
0
    def __init__(self):
        """ The ElixysSimulator initializes its
        status and then registers the callbacks to be executed
        when the commands come in from the host/user
        """
        self.stat = StatusSimulator()
        self.cb_map = {}

        log.debug("Initialize the ElixysSimulator, register callbacks")

        # Setup Callbacks for Mixer commands
        self.register_callback('Mixers',
                               'set_period',
                               self.mixers_set_period)

        self.register_callback('Mixers',
                               'set_duty_cycle',
                               self.mixers_set_duty_cycle)

        # Setup Callbacks for Valve commands
        self.register_callback('Valves',
                               'set_state0',
                               self.valves_set_state0)

        self.register_callback('Valves',
                               'set_state1',
                               self.valves_set_state1)

        self.register_callback('Valves',
                               'set_state2',
                               self.valves_set_state2)

        # Setup Callbacks for Temperature controllers
        self.register_callback('TemperatureControllers',
                               'set_setpoint',
                               self.tempctrl_set_setpoint)

        self.register_callback('TemperatureControllers',
                               'turn_on',
                               self.tempctrl_turn_on)

        self.register_callback('TemperatureControllers',
                               'turn_off',
                               self.tempctrl_turn_off)

        # Setup Callbacks for SMC Intrefaces
        self.register_callback('SMCInterfaces',
                               'set_analog_out',
                               self.smcinterfaces_set_analog_out)

        # Setup Callbacks for Fans
        self.register_callback('Fans',
                               'turn_on',
                               self.fans_turn_on)

        self.register_callback('Fans',
                               'turn_off',
                               self.fans_turn_off)

        # Setup Callback for Linear Actuators
        self.register_callback('LinearActuators',
                               'set_requested_position',
                               self.linacts_set_requested_position)

        self.register_callback('LinearActuators',
                               'home_axis',
                               self.linacts_home_axis)

        self.tempctrl_thread = thread.start_new_thread(self.run_tempctrls,())
Exemplo n.º 16
0
 def smcinterfaces_set_analog_out(self, devid, value):
     """ SMC Interface set analog out """
     log.debug(" SMC Interface %d set analog out = %f", devid, value)
Exemplo n.º 17
0
 def fans_turn_off(self, devid, value=None):
     """ Fans turn off """
     log.debug("Turn off Fan %d", devid)
Exemplo n.º 18
0
 def flushInput(self):
     """ Flush in input buffer """
     log.debug("Flush the controlbox simulator input buffer")
Exemplo n.º 19
0
    def __init__(self):
        """ The ElixysSimulator initializes its
        status and then registers the callbacks to be executed
        when the commands come in from the host/user
        """
        self.stat = StatusSimulator()
        self.cb_map = {}

        log.debug("Initialize the ElixysSimulator, register callbacks")

        # Setup Callbacks for Mixer commands
        self.register_callback('Mixers',
                               'set_period',
                               self.mixers_set_period)

        self.register_callback('Mixers',
                               'set_duty_cycle',
                               self.mixers_set_duty_cycle)

        # Setup Callbacks for Valve commands
        self.register_callback('Valves',
                               'set_state0',
                               self.valves_set_state0)

        self.register_callback('Valves',
                               'set_state1',
                               self.valves_set_state1)

        self.register_callback('Valves',
                               'set_state2',
                               self.valves_set_state2)

        # Setup Callbacks for Temperature controllers
        self.register_callback('TemperatureControllers',
                               'set_setpoint',
                               self.tempctrl_set_setpoint)

        self.register_callback('TemperatureControllers',
                               'turn_on',
                               self.tempctrl_turn_on)

        self.register_callback('TemperatureControllers',
                               'turn_off',
                               self.tempctrl_turn_off)

        # Setup Callbacks for SMC Intrefaces
        self.register_callback('SMCInterfaces',
                               'set_analog_out',
                               self.smcinterfaces_set_analog_out)

        # Setup Callbacks for Fans
        self.register_callback('Fans',
                               'turn_on',
                               self.fans_turn_on)

        self.register_callback('Fans',
                               'turn_off',
                               self.fans_turn_off)

        # Setup Callback for Linear Actuators
        self.register_callback('LinearActuators',
                               'set_requested_position',
                               self.linacts_set_requested_position)

        self.register_callback('LinearActuators',
                               'home_axis',
                               self.linacts_home_axis)

        self.tempctrl_thread = thread.start_new_thread(self.run_tempctrls,())
Exemplo n.º 20
0
 def open(self):
     """ Open the control box simulator """
     log.debug("Open the controlbox simulator")
Exemplo n.º 21
0
 def close(self):
     """ Close the control box simulator """
     log.debug("Close the control box simulator")
Exemplo n.º 22
0
 def mixers_set_period(self, devid, period):
     """ Mixer set period callback """
     log.debug("Set mixer %d period = %d", devid, period)
     self.status.Mixers[devid]['period'] = period
Exemplo n.º 23
0
 def fans_turn_off(self, devid, value=None):
     """ Fans turn off """
     log.debug("Turn off Fan %d", devid)
     state = self.status.Fans['state'] 
     state &= ~(1 << devid)
     self.status.Fans['state'] = state
Exemplo n.º 24
0
 def fans_turn_on(self, devid, value=None):
     """ Fans turn on """
     log.debug("Turn on Fan %d", devid)
     state = self.status.Fans['state'] 
     state |= 1 << devid
     self.status.Fans['state'] = state 
Exemplo n.º 25
0
 def fans_turn_on(self, devid, value=None):
     """ Fans turn on """
     log.debug("Turn on Fan %d", devid)
Exemplo n.º 26
0
 def cb_ssr(self, param):
     """ Callback for  the SSR """
     log.debug("SSR CB %s", param)
Exemplo n.º 27
0
 def linacts_set_requested_position(self, devid, position):
     """ Linear Actuator set requested position """
     log.debug("Set the linear actuator %d requested position = %d",
                 devid, position)
Exemplo n.º 28
0
 def mixers_set_period(self, devid, period):
     """ Mixer set period callback """
     log.debug("Set mixer %d period = %d", devid, period)
Exemplo n.º 29
0
    def update_digital_inputs(self):
        """ Evaluate the valve states and determine
        expected digital input status
        """

        # Check for Reactor 0 down (DI 0)
        if ((self.stat['Valves']['state0'] & (1 << 6)) and
                not(self.stat['Valves']['state1'] & (1 << 6))):
            log.debug("Reactor 0 will go down. DI0=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 0)
            Timer(2.0, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 1)



        # Check for Reactor 0 up (DI 1)
        if ((self.stat['Valves']['state1'] & (1 << 6)) and
                not(self.stat['Valves']['state0'] & (1 << 6))):
            log.debug("Reactor 0 will go up. DI1=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 1)
            Timer(2.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 0)


        # Check for Reactor 1 down (DI 3)
        if ((self.stat['Valves']['state0'] & (1 << 5)) and
                not(self.stat['Valves']['state1'] & (1 << 5))):
            log.debug("Reactor 1 will go down. DI3=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 3)
            Timer(2.0, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 2)



        # Check for Reactor 1 up (DI 2)
        if ((self.stat['Valves']['state1'] & (1 << 5)) and
                not(self.stat['Valves']['state0'] & (1 << 5))):
            log.debug("Reactor 1 will go up. DI2=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 2)
            Timer(2.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 3)


        # Check for Reactor 2 down (DI 5)
        if ((self.stat['Valves']['state0'] & (1 << 4)) and
                not(self.stat['Valves']['state1'] & (1 << 4))):
            log.debug("Reactor 1 will go down. DI3=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 5)
            Timer(2.0, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 4)



        # Check for Reactor 2 up (DI 4)
        if ((self.stat['Valves']['state1'] & (1 << 4)) and
                not(self.stat['Valves']['state0'] & (1 << 4))):
            log.debug("Reactor 1 will go up. DI2=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 4)
            Timer(2.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 5)

        # Check for Gripper up (DI 6)
        if ((self.stat['Valves']['state0'] & (1 << 10)) and
                not(self.stat['Valves']['state1'] & (1 << 10))):
            log.debug("Gripper will go up. DI6=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 6)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 7)

        # Check for Gripper lower (DI 7)
        if ((self.stat['Valves']['state1'] & (1 << 10)) and
                not(self.stat['Valves']['state0'] & (1 << 10))):
            log.debug("Gripper will go down. DI7=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 7)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 6)

        # Check for GasTransfer up (DI 9)
        if ((self.stat['Valves']['state1'] & (1 << 9)) and
                not(self.stat['Valves']['state0'] & (1 << 9))):
            log.debug("GasTransfer will go up. DI9=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 9)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 8)

        # Check for GasTransfer lower (DI 8)
        if ((self.stat['Valves']['state0'] & (1 << 9)) and
                not(self.stat['Valves']['state1'] & (1 << 9))):
            log.debug("GasTransfer will go down. DI9=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 8)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 9)

        # Check for Gripper Open  (DI 10)
        if ((self.stat['Valves']['state1'] & (1 << 8)) and
                not(self.stat['Valves']['state0'] & (1 << 8))):
            log.debug("Gripper will open. DI10=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 10)
            Timer(0.2, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 11)

        # Check for Gripper Close (DI 11)
        if ((self.stat['Valves']['state0'] & (1 << 8)) and
                not(self.stat['Valves']['state1'] & (1 << 8))):
            log.debug("Gripper will close. DI11=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 11)
            Timer(0.2, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 10)
Exemplo n.º 30
0
 def valves_set_state1(self, devid, state):
     """ Set valve state1 """
     log.debug("Set valve state1 = %s", bin(state))
     self.stat.Valves['state1'] = state
     self.update_digital_inputs()
Exemplo n.º 31
0
 def tempctrl_set_setpoint(self, devid, value):
     """ Set temperature controller setpoint """
     log.debug("Set temperature controller %d setpoint = %f",
                 devid, value)
     self.stat.TemperatureControllers[devid]['setpoint'] = value
Exemplo n.º 32
0
 def mixers_set_duty_cycle(self, devid, duty):
     """ Mixer set the duty cycle """
     log.debug("Set mixer %d duty cycle = %f", devid, duty)
     self.status.Mixers[devid]['duty_cycle'] = duty
Exemplo n.º 33
0
    def __init__(self, *args, **kwargs):
        """
        Initialize the status with values we would expect when
        the HW first turns on
        """
        super(StatusSimulator, self).__init__(self, *args, **kwargs)

        log.debug("Initialize The StatusSimulator")
        self.is_valid = True

        log.debug("Set the initial state of the system")
        # Initialize Header
        self.store['Header'] = {}
        self.store['Header']['packet_id'] = 0
        self.store['Header']['packet_type'] = 63
        self.store['Header']['system_error_code'] = 0

        # Initialize Mixers
        mixers = []
        self.store['Mixers'] = {}
        for i in range(self.sysconf['Mixers']['count']):
            mixer = {'duty_cycle':0.0, 'period': 0}
            self.store['Mixers'][i] = mixer
            mixers.append(mixer)

        self.store['Mixers']['Subs'] = mixers
        self.store['Mixers']['count'] = \
                self.sysconf['Mixers']['count']
        self.store['Mixers']['error_code'] = '\x00'
        self.store


        # Initialize Valves
        self.store['Valves'] = {}
        self.store['Valves']['error_code'] = '\x00'
        self.store['Valves']['state0'] = 0
        self.store['Valves']['state1'] = 0
        self.store['Valves']['state2'] = 0

        # Initialize Thermocouples
        thermocouples = []
        self.store['Thermocouples'] = {}
        for i in range(self.sysconf['Thermocouples']['count']):
            thermocouple = {'error_code': '\x00',
                            'temperature':25.0}
            self.store['Thermocouples'][i] = thermocouple
            thermocouples.append(thermocouple)

        self.store['Thermocouples']['Subs'] = thermocouples
        self.store['Thermocouples']['count'] = \
                self.sysconf['Thermocouples']['count']

        # Initialize AUX Thermocouples
        auxthermocouples = []
        self.store['AuxThermocouples'] = {}
        for i in range(self.sysconf['AuxThermocouples']['count']):
            auxthermocouple = {'error_code': '\x00',
                            'temperature':25.0}
            self.store['AuxThermocouples'][i] = auxthermocouple
            auxthermocouples.append(auxthermocouple)

        self.store['AuxThermocouples']['Subs'] = auxthermocouples
        self.store['AuxThermocouples']['count'] = \
                self.sysconf['AuxThermocouples']['count']

        # Initialize heaters
        self['Heaters'] = {'state':0}

        # Initialize Temperature Controllers
        tempctrls = []
        self.store['TemperatureControllers'] = {}
        for i in range(self.sysconf['TemperatureControllers']['count']):
            tempctrl = {'error_code':'\x00', 'setpoint':0.0}
            self.store['TemperatureControllers'][i] = tempctrl
            tempctrls.append(tempctrl)


        self.store['TemperatureControllers']['error_code'] = 0
        self.store['TemperatureControllers']['Subs'] = tempctrls
        self.store['TemperatureControllers']['count'] = \
                self.sysconf['TemperatureControllers']['count']

        # Initialize SMC Interfaces
        smcinterfaces = []
        self.store['SMCInterfaces'] = {}
        for i in range(self.sysconf['SMCInterfaces']['count']):
            smcinterface = {'analog_in':0.0,
                            'analog_out':0.0}
            self.store['SMCInterfaces'][i] = smcinterface
            smcinterfaces.append(smcinterface)

        self.store['SMCInterfaces']['Subs'] = smcinterfaces
        self.store['SMCInterfaces']['count'] = \
                self.sysconf['SMCInterfaces']['count']
        self.store['SMCInterfaces']['error_code'] = '\x00'

        # Initialize Fans
        self.store['Fans'] = {}
        self.store['Fans']['state'] = '\x01'

        # Initialize Linear Actuators
        linacts = []
        self['LinearActuators'] = dict()
        for i in range(self.sysconf['LinearActuators']['count']):
            linact = {'error_code': 0,
                      'position': 0,
                      'requested_position':0}

            self.store['LinearActuators'][i] = linact
            linacts.append(linact)

        self['LinearActuators']['Subs'] = linacts
        self['LinearActuators']['count'] = \
                self.sysconf['LinearActuators']['count']

        # Initialize Digital Inputs
        self.store['DigitalInputs'] = {}
        self.store['DigitalInputs']['error_code'] = '\x00'
        self.store['DigitalInputs']['state'] = 4095

        # Initialize Liquid Sensors
        liqsensors = []
        self.store['LiquidSensors'] = {}
        for i in range(self.sysconf['LiquidSensors']['count']):
            liqsensor = {'analog_in':0.0}
            self.store['LiquidSensors'][i] = liqsensor
            liqsensors.append(liqsensor)

        self.store['LiquidSensors']['Subs'] = liqsensors
        self.store['LiquidSensors']['count'] = \
                self.sysconf['LiquidSensors']['count']
        self.store['LiquidSensors']['error_code'] = '\x00'

        for key,value in self.store.items():
            setattr(self,key,value)
Exemplo n.º 34
0
    def __init__(self, *args, **kwargs):
        """
        Initialize the status with values we would expect when
        the HW first turns on
        """
        super(StatusSimulator, self).__init__(self, *args, **kwargs)

        log.debug("Initialize The StatusSimulator")
        self.is_valid = True

        log.debug("Set the initial state of the system")
        # Initialize Header
        self.store['Header'] = {}
        self.store['Header']['packet_id'] = 0
        self.store['Header']['packet_type'] = 63
        self.store['Header']['system_error_code'] = 0

        # Initialize Mixers
        mixers = []
        self.store['Mixers'] = {}
        for i in range(self.sysconf['Mixers']['count']):
            mixer = {'duty_cycle':0.0, 'period': 0}
            self.store['Mixers'][i] = mixer
            mixers.append(mixer)

        self.store['Mixers']['Subs'] = mixers
        self.store['Mixers']['count'] = \
                self.sysconf['Mixers']['count']
        self.store['Mixers']['error_code'] = '\x00'
        self.store


        # Initialize Valves
        self.store['Valves'] = {}
        self.store['Valves']['error_code'] = '\x00'
        self.store['Valves']['state0'] = 0
        self.store['Valves']['state1'] = 0
        self.store['Valves']['state2'] = 0

        # Initialize Thermocouples
        thermocouples = []
        self.store['Thermocouples'] = {}
        for i in range(self.sysconf['Thermocouples']['count']):
            thermocouple = {'error_code': '\x00',
                            'temperature':25.0}
            self.store['Thermocouples'][i] = thermocouple
            thermocouples.append(thermocouple)

        self.store['Thermocouples']['Subs'] = thermocouples
        self.store['Thermocouples']['count'] = \
                self.sysconf['Thermocouples']['count']

        # Initialize AUX Thermocouples
        auxthermocouples = []
        self.store['AuxThermocouples'] = {}
        for i in range(self.sysconf['AuxThermocouples']['count']):
            auxthermocouple = {'error_code': '\x00',
                            'temperature':25.0}
            self.store['AuxThermocouples'][i] = auxthermocouple
            auxthermocouples.append(auxthermocouple)

        self.store['AuxThermocouples']['Subs'] = auxthermocouples
        self.store['AuxThermocouples']['count'] = \
                self.sysconf['AuxThermocouples']['count']

        # Initialize heaters
        self['Heaters'] = {'state':0}

        # Initialize Temperature Controllers
        tempctrls = []
        self.store['TemperatureControllers'] = {}
        for i in range(self.sysconf['TemperatureControllers']['count']):
            tempctrl = {'error_code':'\x00', 'setpoint':0.0}
            self.store['TemperatureControllers'][i] = tempctrl
            tempctrls.append(tempctrl)


        self.store['TemperatureControllers']['error_code'] = 0
        self.store['TemperatureControllers']['Subs'] = tempctrls
        self.store['TemperatureControllers']['count'] = \
                self.sysconf['TemperatureControllers']['count']

        # Initialize SMC Interfaces
        smcinterfaces = []
        self.store['SMCInterfaces'] = {}
        for i in range(self.sysconf['SMCInterfaces']['count']):
            smcinterface = {'analog_in':0.0,
                            'analog_out':0.0}
            self.store['SMCInterfaces'][i] = smcinterface
            smcinterfaces.append(smcinterface)

        self.store['SMCInterfaces']['Subs'] = smcinterfaces
        self.store['SMCInterfaces']['count'] = \
                self.sysconf['SMCInterfaces']['count']
        self.store['SMCInterfaces']['error_code'] = '\x00'

        # Initialize Fans
        self.store['Fans'] = {}
        self.store['Fans']['state'] = '\x01'

        # Initialize Linear Actuators
        linacts = []
        self['LinearActuators'] = dict()
        for i in range(self.sysconf['LinearActuators']['count']):
            linact = {'error_code': 0,
                      'position': 0,
                      'requested_position':0}

            self.store['LinearActuators'][i] = linact
            linacts.append(linact)

        self['LinearActuators']['Subs'] = linacts
        self['LinearActuators']['count'] = \
                self.sysconf['LinearActuators']['count']

        # Initialize Digital Inputs
        self.store['DigitalInputs'] = {}
        self.store['DigitalInputs']['error_code'] = '\x00'
        self.store['DigitalInputs']['state'] = 4095

        # Initialize Liquid Sensors
        liqsensors = []
        self.store['LiquidSensors'] = {}
        for i in range(self.sysconf['LiquidSensors']['count']):
            liqsensor = {'analog_in':0.0}
            self.store['LiquidSensors'][i] = liqsensor
            liqsensors.append(liqsensor)

        self.store['LiquidSensors']['Subs'] = liqsensors
        self.store['LiquidSensors']['count'] = \
                self.sysconf['LiquidSensors']['count']
        self.store['LiquidSensors']['error_code'] = '\x00'

        for key,value in self.store.items():
            setattr(self,key,value)
Exemplo n.º 35
0
 def mixers_set_duty_cycle(self, devid, duty):
     """ Mixer set the duty cycle """
     log.debug("Set mixer %d duty cycle = %f", devid, duty)
Exemplo n.º 36
0
 def mixers_set_period(self, devid, period):
     """ Mixer set period callback """
     log.debug("Set mixer %d period = %d", devid, period)
Exemplo n.º 37
0
 def valves_set_state2(self, devid, state):
     """ Set valve state2 """
     log.debug("Set valve state2 = %s", bin(state))
     self.stat.Valves['state2'] = state
Exemplo n.º 38
0
 def mixers_set_duty_cycle(self, devid, duty):
     """ Mixer set the duty cycle """
     log.debug("Set mixer %d duty cycle = %f", devid, duty)
Exemplo n.º 39
0
 def tempctrl_turn_off(self, devid, value=None):
     """ Turn off temperature controllers """
     log.debug("Turn off temperature controller %d", devid)
     self.stat.TemperatureControllers[devid]['error_code'] = '\x00'
Exemplo n.º 40
0
 def valves_set_state1(self, devid, state):
     """ Set valve state1 """
     log.debug("Set valve state1 = %s", bin(state))
     self.stat.Valves['state1'] = state
     self.update_digital_inputs()
Exemplo n.º 41
0
 def fans_turn_on(self, devid, value=None):
     """ Fans turn on """
     log.debug("Turn on Fan %d", devid)
Exemplo n.º 42
0
 def valves_set_state2(self, devid, state):
     """ Set valve state2 """
     log.debug("Set valve state2 = %s", bin(state))
     self.stat.Valves['state2'] = state
Exemplo n.º 43
0
 def linacts_set_requested_position(self, devid, position):
     """ Linear Actuator set requested position """
     log.debug("Set the linear actuator %d requested position = %d",
                 devid, position)
Exemplo n.º 44
0
 def tempctrl_set_setpoint(self, devid, value):
     """ Set temperature controller setpoint """
     log.debug("Set temperature controller %d setpoint = %f",
                 devid, value)
     self.stat.TemperatureControllers[devid]['setpoint'] = value
Exemplo n.º 45
0
    def update_digital_inputs(self):
        """ Evaluate the valve states and determine
        expected digital input status
        """

        # Check for Reactor 0 down (DI 0)
        if ((self.stat['Valves']['state0'] & (1 << 6)) and
                not(self.stat['Valves']['state1'] & (1 << 6))):
            log.debug("Reactor 0 will go down. DI0=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 0)
            Timer(2.0, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 1)



        # Check for Reactor 0 up (DI 1)
        if ((self.stat['Valves']['state1'] & (1 << 6)) and
                not(self.stat['Valves']['state0'] & (1 << 6))):
            log.debug("Reactor 0 will go up. DI1=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 1)
            Timer(2.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 0)


        # Check for Reactor 1 down (DI 3)
        if ((self.stat['Valves']['state0'] & (1 << 5)) and
                not(self.stat['Valves']['state1'] & (1 << 5))):
            log.debug("Reactor 1 will go down. DI3=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 3)
            Timer(2.0, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 2)



        # Check for Reactor 1 up (DI 2)
        if ((self.stat['Valves']['state1'] & (1 << 5)) and
                not(self.stat['Valves']['state0'] & (1 << 5))):
            log.debug("Reactor 1 will go up. DI2=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 2)
            Timer(2.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 3)


        # Check for Reactor 2 down (DI 5)
        if ((self.stat['Valves']['state0'] & (1 << 4)) and
                not(self.stat['Valves']['state1'] & (1 << 4))):
            log.debug("Reactor 1 will go down. DI3=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 5)
            Timer(2.0, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 4)



        # Check for Reactor 2 up (DI 4)
        if ((self.stat['Valves']['state1'] & (1 << 4)) and
                not(self.stat['Valves']['state0'] & (1 << 4))):
            log.debug("Reactor 1 will go up. DI2=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 4)
            Timer(2.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 5)

        # Check for Gripper up (DI 6)
        if ((self.stat['Valves']['state0'] & (1 << 10)) and
                not(self.stat['Valves']['state1'] & (1 << 10))):
            log.debug("Gripper will go up. DI6=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 6)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 7)

        # Check for Gripper lower (DI 7)
        if ((self.stat['Valves']['state1'] & (1 << 10)) and
                not(self.stat['Valves']['state0'] & (1 << 10))):
            log.debug("Gripper will go down. DI7=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 7)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 6)

        # Check for GasTransfer up (DI 9)
        if ((self.stat['Valves']['state1'] & (1 << 9)) and
                not(self.stat['Valves']['state0'] & (1 << 9))):
            log.debug("GasTransfer will go up. DI9=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 9)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 8)

        # Check for GasTransfer lower (DI 8)
        if ((self.stat['Valves']['state0'] & (1 << 9)) and
                not(self.stat['Valves']['state1'] & (1 << 9))):
            log.debug("GasTransfer will go down. DI9=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 8)
            Timer(1.0,fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 9)

        # Check for Gripper Open  (DI 10)
        if ((self.stat['Valves']['state1'] & (1 << 8)) and
                not(self.stat['Valves']['state0'] & (1 << 8))):
            log.debug("Gripper will open. DI10=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 10)
            Timer(0.2, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 11)

        # Check for Gripper Close (DI 11)
        if ((self.stat['Valves']['state0'] & (1 << 8)) and
                not(self.stat['Valves']['state1'] & (1 << 8))):
            log.debug("Gripper will close. DI11=True")
            def fxn():
                self.stat['DigitalInputs']['state'] &= ~(1 << 11)
            Timer(0.2, fxn).start()
            self.stat['DigitalInputs']['state'] |= (1 << 10)
Exemplo n.º 46
0
 def tempctrl_turn_off(self, devid, value=None):
     """ Turn off temperature controllers """
     log.debug("Turn off temperature controller %d", devid)
     self.stat.TemperatureControllers[devid]['error_code'] = '\x00'