Пример #1
0
 def setPC104_Digital(self, data):
     pins = HardwareStatusInstance.getInstance().PC_104
     Logging.debugPrint(3, "POST: setPC104_Digital '%s'" % data)
     pins.digital_out.update(data)
     Logging.debugPrint(
         4, "Digital out data: '%s'" % pins.digital_out.getJson())
     return "{'result':'success'}"
Пример #2
0
    def loadThermoCouples(self, profileName, zone):
        '''
        This is a helper medthod for LoadProfile, this will load thermocouples tied to this profile
        '''

        sql = "SELECT * FROM tvac.TC_Profile WHERE profile_name=\"{}\" AND zone=\"{}\";".format(
            profileName, zone)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in loadThermoCouples, zoneCollection: {}".format(
                    str(e)))
            if Logging.debug:
                raise e2

        results = mysql.cur.fetchall()
        TCs = []
        tcList = HardwareStatusInstance.getInstance().Thermocouples.tcList
        for result in results:
            TCs.append(int(result['thermocouple']))

        for tc in tcList:
            if tc.Thermocouple in TCs:
                tc.update({
                    "zone": "zone" + str(int(result['zone'])),
                    "userDefined": True
                })
        return TCs
Пример #3
0
 def setThermocouples(self, thermocouples):
     self.__lock.acquire()
     hwStatus = HardwareStatusInstance.getInstance()
     list = []
     for tc in thermocouples:
         list.append(hwStatus.Thermocouples.getTC(tc))
     self.__lock.release()
     return list
Пример #4
0
    def updateDutyCycle(self):
        '''
        Given that temp_temperature is assigned to a value, this will 
        update the duty cycle for the lamps
        '''

        self.pid.SetPoint = self.temp_temperature
        # TODO: Don't leave this hardcoded
        self.pid.update(self.zoneProfile.getTemp(self.zoneProfile.average))
        self.dutyCycle = self.pid.error_value / self.maxTempRisePerUpdate

        # TODO: pick what lamp you want to use
        if self.lamps:
            self.parent.d_out.update(
                {self.lamps[1] + " PWM DC": self.dutyCycle})
            self.parent.d_out.update(
                {self.lamps[0] + " PWM DC": self.dutyCycle})
        else:
            # for zone 9, the platen
            HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                ['Platen Duty Cycle', self.dutyCycle])

        Logging.debugPrint(
            2, "{}: avg ({})\goal({}) -- {}".format(
                self.name, self.zoneProfile.getTemp(self.zoneProfile.average),
                self.temp_temperature, self.dutyCycle))
        # Logging.logEvent("Debug","Status Update",
        #     {"message": "{}: Current temp: {}".format(self.name,self.zoneProfile.getTemp(self.zoneProfile.average)),
        #     "level":2})
        # Logging.logEvent("Debug","Status Update",
        #     {"message": "{}: Temp Goal temperature is {}".format(self.name,self.temp_temperature),
        #     "level":2})
        # Logging.logEvent("Debug","Status Update",
        #     {"message": "{}: Current duty Cycle: {}".format(self.name,self.dutyCycle),
        #     "level":2})
        Logging.logExpectedTemperatureData({
            "expected_temp_values": [self.temp_temperature],
            "expected_time_values": [time.time()],
            "zone":
            self.name,
            "profileUUID":
            self.zoneProfile.profileUUID,
            "ProfileInstance":
            ProfileInstance.getInstance()
        })
Пример #5
0
    def __init__(self, parent=None):
        Logging.logEvent("Debug", "Status Update", {
            "message": "Creating DutyCycleControlStub",
            "level": 2
        })

        self.zoneProfiles = ProfileInstance.getInstance().zoneProfiles
        self.parent = parent
        Thread.__init__(self)
        self.updatePeriod = ProfileInstance.getInstance(
        ).zoneProfiles.updatePeriod
        self.d_out = HardwareStatusInstance.getInstance().PC_104.digital_out

        self.zones = {
            "zone1":
            ZoneControlStub(name='zone1',
                            lamps=['IR Lamp 1', 'IR Lamp 2'],
                            parent=self),
            "zone2":
            ZoneControlStub(name='zone2',
                            lamps=['IR Lamp 3', 'IR Lamp 4'],
                            parent=self),
            "zone3":
            ZoneControlStub(name='zone3',
                            lamps=['IR Lamp 6', 'IR Lamp 5'],
                            parent=self),
            "zone4":
            ZoneControlStub(name='zone4',
                            lamps=['IR Lamp 7', 'IR Lamp 8'],
                            parent=self),
            "zone5":
            ZoneControlStub(name='zone5',
                            lamps=['IR Lamp 9', 'IR Lamp 10'],
                            parent=self),
            "zone6":
            ZoneControlStub(name='zone6',
                            lamps=['IR Lamp 12', 'IR Lamp 11'],
                            parent=self),
            "zone7":
            ZoneControlStub(name='zone7',
                            lamps=['IR Lamp 13', 'IR Lamp 14'],
                            parent=self),
            "zone8":
            ZoneControlStub(name='zone8',
                            lamps=['IR Lamp 15', 'IR Lamp 16'],
                            parent=self),
            # zone9 is the platen
            "zone9":
            ZoneControlStub(name='zone9', parent=self)
        }

        self.currentSetpoint = 1
        self.ramp = False
        self.soak = False
