def main(): """Main function""" # Parse arguments parser = argparse.ArgumentParser(description=('Runs a stepped power supply program on ' 'a specified power supply and channel')) parser.add_argument('power_supply', choices=('A', 'B', 'C'), help='The capital lette of a power supply e.g. A') parser.add_argument('output', choices=('1', '2'), help='The output number on that power supply. Must be 1 or 2') parser.add_argument('program_file', help="The file that contains the ramp") args = parser.parse_args() global LOG LOG = get_logger( 'STACK TESTER ' + args.power_supply + args.output, level='debug', file_log=True, terminal_log=True, file_name='stack_tester_' + args.power_supply + args.output + '.log', email_on_warnings=False, email_on_errors=False, ) global LOCK_FILE psu_name = '{}{}'.format(args.power_supply, args.output) LOCK_FILE = path.join(THIS_DIR, 'LOCK{}'.format(psu_name)) print(LOCK_FILE) if path.isfile(LOCK_FILE): message = ( 'Stacktester {0} already running\n' '\n' 'The lock file "LOCK{0}" is in place, which indicates ' 'that this stack tester is already running.\n' '\n' 'If you know that it is not true, delete the lock file.') LOCK_FILE = None raise RuntimeError(message.format(psu_name)) # Lock to prevent multiple clients on same channel with open(LOCK_FILE, 'w') as file__: # pylint: disable=unused-variable pass # Check if the server is up if _send_command("1", args.power_supply, 'PING') == 'PONG': LOG.debug('Got PONG from server') SOCK.settimeout(None) # Init program my_program = VoltageCurrentProgram(args) my_program.start() # Appearently, it is better to defined app at the module level for # clean up: http://stackoverflow.com/questions/27131294/ # error-qobjectstarttimer-qtimer-can-only-be-used-with-threads-started-with-qt global APP # pylint: disable=global-variable-undefined APP = QApplication(sys.argv) SteppedProgramRunner(my_program) print('BEFORE app exec') sys.exit(APP.exec_()) print('AFTER app exec')
from time import sleep, time from collections import defaultdict from pprint import pprint from PyExpLabSys.drivers.dataq_binary import DI1110 from PyExpLabSys.combos import LiveContinuousLogger from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python3_only # Note, this file makes use of Python 3 division rules, so it cannot be run on Python 2 # without modification python3_only(__file__) # Setup logger LOG = get_logger('gas_levels307', level='debug') LOG.info('start') CODENAMES = { # The position in the lists corresponds to data cards channel position 'atex': [ 'gassupply_307_ch4_right', 'gassupply_307_ch4_left', 'gassupply_307_h2_right', 'gassupply_307_h2_left', 'gassupply_307_CO_left', 'gassupply_307_CO_right', ], 'regular': [ 'gassupply_307_Ar_right', 'gassupply_307_Ar_left',
""" Pressure and temperature logger, PVD309""" from __future__ import print_function import threading import time from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.value_logger import ValueLogger import PyExpLabSys.drivers.intellemetrics_il800 as intellemetrics_il800 import PyExpLabSys.drivers.inficon_sqm160 as inficon_sqm160 from PyExpLabSys.common.utilities import get_logger import credentials LOGGER = get_logger('PVD309 QCM', level='info', file_log=True, file_name='qcm_log.txt', terminal_log=True) class QcmReader(threading.Thread): """ QCM Reader """ def __init__(self, qcm): threading.Thread.__init__(self) self.qcm = qcm self.rate = None self.thickness = None self.frequency = None self.quit = False self.ttl = 20 def value(self, channel): """ Read values """ self.ttl = self.ttl - 1 if self.ttl < 0:
from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.microreactor_temperature_control import HeaterClass from PyExpLabSys.common.microreactor_temperature_control import CursesTui import PyExpLabSys.common.utilities from PyExpLabSys.common.supported_versions import python2_and_3 PyExpLabSys.common.utilities.ERROR_EMAIL = '*****@*****.**' python2_and_3(__file__) try: MICRO = chr(0x03BC) # Python 2 except ValueError: MICRO = unichr(0x03BC) # Python 2 LOGGER = get_logger(MICRO + '-reactor Temperature control', level='WARN', file_log=True, file_name='temp_control.log', terminal_log=False, email_on_warnings=False) activate_library_logging('PyExpLabSys.common.microreactor_temperature_control', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.auxiliary.pid', logger_to_inherit_from=LOGGER) LOGGER.warn('Program started') class RtdReader(threading.Thread): """ Read resistance of RTD and calculate temperature """ def __init__(self, calib_temp): visa_string = 'usb0::2391::1543::MY47002726::INSTR'
import time from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.supported_versions import python2_and_3 python2_and_3(__file__) try: sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) except IndexError: print('You need to give the name of the raspberry pi as an argument') print('This will ensure that the correct settings file will be used') exit() import settings # pylint: disable=F0401 import credentials LOGGER = get_logger('Socket Dataplot Logger', level='ERROR', file_log=True, file_name='errors.log', terminal_log=False, email_on_warnings=False) class SocketReaderClass(threading.Thread): """ Read the wanted socket """ def __init__(self, host, port, command): threading.Thread.__init__(self) self.host = host self.port = port self.command = command + '#raw' self.command = self.command.encode() self.current_value = None self.quit = False self.ttl = 10 def value(self): """ return current value """
import PyExpLabSys.drivers.pfeiffer_qmg420 as qmg420 import PyExpLabSys.drivers.pfeiffer_qmg422 as qmg422 import PyExpLabSys.apps.qms.qms as ms import PyExpLabSys.apps.qms.qmg_status_output as qmg_status_output import PyExpLabSys.apps.qms.qmg_meta_channels as qmg_meta_channels from PyExpLabSys.common.sockets import LiveSocket, DateDataPullSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.utilities import activate_library_logging from PyExpLabSys.common.supported_versions import python2_and_3 BASEPATH = os.path.abspath(__file__)[:os.path.abspath(__file__).find('PyExpLabSys')] sys.path.append(BASEPATH + '/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=wrong-import-position python2_and_3(__file__) LOGGER = get_logger('Mass Spec', level='warning', file_log=True, file_name='qms.txt', terminal_log=False, email_on_warnings=False, email_on_errors=False, file_max_bytes=104857600, file_backup_count=5) activate_library_logging('PyExpLabSys.drivers.pfeiffer_qmg422', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.apps.qms.qmg_status_output', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.apps.qms.qmg_meta_channels', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.apps.qms.qms', logger_to_inherit_from=LOGGER) try: from local_channels import Local LOCAL_READER = Local() LOCAL_READER.daemon = True
""" QCM logger, PVD309. Originally on rasppi106, but moved here due to repurposing of the rasppi.""" from __future__ import print_function import threading import time from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.value_logger import ValueLogger import PyExpLabSys.drivers.intellemetrics_il800 as intellemetrics_il800 import PyExpLabSys.drivers.inficon_sqm160 as inficon_sqm160 from PyExpLabSys.common.utilities import get_logger import credentials LOGGER = get_logger('PVD309 QCM', level='info', file_log=True, file_name='qcm_log.txt', terminal_log=True) class QcmReader(threading.Thread): """ QCM Reader """ def __init__(self, qcm): threading.Thread.__init__(self) self.qcm = qcm self.rate = None self.thickness = None self.frequency = None self.quit = False self.ttl = 20
"""Continous logger for the Pfeiffer gauges on the theta probe""" import time from PyExpLabSys.drivers.pfeiffer import TPG262 from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import LiveSocket import credentials LOGGER = get_logger('thetaprobe_pressure_logger', file_log=True) def main(): """The main method for the pressure logger""" # Open communication to the pressure measurement unit tpg = TPG262(port='/dev/ttyUSB0', baudrate=9600) LOGGER.info('Initiated driver to TPG 262') # Get a continuous logger codenames = ['thetaprobe_pressure_loadlock', 'thetaprobe_pressure_uvgun'] db_logger = ContinuousLogger(table='dateplots_thetaprobe', username=credentials.USERNAME, password=credentials.PASSWORD, measurement_codenames=codenames) db_logger.start() LOGGER.info('Initiated and started database logger') livesocket = LiveSocket(codenames, 0.2) livesocket.start()
""" Data logger for the PVD309 effusion cells """ import threading import time from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.drivers.omega_cni as omega_cni import PyExpLabSys.drivers.omega_cn7800 as omega_cn7800 import credentials LOGGER = get_logger('PVD309', level='info', file_log=True, file_name='pvd309_effusion_log.txt', terminal_log=False) class TemperatureReader(threading.Thread): """ Communicates with the Omega Controllers """ def __init__(self): cn7800_port = '/dev/serial/by-id/usb-FTDI_USB-RS485_Cable_FTY0VXC8-if00-port0' self.cn7800 = omega_cn7800.CN7800(cn7800_port) self.temp_dca = self.cn7800.read_temperature() cni_port = '/dev/serial/by-id/usb-FTDI_USB-RS485_Cable_FTY0EQZZ-if00-port0' self.cni = omega_cni.ISeries(cni_port, 9600, comm_stnd='rs485') self.temp_mai = self.cni.read_temperature(1) threading.Thread.__init__(self) self.quit = False
if path.isfile(LOCK_FILE): MESSAGE = ( 'Server already running\n' '\n' 'The server lock file "SERVER_LOCK" is in place, which indicates that ' 'the server is already running.\n' '\n' 'If you know that it is not true, delete the lock file.') raise RuntimeError(MESSAGE) # Lock to prevent multiple servers with open(LOCK_FILE, 'w') as file_: pass LOG = get_logger('H2O2 CPX Serv', level='debug', file_log=True, file_name='server.log', file_backup_count=1, file_max_bytes=1048576) STOP_SERVER = False class CPXServer(object): """Server for CPX400DP power supplies""" def __init__(self, devices=None): """Initialize CPXServer Args: devices (dict): Mapping of power supply names (letters) to hostnames. E.g: {'A': '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_C2F95400-if00', 'B': '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_12345600-if00'} """
import telnetlib import socket import threading import time try: import Queue as queue except ImportError: import queue import json import MySQLdb from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 python2_and_3(__file__) LOGGER = get_logger('Host Checker', level='debug', file_log=True, file_name='host_checker.log', terminal_log=True, email_on_warnings=False, email_on_errors=False, file_max_bytes=104857, file_backup_count=5) def host_status(hostname, port): """ Report if a host i available on the network """ host_is_up = True if port != '3389': try: subprocess.check_output(["ping", "-c1", "-W1", hostname]) except subprocess.CalledProcessError: host_is_up = False if port == 3389: # RDP try: _ = telnetlib.Telnet(hostname, 3389) except socket.gaierror:
import threading import socket import json import xml.etree.ElementTree as XML # Used for logging output from twisted, see commented out lines below # from twisted.python import log from twisted.internet import reactor, ssl from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS from PyExpLabSys.common.sockets import LiveSocket LIVESOCKET = None from PyExpLabSys.common.utilities import get_logger LOG = get_logger("ws-server", level="debug", file_log=True, file_max_bytes=10485760) MALFORMED_SUBSCRIPTION = "Error: Malformed subscription line: {}" DATA = {} TIME_REPORT_ALIVE = 60 # Seconds between the thread reporting in WEBSOCKET_IDS = set() # Used only to count open connections CURRENT_CONNECTIONS = "/home/kenni/PyExpLabSys/machines/websocketserver/" "current_connections" def current_log(text): """Log a message to the current file""" with open(CURRENT_CONNECTIONS, "a") as file_: file_.write(text + "\n") class CinfWebSocketHandler(WebSocketServerProtocol): # pylint: disable=W0232
import credentials # Wait time in seconds between serial communications WAIT = 0.25 # codename : (address, key) CODENAME_TRANSLATION = { 'omicron_ana_pressure': (2, 'ion_gauge_1_pressure'), 'omicron_prep_pressure': (1, 'ion_gauge_1_pressure'), 'omicron_roughing_2_prep': (1, 'slot_a_value_1'), 'omicron_roughing_1_ana': (2, 'slot_a_value_1'), 'omicron_roughing_3_diff': (2, 'slot_b_value_1'), } EXTRA_LIVE = {} LOG = get_logger('pvci_monitor', level='warning') class ValuePrinter(threading.Thread): """Print values nicely in terminal""" def __init__(self, logger): """Initialize""" threading.Thread.__init__(self) self.logger = logger self.values = dict(self.logger.values) self.printing = True self.screen = curses.initscr() self.win = curses.newwin(10, 50, 0, 0) curses.cbreak() curses.noecho()
""" Pressure and temperature logger, PVD309""" from __future__ import print_function import threading import time from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.value_logger import ValueLogger import PyExpLabSys.drivers.intellemetrics_il800 as intellemetrics_il800 import PyExpLabSys.drivers.inficon_sqm160 as inficon_sqm160 from PyExpLabSys.common.utilities import get_logger import credentials LOGGER = get_logger("PVD309 QCM", level="info", file_log=True, file_name="qcm_log.txt", terminal_log=True) class QcmReader(threading.Thread): """ QCM Reader """ def __init__(self, qcm): threading.Thread.__init__(self) self.qcm = qcm self.rate = None self.thickness = None self.frequency = None self.quit = False self.ttl = 20 def value(self, channel): """ Read values """ self.ttl = self.ttl - 1
import time from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.supported_versions import python2_and_3 python2_and_3(__file__) try: sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) except IndexError: print('You need to give the name of the raspberry pi as an argument') print('This will ensure that the correct settings file will be used') exit() import settings # pylint: disable=F0401 LOGGER = get_logger('Socket Dataplot Logger', level='ERROR', file_log=True, file_name='errors.log', terminal_log=False, email_on_warnings=False) class SocketReaderClass(threading.Thread): """ Read the wanted socket """ def __init__(self, host, port, command): threading.Thread.__init__(self) self.host = host self.port = port self.command = command + '#raw' self.command = self.command.encode() self.current_value = None self.quit = False self.ttl = 10 def value(self): """ return current value """
import time import threading import socket import json import xml.etree.ElementTree as XML # Used for logging output from twisted, see commented out lines below #from twisted.python import log from twisted.internet import reactor, ssl from autobahn.websocket import WebSocketServerFactory, \ WebSocketServerProtocol, listenWS from PyExpLabSys.common.sockets import LiveSocket LIVESOCKET = None from PyExpLabSys.common.utilities import get_logger LOG = get_logger('ws-server', level='debug', file_log=True, file_max_bytes=10485760) MALFORMED_SUBSCRIPTION = 'Error: Malformed subscription line: {}' DATA = {} TIME_REPORT_ALIVE = 60 # Seconds between the thread reporting in WEBSOCKET_IDS = set() # Used only to count open connections CURRENT_CONNECTIONS = '/home/kenni/PyExpLabSys/machines/websocketserver/'\ 'current_connections' def current_log(text): """Log a message to the current file""" with open(CURRENT_CONNECTIONS, 'a') as file_: file_.write(text + '\n')
""" Module to check that local machine is living up to its duties """ import time from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import DateDataPullSocket import threading import socket import sys sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=F0401 LOGGER = get_logger('Socket Supervisor') class SocketSupervisor(threading.Thread): """ Supervisor will check that a list of ports are still open """ def __init__(self): threading.Thread.__init__(self) self.quit = False self.ports = settings.ports self.setup = settings.setup print self.ports print len(self.ports) print[str(port) for port in self.ports] self.pullsocket = DateDataPullSocket( self.setup + '-socket supervisor', [str(port) for port in self.ports], timeouts=len(self.ports) * [5]) self.pullsocket.start() def run(self):
def main(): """ Main function """ log = get_logger('pressure readout', level='debug') #logging.basicConfig(filename="logger.txt", level=logging.ERROR) #logging.basicConfig(level=logging.ERROR) port = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port' port = '/dev/ttyUSB0' codenames = ['xrd_pressure_turbo_gas_system', 'xrd_pressure_gas_system_wrg', 'xrd_pressure_mass_spec_wrg', 'xrd_pressure_gas_system_baratron'] reader = PressureReader(port) reader.daemon = True reader.start() loggers = {} loggers[codenames[0]] = ValueLogger(reader, comp_val=0.02, comp_type='log', channel=1) loggers[codenames[1]] = ValueLogger(reader, comp_val=0.02, comp_type='log', channel=2) loggers[codenames[2]] = ValueLogger(reader, comp_val=0.02, comp_type='log', channel=3) loggers[codenames[3]] = ValueLogger(reader, comp_val=2, comp_type='lin', channel=4) for i in range(0, 4): loggers[codenames[i]].start() socket = DateDataPullSocket('XRD Pressure', codenames, timeouts=[2.0] * len(codenames)) socket.start() log.info('DateDataPullSocket started') live_socket = LiveSocket('XRD pressure', codenames) live_socket.start() log.info('LiveSocket started') db_logger = ContinuousDataSaver(continuous_data_table='dateplots_xrd', username=credentials.user, password=credentials.passwd, measurement_codenames=codenames) db_logger.start() log.info('ContinuousDataSaver started') time.sleep(5) try: while True: time.sleep(0.25) for name in codenames: value = loggers[name].read_value() log.debug('Read codename %s value %s', name, value) socket.set_point_now(name, value) live_socket.set_point_now(name, value) if loggers[name].read_trigged(): log.debug('Saved codename %s value %s', name, value) db_logger.save_point_now(name, value) loggers[name].clear_trigged() except KeyboardInterrupt: log.info('Stopping everything and waiting 5 s') socket.stop() live_socket.stop() db_logger.stop() time.sleep(5) log.info('Everything stopped, bye!') except Exception: # Unexpected exception, log it log.exception('Unexpected exception during main loop') raise
# pylint: disable=C0103 """This file logs data from the chiller at the UHV Sputterchamber""" from __future__ import print_function import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 import credentials python2_and_3(__file__) LOG = get_logger('chiller_logger_uhv_sputterchamber') def main(): """Main function""" chiller_port = '/dev/serial/by-id/' chiller_port += 'usb-1a86_USB2.0-Ser_-if00-port0' LOG.info('Using chiller port %s', chiller_port) reader = ChillerReader(chiller_port) reader.start() LOG.info('ChillerReader started') codenames = ['uhv_sputterchamber_chiller_temperature', 'uhv_sputterchamber_chiller_flow', 'uhv_sputterchamber_chiller_temperature_ambient', 'uhv_sputterchamber_chiller_pressure', 'uhv_sputterchamber_chiller_temperature_setpoint']
"""This file logs data from the chiller at the thetaprobe""" from __future__ import print_function import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger import credentials LOG = get_logger('chiller_logger_omicron') def main(): """Main function""" chiller_port = '/dev/serial/by-id/' chiller_port += 'usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0' LOG.info('Using chiller port %s', chiller_port) reader = ChillerReader(chiller_port) reader.start() LOG.info('ChillerReader started') codenames = [ 'omicron_chiller_temperature', 'omicron_chiller_flow', 'omicron_chiller_temperature_ambient', 'omicron_chiller_pressure', 'omicron_chiller_temperature_setpoint' ] LOG.debug('Using codenames %s', codenames) loggers = {}
# pylint: disable=C0103 """This file logs data from the chiller at the thetaprobe""" from __future__ import print_function import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 import credentials python2_and_3(__file__) LOG = get_logger('chiller_logger_xrd') def main(): """Main function""" chiller_port = '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0' LOG.info('Using chiller port %s', chiller_port) new_chiller_port = '/dev/serial/by-id/' new_chiller_port += 'usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0' LOG.info('Using chiller port %s', new_chiller_port) #Names without new-prefix refers to the old xrd, names including new #refers to the new xrd reader = ChillerReader(chiller_port) reader.start()
""" Emission control for TOF """ import time import threading import PyExpLabSys.drivers.cpx400dp as CPX import PyExpLabSys.auxiliary.pid as pid from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.drivers.keithley_smu as smu import emission_tui import credentials LOGGER = get_logger('Emission', level='info', file_log=True, file_name='emission_log.txt', terminal_log=False) LOGGER.error('Start') class EmissionControl(threading.Thread): """ Control the emission of a filament. """ def __init__(self): threading.Thread.__init__(self) channels = ['setpoint', 'emission', 'ionenergy'] self.datasocket = DateDataPullSocket('emission_tof', channels, timeouts=[99999999, 1.0, 99999999]) self.datasocket.start() self.pushsocket = DataPushSocket('tof-emission-push_control', action='enqueue') self.pushsocket.start() self.livesocket = LiveSocket('tof-emission', channels) self.livesocket.start()
except ImportError: import socketserver as SocketServer from queue import Queue from collections import Counter, defaultdict # Used for logging output from twisted, see commented out lines below #from twisted.python import log from twisted.internet import reactor, ssl from autobahn.twisted.websocket import (WebSocketServerFactory, WebSocketServerProtocol, listenWS) from PyExpLabSys.common import utilities utilities.WARNING_EMAIL = '*****@*****.**' utilities.ERROR_EMAIL = '*****@*****.**' LOG = utilities.get_logger('ws-server2', level='info', file_log=True, file_max_bytes=10485760) # Used only to count open connections WEBSOCKET_IDS = set() # Dictionary to keep track of subscriptions, keys are host:codename values is a set of # websocket connections SUBSCRIPTIONS = defaultdict(set) # Used to keep track of last values, these will be sent upon subscription. Keys are hostname:codename LAST = {} # Data queue: (time_received, data_items, data_len) DATA_QUEUE = Queue()
""" Temperature controller """ import time import threading import socket import curses import PyExpLabSys.auxiliary.pid as PID import PyExpLabSys.drivers.cpx400dp as cpx import PyExpLabSys.drivers.isotech_ips as ips from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.common.utilities PyExpLabSys.common.utilities.ERROR_EMAIL = '*****@*****.**' LOGGER = get_logger('VHP Temperature control', level='INFO', file_log=True, file_name='temp_control.log', terminal_log=False) class CursesTui(threading.Thread): """ Text user interface for furnace heating control """ def __init__(self, heating_class, heater): threading.Thread.__init__(self) self.start_time = time.time() self.quit = False self.hc = heating_class self.heager = heater self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(False) self.screen.keypad(1) self.screen.nodelay(1)
from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.utilities import activate_library_logging from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.microreactor_temperature_control import HeaterClass from PyExpLabSys.common.microreactor_temperature_control import CursesTui import PyExpLabSys.common.utilities from PyExpLabSys.common.supported_versions import python2_and_3 PyExpLabSys.common.utilities.ERROR_EMAIL = '*****@*****.**' python2_and_3(__file__) try: MICRO = chr(0x03BC) # Python 2 except ValueError: MICRO = unichr(0x03BC) # Python 2 LOGGER = get_logger(MICRO + '-reactor Temperature control', level='WARN', file_log=True, file_name='temp_control.log', terminal_log=False, email_on_warnings=False) activate_library_logging('PyExpLabSys.common.microreactor_temperature_control', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.auxiliary.pid', logger_to_inherit_from=LOGGER) LOGGER.warn('Program started') class RtdReader(threading.Thread): """ Read resistance of RTD and calculate temperature """ def __init__(self, calib_temp): visa_string = 'usb0::2391::1543::MY47002726::INSTR' self.rtd_reader = dmm.Agilent34410ADriver(interface='usbtmc', connection_string=visa_string) self.rtd_reader.select_measurement_function('FRESISTANCE') self.calib_temp = calib_temp
# pylint: disable=C0103 """This file logs data from the chiller at the GC MS""" from __future__ import print_function import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 import credentials python2_and_3(__file__) LOG = get_logger('chiller_logger_gc_ms') def main(): """Main function""" chiller_port = '/dev/serial/by-id/' chiller_port += 'usb-1a86_USB2.0-Ser_-if00-port0' LOG.info('Using chiller port %s', chiller_port) reader = ChillerReader(chiller_port) reader.start() LOG.info('ChillerReader started') codenames = ['gc_ms_chiller_temperature', 'gc_ms_chiller_flow', 'gc_ms_chiller_temperature_ambient', 'gc_ms_chiller_pressure', 'gc_ms_chiller_temperature_setpoint']
# -*- coding: utf-8 -*- """This script read the sample temperature from an Omega CNi3244_C24 temperature control unit and makes it available on a data socket. Furthermore, it also log significant temperature points to the database. """ import time from PyExpLabSys.drivers.omega import CNi3244_C24 from PyExpLabSys.common.sockets import DateDataSocket from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.utilities import get_logger LOGGER = get_logger('temperatue', level='INFO', file_log=True, file_name='temperature_log') TEMPERATURE_CHANGE_THRESHOLD = 0.3 TIMEOUT = 600 SHORT_NAME = 'tts' NAME = 'tower_temperature_sample' def main_measure_loop(cni, socket, db_logger): """The main measuring loop""" last_temp = -100000 last_time = 0 while True: # Current values now = time.time() current = cni.read_temperature() # The read_tempearture returns None if no thermocouple is connected
LOCK_FILE = path.join(THIS_DIR, 'SERVER_LOCK') if path.isfile(LOCK_FILE): MESSAGE = ('Server already running\n' '\n' 'The server lock file "SERVER_LOCK" is in place, which indicates that ' 'the server is already running.\n' '\n' 'If you know that it is not true, delete the lock file.') raise RuntimeError(MESSAGE) # Lock to prevent multiple servers with open(LOCK_FILE, 'w') as file_: pass LOG = get_logger('H2O2 CPX Serv', level='debug', file_log=True, file_name='server.log', file_backup_count=1, file_max_bytes=1048576) STOP_SERVER = False class CPXServer(object): """Server for CPX400DP power supplies""" def __init__(self, devices=None): """Initialize CPXServer Args: devices (dict): Mapping of power supply names (letters) to hostnames. E.g: {'A': '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_C2F95400-if00', 'B': '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_12345600-if00'} """ if not devices:
import credentials # Wait time in seconds between serial communications WAIT = 0.25 # codename : (address, key) CODENAME_TRANSLATION = { 'omicron_ana_pressure': (2, 'ion_gauge_1_pressure'), 'omicron_prep_pressure': (1, 'ion_gauge_1_pressure'), 'omicron_roughing_2_prep': (1, 'slot_a_value_1'), 'omicron_roughing_1_ana': (2, 'slot_a_value_1'), 'omicron_roughing_3_diff': (2, 'slot_b_value_1'), } EXTRA_LIVE = {} LOG = get_logger('pvci_monitor', level='info') def print_values(values): """Print values (type: dict) in a nice fashion to terminal window""" print('-' * 20) for codename, value in values.items(): print(codename + ': {} mbar'.format(value)) def run(pvci, live_socket, pullsocket, database_saver, criterium_checker): """Measure and log """ values = {} for codename in CODENAME_TRANSLATION.keys(): values[codename] = 0
# Wait time in seconds between serial communications WAIT = 0.25 # codename : (address, key) CODENAME_TRANSLATION = { 'omicron_ana_pressure': (2, 'ion_gauge_1_pressure'), 'omicron_prep_pressure': (1, 'ion_gauge_1_pressure'), 'omicron_roughing_2_prep': (1, 'slot_a_value_1'), 'omicron_roughing_1_ana': (2, 'slot_a_value_1'), 'omicron_roughing_3_diff': (2, 'slot_b_value_1'), } EXTRA_LIVE = { } LOG = get_logger('pvci_monitor', level='warning') class ValuePrinter(threading.Thread): """Print values nicely in terminal""" def __init__(self, logger): """Initialize""" threading.Thread.__init__(self) self.logger = logger self.values = dict(self.logger.values) self.printing = True self.screen = curses.initscr() self.win = curses.newwin(10, 50, 0, 0) curses.cbreak() curses.noecho()
""" App to log output from Pfeiffer Turbo Pumps """ # -*- coding: utf-8 -*- import time import sys from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import LiveSocket import PyExpLabSys.drivers.pfeiffer_turbo_pump as tp from PyExpLabSys.common.utilities import get_logger sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=F0401 LOGGER = get_logger('Turbo Pump', level='info', file_log=True, file_name='turbo_log.txt', terminal_log=False) def main(): """ Main loop """ mainpump = tp.TurboDriver(adress=1, port=settings.port) mainpump.start() tui = tp.CursesTui(mainpump) tui.daemon = True tui.start() reader = tp.TurboReader(mainpump) reader.daemon = True
try: import Queue as queue except ImportError: import queue import json import MySQLdb from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 python2_and_3(__file__) LOGGER = get_logger('Host Checker', level='debug', file_log=True, file_name='host_checker.log', terminal_log=True, email_on_warnings=False, email_on_errors=False, file_max_bytes=104857, file_backup_count=5) def host_status(hostname, port): """ Report if a host i available on the network """ host_is_up = True if port != '3389': try: subprocess.check_output(["ping", "-c1", "-W1", hostname]) except subprocess.CalledProcessError: host_is_up = False
def main(): """Main function""" # Parse arguments parser = argparse.ArgumentParser( description=('Runs a stepped power supply program on ' 'a specified power supply and channel')) parser.add_argument('power_supply', choices=('A', 'B', 'C'), help='The capital lette of a power supply e.g. A') parser.add_argument( 'output', choices=('1', '2'), help='The output number on that power supply. Must be 1 or 2') parser.add_argument('program_file', help="The file that contains the ramp") args = parser.parse_args() global LOG LOG = get_logger( 'STACK TESTER ' + args.power_supply + args.output, level='debug', file_log=True, terminal_log=True, file_name='stack_tester_' + args.power_supply + args.output + '.log', email_on_warnings=False, email_on_errors=False, ) global LOCK_FILE psu_name = '{}{}'.format(args.power_supply, args.output) LOCK_FILE = path.join(THIS_DIR, 'LOCK{}'.format(psu_name)) print(LOCK_FILE) if path.isfile(LOCK_FILE): message = ('Stacktester {0} already running\n' '\n' 'The lock file "LOCK{0}" is in place, which indicates ' 'that this stack tester is already running.\n' '\n' 'If you know that it is not true, delete the lock file.') LOCK_FILE = None raise RuntimeError(message.format(psu_name)) # Lock to prevent multiple clients on same channel with open(LOCK_FILE, 'w') as file__: # pylint: disable=unused-variable pass # Check if the server is up if _send_command("1", args.power_supply, 'PING') == 'PONG': LOG.debug('Got PONG from server') SOCK.settimeout(None) # Init program my_program = VoltageCurrentProgram(args) my_program.start() # Appearently, it is better to defined app at the module level for # clean up: http://stackoverflow.com/questions/27131294/ # error-qobjectstarttimer-qtimer-can-only-be-used-with-threads-started-with-qt global APP # pylint: disable=global-variable-undefined APP = QApplication(sys.argv) SteppedProgramRunner(my_program) print('BEFORE app exec') sys.exit(APP.exec_()) print('AFTER app exec')
import socket import curses import pickle import PyExpLabSys.auxiliary.pid as PID import PyExpLabSys.drivers.cpx400dp as cpx import PyExpLabSys.drivers.agilent_34410A as dmm import PyExpLabSys.auxiliary.rtd_calculator as rtd_calculator from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.common.utilities from PyExpLabSys.common.supported_versions import python2_and_3 PyExpLabSys.common.utilities.ERROR_EMAIL = '*****@*****.**' python2_and_3(__file__) LOGGER = get_logger('Microreactor Temperature control', level='ERROR', file_log=True, file_name='temp_control.log', terminal_log=False, email_on_warnings=False) class CursesTui(threading.Thread): """ Text user interface for furnace heating control """ def __init__(self, heating_class): threading.Thread.__init__(self) self.start_time = time.time() self.quit = False self.heater = heating_class self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(False) self.screen.keypad(1) self.screen.nodelay(1)
import PyExpLabSys.drivers.agilent_34410A as a34410A from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 import emission_tui import credentials python2_and_3(__file__) LOGGER = get_logger('Emission', level='warn', file_log=True, file_name='emission_log.txt', terminal_log=False, email_on_errors=True, email_on_warnings=True) LOGGER.info('Start') class EmissionControl(threading.Thread): """ Control the emission of a filament. """ def __init__(self): threading.Thread.__init__(self) channels = ['setpoint', 'emission', 'ionenergy'] self.datasocket = DateDataPullSocket( 'emission_tof', channels, timeouts=[99999999, 1.0, 99999999]) self.datasocket.start()
from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.utilities import activate_library_logging from PyExpLabSys.common.supported_versions import python2_and_3 BASEPATH = os.path.abspath( __file__)[:os.path.abspath(__file__).find('PyExpLabSys')] sys.path.append(BASEPATH + '/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=wrong-import-position python2_and_3(__file__) LOGGER = get_logger('Mass Spec', level='warning', file_log=True, file_name='qms.txt', terminal_log=False, email_on_warnings=False, email_on_errors=False, file_max_bytes=104857600, file_backup_count=5) activate_library_logging('PyExpLabSys.drivers.pfeiffer_qmg422', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.apps.qms.qmg_status_output', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.apps.qms.qmg_meta_channels', logger_to_inherit_from=LOGGER) activate_library_logging('PyExpLabSys.apps.qms.qms', logger_to_inherit_from=LOGGER) try:
# pylint: disable=E1101 """ Module to run a graphical logbook of a specific area """ import cv import time import MySQLdb from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.drivers.vivo_technologies import ThreadedBarcodeReader, detect_barcode_device from PyExpLabSys.drivers.four_d_systems import PicasouLCD28PTU import sys sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=F0401 LOGGER = get_logger('Picture_Logbook') class PictureLogbook(object): """ Handle login and logout of users """ def __init__(self): LOGGER.info('Started Picture Logbook') self.picaso = PicasouLCD28PTU(serial_device='/dev/ttyUSB0', baudrate=115200, debug=True) dev_ = detect_barcode_device() LOGGER.info('Barcode device: ' + dev_) self.tbs = ThreadedBarcodeReader(dev_) self.tbs.start() self.setup = settings.setup self.livesocket = LiveSocket(self.setup + '-Picture Logbook', ['logged_in_user'])
# pylint: disable=C0103 """This file logs data from the chiller at the thetaprobe""" import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.supported_versions import python2_and_3 import credentials python2_and_3(__file__) LOG = get_logger('chiller_logger_thetaprobe') def main(): """Main function""" chiller_port = '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0' LOG.info('Using chiller port %s', chiller_port) reader = ChillerReader(chiller_port) reader.start() LOG.info('ChillerReader started') codenames = [ 'thetaprobe_chiller_temperature', 'thetaprobe_chiller_flow', 'thetaprobe_chiller_temperature_ambient', 'thetaprobe_chiller_pressure', 'thetaprobe_chiller_temperature_setpoint' ] LOG.debug('Using codenames %s', codenames)
""" Data logger for the PVD309 effusion cells """ import threading import time from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.drivers.omega_cni as omega_cni import PyExpLabSys.drivers.omega_cn7800 as omega_cn7800 import credentials LOGGER = get_logger('PVD309', level='info', file_log=True, file_name='pvd309_effusion_log.txt', terminal_log=False) class TemperatureReader(threading.Thread): """ Communicates with the Omega Controllers """ def __init__(self): cn7800_port = '/dev/serial/by-id/usb-FTDI_USB-RS485_Cable_FTY0VXC8-if00-port0' self.cn7800 = omega_cn7800.CN7800(cn7800_port) self.temp_mai = self.cn7800.read_temperature() cni_port = '/dev/serial/by-id/usb-FTDI_USB-RS485_Cable_FTY0EQZZ-if00-port0' self.cni = omega_cni.ISeries(cni_port, 9600, comm_stnd='rs485') self.temp_dca = self.cni.read_temperature(1) threading.Thread.__init__(self) self.quit = False self.ttl = 10 def value(self, channel): """ Return current value of reader """ self.ttl = self.ttl - 1
from PyExpLabSys.drivers.epimax import PVCi import credentials CODENAME_TRANSLATION = { 'thetaprobe_main_chamber_pressure': 'ion_gauge_1_pressure', 'thetaprobe_load_lock_roughing_pressure': 'slot_a_value_1', 'thetaprobe_main_chamber_temperature': 'slot_b_value_1', } EXTRA_LIVE = { 'thetaprobe_bakeout_setpoint': ('bake_out_setpoint', ), 'thetaprobe_bakeout_remaining': ('remaining_bake_out_time', ), 'thetaprobe_ion_gauge_settings': ('ion_gauge_1_status', 'ion_gauge_emission_setting'), } LOG = get_logger('pvci_monitor', level='debug') def run(pvci, live_socket, database_saver, criterium_checker): """Measure and log""" # For last values cache last values and save send time extra_live_value_cache = { key: { 'time': 0.0, 'value': None } for key in EXTRA_LIVE } last_extra = 0.0 while True: values = pvci.get_fields('common')
MESSAGE = ( "Server already running\n" "\n" 'The server lock file "SERVER_LOCK" is in place, which indicates that ' "the server is already running.\n" "\n" "If you know that it is not true, delete the lock file." ) raise RuntimeError(MESSAGE) # Lock to prevent multiple servers with open(LOCK_FILE, "w") as file_: pass LOG = get_logger( "H2O2 CPX Serv", level="debug", file_log=True, file_name="server.log", file_backup_count=1, file_max_bytes=1048576 ) STOP_SERVER = False class CPXServer(object): """Server for CPX400DP power supplies""" def __init__(self, devices=None): """Initialize CPXServer Args: devices (dict): Mapping of power supply names (letters) to hostnames. E.g: {'A': '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_C2F95400-if00', 'B': '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_12345600-if00'} """
import Queue import PyExpLabSys.common.database_saver as database_saver import PyExpLabSys.drivers.pfeiffer_qmg420 as qmg420 import PyExpLabSys.drivers.pfeiffer_qmg422 as qmg422 import PyExpLabSys.apps.qms.qms as ms import PyExpLabSys.apps.qms.qmg_status_output as qmg_status_output import PyExpLabSys.apps.qms.qmg_meta_channels as qmg_meta_channels from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.utilities import get_logger BASEPATH = os.path.abspath(__file__)[:os.path.abspath(__file__).find('PyExpLabSys')] sys.path.append(BASEPATH + '/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=F0401 LOGGER = get_logger('Mass Spec', level='info', file_log=True, file_name='qms.txt', terminal_log=False) class MassSpec(object): """ User interface to mass spec code """ def __init__(self): sql_queue = Queue.Queue() self.data_saver = database_saver.SqlSaver(settings.username, settings.username, sql_queue) self.data_saver.start() if settings.qmg == '420': self.qmg = qmg420.qmg_420(settings.port) if settings.qmg == '422': print settings.port self.qmg = qmg422.qmg_422(port=settings.port, speed=settings.speed) livesocket = LiveSocket(settings.name + '-mass-spec', ['qms-value'])
import threading import time from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.value_logger import ValueLogger import PyExpLabSys.drivers.honeywell_6000 as honeywell_6000 import PyExpLabSys.common.utilities from PyExpLabSys.common.supported_versions import python2_and_3 import credentials PyExpLabSys.common.utilities.ERROR_EMAIL = '*****@*****.**' python2_and_3(__file__) LOGGER = get_logger('GC MS temperature logger', level='WARN', file_log=True, file_name='temp_control.log', terminal_log=False, email_on_warnings=False) LOGGER.warning('Program started') class Reader(threading.Thread): """ Pressure reader """ def __init__(self, honeywell): threading.Thread.__init__(self) self.honeywell = honeywell self.temperature = None self.humidity = None self.quit = False self.ttl = 20
"""This file logs data from the chiller at the thetaprobe""" from __future__ import print_function import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger import credentials LOG = get_logger('chiller_logger_xrd') def main(): """Main function""" chiller_port = '/dev/serial/by-id/' chiller_port += 'usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0' LOG.info('Using chiller port %s', chiller_port) reader = ChillerReader(chiller_port) reader.start() LOG.info('ChillerReader started') codenames = ['ps_chiller_temperature', 'ps_chiller_flow', 'ps_chiller_temperature_ambient', 'ps_chiller_pressure', 'ps_chiller_temperature_setpoint'] LOG.debug('Using codenames %s', codenames) loggers = {} for i in range(0, len(codenames)): loggers[codenames[i]] = ValueLogger(reader, comp_val=0.1, channel=i) loggers[codenames[i]].start()
"""Continuous logger for the Pfeiffer gauges on the theta probe""" import time from PyExpLabSys.drivers.pfeiffer import TPG262 from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import LiveSocket import credentials LOGGER = get_logger('thetaprobe_pressure_logger') def main(): """The main method for the pressure logger""" # Open communication to the pressure measurement unit tpg = TPG262(port='/dev/ttyUSB0', baudrate=9600) LOGGER.info('Initiated driver to TPG 262') # Get a continuous logger codenames = ['thetaprobe_pressure_loadlock'] db_logger = ContinuousLogger(table='dateplots_thetaprobe', username=credentials.USERNAME, password=credentials.PASSWORD, measurement_codenames=codenames) db_logger.start() LOGGER.info('Initiated and started database logger') name = 'Thetaprobe pressure load lock and UV gun' livesocket = LiveSocket(name, codenames, 0.2)
# -*- coding: utf-8 -*- """This script read the sample temperature from an Omega CNi3244_C24 temperature control unit and makes it available on a data socket. Furthermore, it also log significant temperature points to the database. """ import time from PyExpLabSys.drivers.omega import CNi3244_C24 from PyExpLabSys.common.sockets import DateDataPullSocket #from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.utilities import get_logger LOGGER = get_logger('temperatue', level='INFO', file_log=True, file_name='temperature_log') TEMPERATURE_CHANGE_THRESHOLD = 0.3 TIMEOUT = 600 SHORT_NAME = 'tts' NAME = 'tower_temperature_sample' FULL_NAME = 'Tower temperature of sample' def main_measure_loop(cni, socket, db_logger): """The main measuring loop""" last_temp = -100000 last_time = 0 while True: # Current values now = time.time() current = cni.read_temperature()
import time import threading import socket import curses import PyExpLabSys.auxiliary.pid as PID import PyExpLabSys.drivers.cpx400dp as cpx import PyExpLabSys.drivers.isotech_ips as ips from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.common.utilities PyExpLabSys.common.utilities.ERROR_EMAIL = '*****@*****.**' LOGGER = get_logger('VHP Temperature control', level='INFO', file_log=True, file_name='temp_control.log', terminal_log=False) class CursesTui(threading.Thread): """ Text user interface for furnace heating control """ def __init__(self, heating_class, heater): threading.Thread.__init__(self) self.start_time = time.time() self.quit = False self.hc = heating_class self.heager = heater self.screen = curses.initscr() curses.noecho() curses.cbreak()
# pylint: disable=R0913,W0142,C0103 #import SocketServer """ Temperature controller """ import time import threading import socket import curses import pickle import PyExpLabSys.auxiliary.pid as PID import PyExpLabSys.drivers.cpx400dp as cpx import PyExpLabSys.drivers.agilent_34410A as dmm import PyExpLabSys.auxiliary.rtd_calculator as rtd_calculator from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.utilities import get_logger LOG = get_logger('mytemp', file_log=True) class CursesTui(threading.Thread): """ Text user interface for furnace heating control """ def __init__(self, heating_class): threading.Thread.__init__(self) self.start_time = time.time() self.quit = False self.hc = heating_class self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(False) self.screen.keypad(1) self.screen.nodelay(1)
* 254 is the system status """ import time import json import sys import credentials from PyExpLabSys.drivers.crowcon import Vortex #from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver #from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger LOGGER = get_logger('b312gasalarm', level='debug') import MySQLdb # Python 3 check if sys.version_info.major < 3: raise RuntimeError('Run with Python 3') # Gas alarm configuration to codename translation CONF_TO_NAME = { '1 Pumperum %LEL': 'B312_gasalarm_H2_pumproom', '2 Hall %LEL': 'B312_gasalarm_H2_hall_west', '3 Hall %LEL': 'B312_gasalarm_H2_hall_east', '4 LAB %LEL': 'B312_gasalarm_H2_chemlab', '5 Pumperum PPM': 'B312_gasalarm_CO_pumproom', '6 Hall PPM': 'B312_gasalarm_CO_hall_west', '7 Hall PPM': 'B312_gasalarm_CO_hall_east',
"""This file implements the central websockets server for servcinf""" import time import threading import socket import json import xml.etree.ElementTree as XML # Used for logging output from twisted, see commented out lines below #from twisted.python import log from twisted.internet import reactor, ssl from autobahn.websocket import WebSocketServerFactory, \ WebSocketServerProtocol, listenWS from PyExpLabSys.common.utilities import get_logger LOG = get_logger('ws-server', level='info') MALFORMED_SUBSCRIPTION = 'Error: Malformed subscription line: {}' DATA = {} TIME_REPORT_ALIVE = 60 # Seconds between the thread reporting in WEBSOCKET_IDS = set() # Used only to count open connections class CinfWebSocketHandler(WebSocketServerProtocol): # pylint: disable=W0232 """Class that handles a websocket connection""" def onOpen(self): """Log when the connection is opened""" WEBSOCKET_IDS.add(id(self)) LOG.info('wshandler: Connection opened, count: {}'. format(len(WEBSOCKET_IDS)))
* 255 is the system power status * 254 is the system status """ import time import json import sys import credentials from PyExpLabSys.drivers.crowcon import Vortex #from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver #from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger LOGGER = get_logger('b312gasalarm', level='debug') import MySQLdb # Python 3 check if sys.version_info.major < 3: raise RuntimeError('Run with Python 3') # Gas alarm configuration to codename translation CONF_TO_NAME = { '1 Pumperum %LEL': 'B312_gasalarm_H2_pumproom', '2 Hall %LEL': 'B312_gasalarm_H2_hall_west', '3 Hall %LEL': 'B312_gasalarm_H2_hall_east', '4 LAB %LEL': 'B312_gasalarm_H2_chemlab', '5 Pumperum PPM': 'B312_gasalarm_CO_pumproom', '6 Hall PPM': 'B312_gasalarm_CO_hall_west', '7 Hall PPM': 'B312_gasalarm_CO_hall_east',
"""Continuous logger for the Pfeiffer gauges on the theta probe""" import time from PyExpLabSys.drivers.pfeiffer import TPG262 from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import LiveSocket import credentials LOGGER = get_logger('thetaprobe_pressure_logger') def main(): """The main method for the pressure logger""" # Open communication to the pressure measurement unit tpg = TPG262(port='/dev/ttyUSB0', baudrate=9600) LOGGER.info('Initiated driver to TPG 262') # Get a continuous logger codenames = ['thetaprobe_pressure_loadlock'] db_logger = ContinuousLogger(table='dateplots_thetaprobe', username=credentials.USERNAME, password=credentials.PASSWORD, measurement_codenames=codenames) db_logger.start() LOGGER.info('Initiated and started database logger') name = 'Thetaprobe pressure load lock and UV gun' livesocket = LiveSocket(name, codenames, 0.2) livesocket.start()
"""This file is responsible for measuring temeprature related to the coupled reactor setup """ import time from PyExpLabSys.common.sockets import DateDataPullSocket import PyExpLabSys.drivers.omega_D6400 as D6400 from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import DateDataPullSocket LOGGER = get_logger('coupled_reactor_temp') class TemperatureLogger(object): def __init__(self): # Initialize omega driver LOGGER.info('Initialize omega d6400 driver') d6400_id = '/dev/serial/by-id/usb-FTDI_USB-RS485_Cable_FTWGRP0B-if00'\ '-port0' self.d6400 = D6400.OmegaD6400(1, d6400_id) for channel in range(1, 8): LOGGER.info('Set range for channel {}'.format(channel)) self.d6400.update_range_and_function(channel, action='tc', fullrange='K') # Initialize socket name = 'Coupled reactor temperatures' self.codenames = { 1: 'R1_temp', 2: 'R1_sample_temp',
import threading import PyExpLabSys.drivers.cpx400dp as CPX import PyExpLabSys.auxiliary.pid as pid from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.database_saver import ContinuousDataSaver from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.utilities import get_logger import PyExpLabSys.drivers.keithley_smu as smu import emission_tui import credentials LOGGER = get_logger('Emission', level='info', file_log=True, file_name='emission_log.txt', terminal_log=False) LOGGER.error('Start') class EmissionControl(threading.Thread): """ Control the emission of a filament. """ def __init__(self): threading.Thread.__init__(self) channels = ['setpoint', 'emission', 'ionenergy'] self.datasocket = DateDataPullSocket( 'emission_tof', channels, timeouts=[99999999, 1.0, 99999999]) self.datasocket.start() self.pushsocket = DataPushSocket('tof-emission-push_control',
# pylint: disable=C0103 """This file logs data from the chiller at the thetaprobe""" import time import math from PyExpLabSys.common.value_logger import ValueLogger from PyExpLabSys.common.chiller_reader import ChillerReader from PyExpLabSys.common.loggers import ContinuousLogger from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.utilities import get_logger import credentials LOG = get_logger('chiller_logger_thetaprobe') def main(): """Main function""" chiller_port = '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0' LOG.info('Using chiller port %s', chiller_port) reader = ChillerReader(chiller_port) reader.start() LOG.info('ChillerReader started') codenames = ['thetaprobe_chiller_temperature', 'thetaprobe_chiller_flow', 'thetaprobe_chiller_temperature_ambient', 'thetaprobe_chiller_pressure', 'thetaprobe_chiller_temperature_setpoint'] LOG.debug('Using codenames %s', codenames)
""" Module to check that local machine is living up to its duties """ import time from PyExpLabSys.common.utilities import get_logger from PyExpLabSys.common.sockets import DateDataPullSocket import threading import socket import sys sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=F0401 from PyExpLabSys.common.supported_versions import python2_and_3 python2_and_3(__file__) LOGGER = get_logger('Socket Supervisor') class SocketSupervisor(threading.Thread): """ Supervisor will check that a list of ports are still open """ def __init__(self): threading.Thread.__init__(self) self.quit = False self.ports = settings.ports self.setup = settings.setup self.pullsocket = DateDataPullSocket(self.setup + '-socket supervisor', [str(port) for port in self.ports], timeouts=len(self.ports)*[5]) self.pullsocket.start() def run(self): """ Main loop """ while not self.quit: for port in self.ports: time.sleep(1) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
""" App to control PW-modulated bakeout boxes """ # -*- coding: utf-8 -*- import time import sys import threading import curses import wiringpi2 as wp # pylint: disable=F0401 from PyExpLabSys.common.sockets import LiveSocket from PyExpLabSys.common.sockets import DataPushSocket from PyExpLabSys.common.sockets import DateDataPullSocket from PyExpLabSys.common.utilities import get_logger sys.path.append('/home/pi/PyExpLabSys/machines/' + sys.argv[1]) import settings # pylint: disable=F0401 LOGGER = get_logger('Bakeout', level='info', file_log=True, file_name='bakeout_log.txt', terminal_log=False) class CursesTui(threading.Thread): """ Text UI for bakeout program """ def __init__(self, baker_instance): threading.Thread.__init__(self) self.baker = baker_instance self.watchdog = baker_instance.watchdog self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(False) self.screen.keypad(1) self.screen.nodelay(1) def run(self):