Пример #6
0
    def __init__(self, parent=None, group=None, target=None, name=None,
                 args=(), kwargs=None, verbose=None):
        Thread.__init__(self, group=group, target=target, name=name)
        self.args = args
        self.kwargs = kwargs
        self.parent = parent

        self.pwr_supply = Tdk_lambda_Genesys()
        self.zoneProfiles = ProfileInstance.getInstance().zoneProfiles
        self.hw = HardwareStatusInstance.getInstance()
        self.ps_read_peroid = 4.0  # 0.5s loop period
Пример #7
0
 def SendHwCmd(self, data):
     if type(data) is not list:
         return '{"result":"Needs a json dictionary of a cmds."}'
     hw = HardwareStatusInstance.getInstance()
     Logging.debugPrint(3, "POST: SendHwCmd '%s'" % data)
     if data[0] == "Shi_MCC_Cmds":  # ['cmd', arg, arg,... arg]
         hw.Shi_MCC_Cmds.append(data[1:])
     elif data[0] == "Shi_Compressor_Cmds":  # 'cmd'
         hw.Shi_Compressor_Cmds.append(data[1])
     elif data[0] == "TdkLambda_Cmds":  # ['cmd', arg, arg,... arg]
         hw.TdkLambda_Cmds.append(data[1:])
     else:
         return '{"result":"Unknown Hardware Target."}'
     return '{"result":"success"}'
Пример #8
0
    def __init__(self,
                 parent=None,
                 group=None,
                 target=None,
                 name=None,
                 args=(),
                 kwargs=None,
                 verbose=None):
        Thread.__init__(self, group=group, target=target, name=name)
        self.args = args
        self.kwargs = kwargs
        self.parent = parent

        self.compressor = ShiCompressor()
        self.hw = HardwareStatusInstance.getInstance()
        self.compressor_read_period = 4  # 0.5s loop period
        self.op_hours_read_period = 120  # 120s = 2 min read period
Пример #9
0
    def __init__(self,
                 parent=None,
                 group=None,
                 target=None,
                 name=None,
                 args=(),
                 kwargs=None,
                 verbose=None):
        Thread.__init__(self, group=group, target=target, name=name)
        self.args = args
        self.kwargs = kwargs
        self.parent = parent

        self.mcc = Shi_Mcc()
        self.hw = HardwareStatusInstance.getInstance()
        self.mcc_read_period = 1  # 0.5s loop period
        self.param_period = 30  # 10 second period
Пример #10
0
    def __init__(self,
                 group=None,
                 target=None,
                 name=None,
                 args=(),
                 kwargs=None,
                 verbose=None):

        Logging.logEvent("Debug", "Status Update", {
            "message": "Creating VacuumControlStub:",
            "level": 3
        })

        Thread.__init__(self, group=group, target=target, name=name)
        self.args = args
        self.kwargs = kwargs

        self.zoneProfiles = ProfileInstance.getInstance().zoneProfiles
        self.profile = ProfileInstance.getInstance()
        self.hw = HardwareStatusInstance.getInstance()
        self.state = None
        self.pres_opVac = 9e-5
        self.pres_atm = 100
        self.pres_cryoP_Prime = 40e-3
        self.pres_chamber_crossover = 25e-3
        self.pres_chamber_max_crossover = 40e-3
        self.pres_min_roughing = 9e-4
        self.pres_ruffon = 70
        self.cryoPumpPressure = None
        self.chamberPressure = None
        self.roughPumpPressure = None

        self.updatePeriod = 1

        # # FOR TESTING ################################
        # self.state = "Operational Vacuum"
        # self.hw.OperationalVacuum = True
        # # FOR TESTING ################################

        if os.name == "posix":
            userName = os.environ['LOGNAME']
        else:
            userName = "******"
Пример #11
0
    def __init__(self,
                 parent=None,
                 group=None,
                 target=None,
                 name=None,
                 args=(),
                 kwargs=None,
                 verbose=None):
        Thread.__init__(self, group=group, target=target, name=name)
        self.args = args
        self.kwargs = kwargs
        self.parent = parent

        self.zoneProfiles = ProfileInstance.getInstance().zoneProfiles
        self.Pgauge = PfeifferGauge()
        self.hw = HardwareStatusInstance.getInstance()
        self.gauges = self.hw.PfeifferGuages
        self.pressure_read_peroid = 0.5  # 0.5s loop period
        self.param_period = 5  # 5 second period
Пример #12
0
    def __init__(self,
                 parent=None,
                 group=None,
                 target=None,
                 name=None,
                 args=(),
                 kwargs=None,
                 verbose=None):
        Thread.__init__(self, group=group, target=target, name=name)
        self.args = args
        self.kwargs = kwargs

        self.ts_reg = TS_Registers()
        self.da_io = PC_104_Instance.getInstance()
        self.hw = HardwareStatusInstance.getInstance()
        self.adc_period = 0.0125  # adc_clock*8 = 0.1s loop period
        self.pwm_period = 10  # 10 second pwm period
        # self.pwm_min_dc_sec = 1  # minimum Duty Cycle of 1 second
        self.ir_lamp_pwm = []
        self.time_test = time.time()
        self.parent = parent
Пример #13
0
 def heatUpPlaten(self, data):
     dutyCycle = float(data['dutyCycle'])
     tdKs = HardwareStatusInstance.getInstance().TdkLambda_PS
     if not ProfileInstance.getInstance().activeProfile:
         if dutyCycle == 0:
             if tdKs.get_platen_left(
             ).output_enable or tdKs.get_platen_right().output_enable:
                 HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                     ['Disable Platen Output'])
                 return "{'result':'Disabled Platen'}"
             else:
                 return "{'result':'Platen Off'}"
         else:
             if not (tdKs.get_platen_left().output_enable
                     and tdKs.get_platen_right().output_enable):
                 HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                     ['Setup Platen'])
             HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                 ['Platen Duty Cycle', dutyCycle])
             return "{'result':'Platen duty cycle set'}"
     else:
         return "{'result':'Not used in Profile'}"
Пример #14
0
 def heatUpShroud(self, data):
     dutyCycle = float(data['dutyCycle'])
     tdKs = HardwareStatusInstance.getInstance().TdkLambda_PS
     if not ProfileInstance.getInstance().activeProfile:
         if dutyCycle == 0:
             if tdKs.get_shroud_left(
             ).output_enable or tdKs.get_shroud_right().output_enable:
                 HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                     ['Disable Shroud Output'])
                 return "{'result':'Disabled Shroud'}"
             else:
                 return "{'result':'Shroud Off'}"
         else:
             if not (tdKs.get_shroud_left().output_enable
                     and tdKs.get_shroud_right().output_enable):
                 HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                     ['Setup Shroud'])
                 print("Turning on Shroud")
             HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                 ['Shroud Duty Cycle', dutyCycle])
             return "{'result':'Shroud duty cycle set'}"
     else:
         return "{'result':'Not used in Profile'}"
Пример #15
0
                        "level":
                        2
                    })
                if Logging.debug:
                    raise e
                self.compressor.close_port()
                time.sleep(4)


if __name__ == '__main__':
    # adding debug info
    if (len(sys.argv) > 1):
        for arg in sys.argv:
            if arg.startswith("-v"):
                Logging.verbos = arg.count("v")
    Logging.logEvent("Debug", "Status Update", {
        "message": "Debug on: Level {}".format(Logging.verbos),
        "level": 1
    })

    hw_status = HardwareStatusInstance.getInstance()
    hw_status.PC_104.digital_out.update({'CryoP Pwr Relay 1': True})

    thread = ShiCompressorUpdater()
    thread.daemon = True
    thread.start()

    while True:
        time.sleep(5)
        print(hw_status.ShiCryopump.getJson())
Пример #16
0
            'CC Correction': self.Pgauge.GetCorrCC(2)
        }, {
            'addr': 3,
            'Model Name': self.Pgauge.GetModelName(3),
            'Software Vir': self.Pgauge.GetSofwareV(3),
            'Pressure SP 1': self.Pgauge.GetSwPressure(3, True),
            'Pressure SP 2': self.Pgauge.GetSwPressure(3, False),
            'Pirani Correction': self.Pgauge.GetCorrPir(3)
        }]
        self.gauges.update(paramslist)


if __name__ == '__main__':
    # adding debug info
    if (len(sys.argv) > 1):
        for arg in sys.argv:
            if arg.startswith("-v"):
                Logging.verbos = arg.count("v")
    Logging.logEvent("Debug", "Status Update", {
        "message": "Debug on: Level {}".format(Logging.verbos),
        "level": 1
    })
    thread = PfeifferGaugeUpdater()
    thread.daemon = True
    thread.start()

    p = HardwareStatusInstance.getInstance().PfeifferGuages
    while True:
        time.sleep(5)
        print(p.getJson())
Пример #17
0
 def setPC104_Analog(self, data):
     pins = HardwareStatusInstance.getInstance().PC_104
     pins.analog_out.update(data)
     return "{'result':'success'}"
Пример #18
0
    def run(self):
        # While true to restart the thread if it errors out
        while True:
            # Check to make sure there is an active profile
            # and that we are sitting in an operational vacuum
            # and that all drivers and updaters are running
            a_out = self.hardwareStatus.getInstance().PC_104.analog_out  # todo: better variable name?
            d_out = self.hardwareStatus.getInstance().PC_104.digital_out
            a_out.update({'LN2 Shroud': 0,'LN2 Platen': 0})
            d_out.update({'LN2-S Sol': False, 'LN2-P Sol': False, })
            if ProfileInstance.getInstance().activeProfile and HardwareStatusInstance.getInstance().OperationalVacuum:
                # try and catch anything that might go wrong
                try:
                    # some start up stuff here
                    ln2_max = 0.1
                    ln2_min = -0.2 
                    valveMax = 4095/2
                    time.sleep(self.SLEEP_TIME)
                    # hwStatus = self.hardwareStatus.getInstance()
                    if os.name == "posix":
                        userName = os.environ['LOGNAME']
                    else:
                        userName = "******" 

                    # Normal program loop
                    while ProfileInstance.getInstance().activeProfile and HardwareStatusInstance.getInstance().OperationalVacuum:
                        dutycyclelist = []
                        platenDuty = None
                        for zoneStr in self.ThreadCollection.dutyCycleThread.zones:
                            
                            zone = self.ThreadCollection.dutyCycleThread.zones[zoneStr]
                            # If a zone doesn't have a dutyCycle, they aren't running, so we can safely ignore them
                            try:
                                if zoneStr != "zone9":
                                    dutycyclelist.append(zone.dutyCycle)
                                else:
                                    platenDuty = zone.dutyCycle
                            except Exception as e:
                                pass
                        if dutycyclelist:
                            dutycyclemin = min(dutycyclelist)
                            Logging.debugPrint(3,"Min Duty Cycle: {}".format(dutycyclemin))

                            if dutycyclemin < ln2_max: # todo: arb_value to be determined
                                # throw safety up
                                d_out.update({'LN2-S Sol': True})
                                # 2500 is the point the valve should be opened too
                                #a_out.update({'LN2 Shroud': 4095, 'LN2 Platen': 4095})
                                PercentVavleopen = valveMax*(dutycyclemin-ln2_max)/(ln2_min-ln2_max)
                                if dutycyclemin < ln2_min:
                                    PercentVavleopen = valveMax
                                a_out.update({'LN2 Shroud': PercentVavleopen})
                                Logging.debugPrint(3,"The Shroud LN2 should be on {}".format(PercentVavleopen))
                            else:
                                Logging.debugPrint(3,"The Shroud LN2 should be off")
                                # What's the difference between this and...
                                d_out.update({'LN2-S Sol': False})
                                a_out.update({'LN2 Shroud': 0})
                            # end of if/else
                        # end of if DutycycleList
                        if platenDuty:
                            if platenDuty < ln2_max: # todo: arb_value to be determined
                                # throw safety up
                                d_out.update({'LN2-P Sol': True})
                                # 2500 is the point the valve should be opened too
                                #a_out.update({'LN2 Shroud': 4095, 'LN2 Platen': 4095})
                                PercentVavleopen = valveMax*(platenDuty-ln2_max)/(ln2_min-ln2_max)
                                if platenDuty < ln2_min:
                                    PercentVavleopen = valveMax
                                a_out.update({'LN2 Platen': PercentVavleopen})
                                Logging.debugPrint(3,"The Platen LN2 should be on {}".format(PercentVavleopen))
                            else:
                                Logging.debugPrint(3,"The Platen LN2 should be off")
                                # What's the difference between this and...
                                d_out.update({'LN2-P Sol': False, })
                                a_out.update({'LN2 Platen': 0})
                        time.sleep(self.SLEEP_TIME)
                    # end of Inner While True
                except Exception as e:
                    Logging.debugPrint(1, "Error in run, LN2 Control Stub: {}".format(str(e)))
                    if Logging.debug:
                        raise e
                # end of try catch
            else:
                Logging.debugPrint(4,"LN2: AP: {}, Vacuum: {}".format(ProfileInstance.getInstance().activeProfile,HardwareStatusInstance.getInstance().OperationalVacuum))
            # end of If should be running
            time.sleep(self.SLEEP_TIME)
Пример #19
0
    def run(self):
        # This should always stay on
        while True:
            # initialization of the safety Thread
            try:
                # Temps are in Kelvin
                MAX_OPERATING_TEMP = 437
                # safe at all lower bounds
                # MIN_OPERATING_TEMP

                MAX_TOUCH_TEMP = 318.15
                MIN_TOUCH_TEMP = 269.15

                # TODO, make this user defined
                # These are test values, they will change when the code is written to change them
                self.MAX_UUT_TEMP = {}
                self.MIN_UUT_TEMP = {}

                SLEEP_TIME = 1  # in seconds

                # Used to keep track of the first time through a loop
                vacuum = False

                hardwareStatusInstance = HardwareStatusInstance.getInstance()

                Logging.logEvent("Debug", "Status Update", {
                    "message": "Starting Safety Checker Thread",
                    "level": 3
                })
                # stop when the program ends
                while True:
                    Logging.logEvent("Debug", "Status Update", {
                        "message": "Running Safety Checker Thread",
                        "level": 4
                    })

                    tempErrorDict = {
                        "System Alarm: High Temperature": False,
                        "Product Saver Alarm: High Temperature": False,
                        "Product Saver Alarm: Low Temperature": False,
                        "Human Touch Alarm: High Temperature": False,
                        "Human Touch Alarm: Low Temperature": False,
                        "Pressure Loss In Profile": False,
                    }
                    TCs = hardwareStatusInstance.Thermocouples.ValidTCs
                    for tc in TCs:
                        # if there are any TC's higher than max temp
                        if tc.temp > MAX_OPERATING_TEMP:
                            # print("{}-> {}".format(tc.Thermocouple, tc.temp))
                            errorDetail = "TC # {} is above MAX_OPERATING_TEMP ({}). Currently {}c".format(
                                tc.Thermocouple, MAX_OPERATING_TEMP, tc.temp)
                            error = {
                                "time": str(datetime.now()),
                                "event": "System Alarm: High Temperature",
                                "item": "Thermocouple",
                                "itemID": tc.Thermocouple,
                                "details": errorDetail,
                                "actions": ["Turned off heater", "Log Event"]
                            }
                            self.logEvent(error)
                            tempErrorDict[error['event']] = True

                            d_out = HardwareStatusInstance.getInstance(
                            ).PC_104.digital_out
                            ProfileInstance.getInstance().activeProfile = False
                            Logging.debugPrint(
                                1,
                                "ERROR Heat was above max operating temperature ({})"
                                .format(tc.temp))
                            vacuum = False
                            d_out.update({"IR Lamp 1 PWM DC": 0})
                            d_out.update({"IR Lamp 2 PWM DC": 0})
                            d_out.update({"IR Lamp 3 PWM DC": 0})
                            d_out.update({"IR Lamp 4 PWM DC": 0})
                            d_out.update({"IR Lamp 5 PWM DC": 0})
                            d_out.update({"IR Lamp 6 PWM DC": 0})
                            d_out.update({"IR Lamp 7 PWM DC": 0})
                            d_out.update({"IR Lamp 8 PWM DC": 0})
                            d_out.update({"IR Lamp 9 PWM DC": 0})
                            d_out.update({"IR Lamp 10 PWM DC": 0})
                            d_out.update({"IR Lamp 11 PWM DC": 0})
                            d_out.update({"IR Lamp 12 PWM DC": 0})
                            d_out.update({"IR Lamp 13 PWM DC": 0})
                            d_out.update({"IR Lamp 14 PWM DC": 0})
                            d_out.update({"IR Lamp 15 PWM DC": 0})
                            d_out.update({"IR Lamp 16 PWM DC": 0})

                            HardwareStatusInstance.getInstance(
                            ).TdkLambda_Cmds.append(['Shroud Duty Cycle', 0])
                            HardwareStatusInstance.getInstance(
                            ).TdkLambda_Cmds.append(['Platen Duty Cycle', 0])

                            releaseHoldThread()
                        # end of max operational test

                        if tc.userDefined:
                            # print("tc: {} zone: {}".format(tc.Thermocouple,tc.zone))
                            if tc.zone != 0:
                                if tc.temp > ProfileInstance.getInstance(
                                ).zoneProfiles.getZone(tc.zone).maxHeatError:
                                    errorDetail = "TC # {} is above MAX_UUT_TEMP ({}). Currently {}c".format(
                                        tc.Thermocouple,
                                        ProfileInstance.getInstance().
                                        zoneProfiles.getZone(
                                            tc.zone).maxHeatError, tc.temp)
                                    error = {
                                        "time":
                                        str(datetime.now()),
                                        "event":
                                        "Product Saver Alarm: High Temperature",
                                        "item":
                                        "Thermocouple",
                                        "itemID":
                                        tc.Thermocouple,
                                        "details":
                                        errorDetail,
                                        "actions":
                                        ["Turned off heater", "Log Event"]
                                    }
                                    self.logEvent(error)
                                    tempErrorDict[error['event']] = True
                                # end of max user test

                                if tc.temp < ProfileInstance.getInstance(
                                ).zoneProfiles.getZone(tc.zone).minHeatError:
                                    errorDetail = "TC # {} is below MIN_UUT_TEMP ({}). Currently {}c".format(
                                        tc.Thermocouple,
                                        ProfileInstance.getInstance().
                                        zoneProfiles.getZone(
                                            tc.zone).minHeatError, tc.temp)
                                    error = {
                                        "time":
                                        str(datetime.now()),
                                        "event":
                                        "Product Saver Alarm: Low Temperature",
                                        "item":
                                        "Thermocouple",
                                        "itemID":
                                        tc.Thermocouple,
                                        "details":
                                        errorDetail,
                                        "actions":
                                        ["Turned off LN flow", "Log Event"]
                                    }
                                    self.logEvent(error)
                                    tempErrorDict[error['event']] = True
                        # end of min user test
                        # end of user test

                        # Get the full list
                        OutsideThermoCouples = []
                        if tc.Thermocouple in OutsideThermoCouples:
                            if tc.temp > MAX_TOUCH_TEMP:
                                errorDetail = "TC # {} is above MAX_TOUCH_TEMP ({}). Currently {}c".format(
                                    tc.Thermocouple, MAX_TOUCH_TEMP, tc.temp)
                                error = {
                                    "time": str(datetime.now()),
                                    "event":
                                    "Human Touch Alarm: High Temperature",
                                    "item": "Thermocouple",
                                    "itemID": tc.Thermocouple,
                                    "details": errorDetail,
                                    "actions": ["Log Event"]
                                }
                                self.logEvent(error)
                                tempErrorDict[error['event']] = True
                            # end of max touch test

                            if tc.temp < MIN_TOUCH_TEMP:
                                errorDetail = "TC # {} is below MIN_TOUCH_TEMP ({}). Currently {}c".format(
                                    tc.Thermocouple, MIN_TOUCH_TEMP, tc.temp)
                                error = {
                                    "time": str(datetime.now()),
                                    "event":
                                    "Human Touch Alarm: Low Temperature",
                                    "item": "Thermocouple",
                                    "itemID": tc.Thermocouple,
                                    "details": errorDetail,
                                    "actions": ["Log Event"]
                                }
                                self.logEvent(error)
                                tempErrorDict[error['event']] = True
                    # end of min touch test
                    # if of outside thermaltest
                    # End of TC for loop

                    for errorType in self.errorDict:
                        # for every type of error
                        if self.errorDict[
                                errorType] and not tempErrorDict[errorType]:
                            # It was true and now is not, log it.

                            # make a event log
                            errorLog = {
                                "time": str(datetime.now()),
                                "event": errorType,
                                "item": "Thermocouple",
                                "itemID": tc.Thermocouple,
                                "details": "The current event has ended",
                                "actions": ["Log Event"]
                            }
                            self.logEvent(errorLog)

                    self.errorDict = tempErrorDict

                    # Logging if you've entered operational vacuum, and then left it
                    # TODO: OperationalVacuum can't be updated if there isn't an active profile...this needs to change
                    if HardwareStatusInstance.getInstance().OperationalVacuum:
                        vacuum = True

                    if os.name == "posix":
                        userName = os.environ['LOGNAME']
                    else:
                        userName = "******"
                    if "root" in userName:
                        if vacuum and HardwareStatusInstance.getInstance(
                        ).PfeifferGuages.get_chamber_pressure() > 1e-4:
                            d_out = HardwareStatusInstance.getInstance(
                            ).PC_104.digital_out
                            ProfileInstance.getInstance().activeProfile = False
                            Logging.debugPrint(
                                1,
                                "ERROR Pressure is above 10^-4. ({})".format(
                                    HardwareStatusInstance.getInstance(
                                    ).PfeifferGuages.get_chamber_pressure()))
                            vacuum = False
                            # TODO: Send Error
                            d_out.update({"IR Lamp 1 PWM DC": 0})
                            d_out.update({"IR Lamp 2 PWM DC": 0})
                            d_out.update({"IR Lamp 3 PWM DC": 0})
                            d_out.update({"IR Lamp 4 PWM DC": 0})
                            d_out.update({"IR Lamp 5 PWM DC": 0})
                            d_out.update({"IR Lamp 6 PWM DC": 0})
                            d_out.update({"IR Lamp 7 PWM DC": 0})
                            d_out.update({"IR Lamp 8 PWM DC": 0})
                            d_out.update({"IR Lamp 9 PWM DC": 0})
                            d_out.update({"IR Lamp 10 PWM DC": 0})
                            d_out.update({"IR Lamp 11 PWM DC": 0})
                            d_out.update({"IR Lamp 12 PWM DC": 0})
                            d_out.update({"IR Lamp 13 PWM DC": 0})
                            d_out.update({"IR Lamp 14 PWM DC": 0})
                            d_out.update({"IR Lamp 15 PWM DC": 0})
                            d_out.update({"IR Lamp 16 PWM DC": 0})

                            HardwareStatusInstance.getInstance(
                            ).TdkLambda_Cmds.append(['Shroud Duty Cycle', 0])
                            HardwareStatusInstance.getInstance(
                            ).TdkLambda_Cmds.append(['Platen Duty Cycle', 0])

                            releaseHoldThread()

                        # end if vacuum in bad condintion
                    # end if root
                    time.sleep(SLEEP_TIME)
            # end of inner while true loop
            except Exception as e:
                Logging.debugPrint(
                    1, "Error in Safety Checker: {}".format(str(e)))
                if Logging.debug:
                    raise e
                time.sleep(SLEEP_TIME)
Пример #20
0
            if arg.startswith("-v"):
                Logging.verbos = arg.count("v")
    if(len(sys.argv)>2):
        for arg in sys.argv:
            if "--debug" in arg:
                Logging.debug = True
    Logging.logEvent("Debug","Status Update",
        {"message": "Verbos on: Level {}".format(Logging.verbos),
         "level":1})
    PORT = 8000

    Logging.logEvent("Debug","Status Update",
        {"message": "Starting initializing threads and drivers",
         "level":1})

    hardwareStatusInstance = HardwareStatusInstance.getInstance()
    profileInstance = ProfileInstance.getInstance()
    threadInstance = ThreadCollectionInstance.getInstance()

    Logging.logEvent("Event","System",
        {"message": "Server is fully booted",
        "ProfileInstance": profileInstance.getInstance()})
    Logging.logEvent("Debug","Status Update",
        {"message": "Finished initializing threads and drivers",
         "level":1})

    httpd = ReuseAddrTCPServer(("", PORT), VerbHandler)

    Logging.logEvent("Debug","Status Update",
        {"message": "Start Up Complete, Server is listening for request...",
         "level":1})
Пример #21
0
    def run(self):
        # While true to restart the thread if it errors out
        while True:
            # Check to make sure there is an active profile
            # and that we are sitting in an operational vacuum
            # and that all drivers and updaters are running
            if ProfileInstance.getInstance().activeProfile and \
                HardwareStatusInstance.getInstance().OperationalVacuum and \
                ProfileInstance.getInstance().zoneProfiles.getActiveProfileStatus():
                try:
                    Logging.logEvent("Debug", "Status Update", {
                        "message": "DCCS: Starting Duty Cycle thread",
                        "level": 2
                    })

                    Logging.logEvent(
                        "Event", "Start Profile", {
                            'time': datetime.time(),
                            "message": ProfileInstance.getInstance().
                            zoneProfiles.profileName,
                            "ProfileInstance": ProfileInstance.getInstance()
                        })

                    ProfileInstance.getInstance(
                    ).zoneProfiles.updateThermalStartTime(time.time())

                    # local temp variables for checking state
                    #TODO: Start time should gotten somewhere else, not made here
                    if self.zoneProfiles.thermalStartTime:
                        self.startTime = self.zoneProfiles.thermalStartTime
                    else:
                        self.startTime = int(time.time())
                    currentSetpointTemporary = 1
                    rampTemporary = False
                    soakTemporary = True

                    Logging.logEvent("Debug", "Status Update", {
                        "message": "DCCS: Setting up Platen",
                        "level": 2
                    })
                    HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                        ['Setup Platen', ''])

                    for zone in self.zones:
                        if self.zones[zone].zoneProfile.activeZoneProfile:
                            self.zones[zone].maxTempRisePerMin = self.zones[
                                zone].zoneProfile.maxHeatPerMin
                            self.zones[zone].maxTempRisePerUpdate = (
                                self.zones[zone].maxTempRisePerMin /
                                60) * self.updatePeriod
                            self.zones[
                                zone].expected_temp_values, self.expected_time_values = self.zones[
                                    zone].createExpectedValues(
                                        self.zones[zone].zoneProfile.
                                        thermalProfiles,
                                        startTime=self.zoneProfiles.
                                        thermalStartTime)
                    # Program loop is here
                    while ProfileInstance.getInstance().activeProfile:

                        Logging.logEvent(
                            "Debug", "Status Update", {
                                "message": "DCCS: Running Duty Cycle Thread",
                                "level": 3
                            })

                        # You might need to stay is pause

                        # get current time
                        currentTime = time.time()

                        # if there is no more expected time values, break out of while True loop
                        if len(self.expected_time_values) <= 0:
                            break

                        # this will find the time value matching the current time
                        # and give us the temp value it should be at that time.
                        # print("currentTime: {}".format(currentTime))
                        # print("expected_time_values: {}".format(self.expected_time_values))
                        while currentTime > self.expected_time_values[0]:

                            for zone in self.zones:
                                if self.zones[
                                        zone].zoneProfile.activeZoneProfile:
                                    self.zones[
                                        zone].temp_temperature = self.zones[
                                            zone].expected_temp_values[0]
                                    self.zones[
                                        zone].expected_temp_values = self.zones[
                                            zone].expected_temp_values[1:]
                            self.expected_time_values = self.expected_time_values[
                                1:]
                            if len(self.setpoint_start_time) > 0:
                                if currentTime > self.setpoint_start_time[0][0]:
                                    rampTemporary = True
                                    soakTemporary = False
                                    if currentTime > self.setpoint_start_time[
                                            0][1]:
                                        rampTemporary = False
                                        soakTemporary = True
                                        self.setpoint_start_time = self.setpoint_start_time[
                                            1:]
                                        currentSetpointTemporary += 1
                                    if len(self.setpoint_start_time) <= 0:
                                        break

                            if len(self.expected_time_values) <= 0:
                                break

                        self.checkPause()
                        self.checkHold()
                        # compare the temps just made with the values in self.
                        # if they are different, or important log it
                        if rampTemporary == True and self.ramp == False:
                            ProfileInstance.getInstance(
                            ).currentSetpoint = currentSetpointTemporary
                            Logging.logEvent(
                                "Event", "Profile", {
                                    "message":
                                    "Profile {} has entered setpoint {} Ramp".
                                    format(
                                        ProfileInstance.getInstance(
                                        ).zoneProfiles.profileName,
                                        currentSetpointTemporary),
                                    "ProfileInstance":
                                    ProfileInstance.getInstance()
                                })
                        if soakTemporary == True and self.soak == False:
                            if currentSetpointTemporary > 1:
                                Logging.logEvent(
                                    "Event", "Profile", {
                                        "message":
                                        "Profile {} has entered setpoint {} Soak"
                                        .format(
                                            ProfileInstance.getInstance(
                                            ).zoneProfiles.profileName,
                                            currentSetpointTemporary - 1),
                                        "ProfileInstance":
                                        ProfileInstance.getInstance()
                                    })
                                ProfileInstance.getInstance.inRamp = False
                        self.ramp = rampTemporary
                        self.soak = soakTemporary
                        # With the temp goal tempurture picked, make the duty cycle
                        for zone in self.zones:
                            if self.zones[zone].zoneProfile.activeZoneProfile:
                                # This checks to see if a current temp has been made...
                                if self.zones[zone].temp_temperature:
                                    self.zones[zone].updateDutyCycle()
                                else:
                                    print("Waiting...")

                            if len(self.expected_time_values) <= 0:
                                break
                        # sleep until the next time around
                        time.sleep(self.updatePeriod)
                    # end of inner while True
                    # end of test

                    # turning off lamps at the end of test

                    for zone in self.zones:
                        if self.zones[zone].zoneProfile.activeZoneProfile:

                            zone = self.zones[zone]
                            if zone.lamps:
                                self.d_out.update(
                                    {zone.lamps[1] + " PWM DC": 0})
                                self.d_out.update(
                                    {zone.lamps[0] + " PWM DC": 0})
                            else:
                                HardwareStatusInstance.getInstance(
                                ).TdkLambda_Cmds.append(
                                    ['Platen Duty Cycle', 0])
                    #TODO: Turn off the heaters here

                    Logging.logEvent(
                        "Event", "End Profile", {
                            'time': datetime.time(),
                            "message": ProfileInstance.getInstance().
                            zoneProfiles.profileName,
                            "ProfileInstance": ProfileInstance.getInstance()
                        })

                    HardwareStatusInstance.getInstance().TdkLambda_Cmds.append(
                        ['Disable Platen Output', ''])

                    self.updateDBwithEndTime()
                    self.running = False
                    tcList = HardwareStatusInstance.getInstance(
                    ).Thermocouples.tcList
                    for tc in tcList:
                        tc.update({"zone": 0, "userDefined": False})

                    # self.zoneProfile.activeZoneProfile = False
                    # This assumes all zones have the same end time
                    ProfileInstance.getInstance().activeProfile = False
                    ProfileInstance.getInstance().vacuumWanted = False
                except Exception as e:
                    exc_type, exc_obj, exc_tb = sys.exc_info()
                    fname = os.path.split(
                        exc_tb.tb_frame.f_code.co_filename)[1]
                    print("Error: {} in file {}:{}".format(
                        exc_type, fname, exc_tb.tb_lineno))

                    self.running = False
                    ProfileInstance.getInstance(
                    ).zoneProfiles.activeProfile = False
                    Logging.debugPrint(
                        1, "DCCS: Error in run, Duty Cycle: {}".format(str(e)))
                    Logging.logEvent(
                        "Error", "Duty Cycle Control Stub Thread", {
                            "type": exc_type,
                            "filename": fname,
                            "line": exc_tb.tb_lineno,
                            "thread": "DutyCycleControlStub",
                            "ThreadCollection": self.parent,
                            "item": "Duty Cycle Control Stub",
                            "itemID": -1,
                            "details":
                            "There is a software error ({})".format(e)
                        })

                    if Logging.debug:
                        raise e
                # end of try, catch
            else:
                Logging.debugPrint(
                    4, "DCCS: activeProfile: {}".format(
                        ProfileInstance.getInstance().activeProfile))
                Logging.debugPrint(
                    4, "DCCS: OperationalVacuum: {}".format(
                        HardwareStatusInstance.getInstance().OperationalVacuum)
                )
                Logging.debugPrint(
                    4, "DCCS: getActiveProfileStatus: {}".format(
                        ProfileInstance.getInstance(
                        ).zoneProfiles.getActiveProfileStatus()))
            # Sleeping so it doesn't busy wait
            time.sleep(1)