当前位置: 首页>>代码示例>>Python>>正文


Python LiveSocket.stop方法代码示例

本文整理汇总了Python中PyExpLabSys.common.sockets.LiveSocket.stop方法的典型用法代码示例。如果您正苦于以下问题:Python LiveSocket.stop方法的具体用法?Python LiveSocket.stop怎么用?Python LiveSocket.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyExpLabSys.common.sockets.LiveSocket的用法示例。


在下文中一共展示了LiveSocket.stop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_live_multiple_variables

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
def test_live_multiple_variables(sock):
    codenames = ['name1', 'name2']
    live_socket = LiveSocket(NAME, codenames, 1.0)
    live_socket.start()

    port = 8000

    # Test the 'codenames' command
    data = send_and_resc(sock, 'codenames', port)
    expected = ['name1', 'name2']
    assert(json.loads(data) == expected)

    # Test the 'sane_interval' command
    data = send_and_resc(sock, 'sane_interval', port)
    assert(json.loads(data) - 1.0 < 1E-8)

    for n in range(3):
        now = time.time()
        live_socket.set_point('name1', (now, n))
        live_socket.set_point('name2', (now, n+1))

        # Test the 'data' command
        data = send_and_resc(sock, 'data', port)
        expected = [[now, n], [now, n+1]]
        assert(json.loads(data) == expected)

        time.sleep(0.1)

    live_socket.stop()
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:31,代码来源:test_live_socket.py

示例2: main

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
def main():
    """Main function"""
    pvci = PVCi('/dev/serial/by-id/'
                'usb-FTDI_USB-RS485_Cable_FTY3M2GN-if00-port0')

    # Start live socket
    live_socket = LiveSocket('thetaprobe_pvci', list(CODENAME_TRANSLATION.keys()),
                             sane_interval=0.5)
    live_socket.start()

    # Start database saver
    database_saver = ContinuousDataSaver(
        'dateplots_thetaprobe', credentials.USERNAME,
        credentials.PASSWORD, list(CODENAME_TRANSLATION.keys())
    )
    database_saver.start()

    # Set up criterium checker
    criterium_checker = LoggingCriteriumChecker(
        codenames=list(CODENAME_TRANSLATION.keys()),
        types=['log', 'log', 'lin'],
        criteria=[0.1, 0.1, 1.0],
    )


    try:
        run(pvci, live_socket, database_saver, criterium_checker)
    except KeyboardInterrupt:
        pvci.close()
        live_socket.stop()
        database_saver.stop()
开发者ID:jlopezBolt,项目名称:PyExpLabSys,代码行数:33,代码来源:pvci_monitor.py

示例3: test_live_wrong_codename

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
def test_live_wrong_codename():
    codenames = ['name1', 'name2']
    live_socket = LiveSocket(NAME, codenames, 1.0)
    live_socket.start()

    # Test that trying to set an unknown name raises an exception
    with pytest.raises(ValueError):
        live_socket.set_point('bad name', (1, 2))

    live_socket.stop()
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:12,代码来源:test_live_socket.py

示例4: main

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
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()

    loadlock_last = {'value': 1E20, 'time': 0}
    uvgun_last = {'value': 1E20, 'time': 0}

    try:
        while True:
            # get the values: returns:
            # (value1, (status_code1, status_message1),
            # value2, (status_code2, status_message2))
            value_ll, code_ll, value_uv, code_uv = tpg.pressure_gauges()
            livesocket.set_point_now('thetaprobe_pressure_loadlock', value_ll)
            livesocket.set_point_now('thetaprobe_pressure_uvgun', value_uv)

            ### Load lock
            if code_ll[0] in [0, 1]:  # If measurement is OK or underranged
                if logging_criteria(value_ll, loadlock_last):
                    LOGGER.info('Add value {} for load lock'.format(value_ll))
                    now_ll = db_logger.enqueue_point_now(
                        'thetaprobe_pressure_loadlock',
                        value_ll)
                    loadlock_last['value'] = value_ll
                    loadlock_last['time'] = now_ll

            ### UV gun
            if code_uv[0] in [0, 1]:  # If measurement is OK or underranged
                if logging_criteria(value_uv, uvgun_last):
                    LOGGER.info('Add value {} for UV gun'.format(value_uv))
                    now_uv = db_logger.enqueue_point_now(
                        'thetaprobe_pressure_uvgun',
                        value_uv)
                    uvgun_last['value'] = value_uv
                    uvgun_last['time'] = now_uv
    except KeyboardInterrupt:
        LOGGER.info('Keyboard interrupt. Shutting down')
        db_logger.stop()
        livesocket.stop()
        LOGGER.info('Database logger stoppped. Exiting!')
开发者ID:JNRiedel,项目名称:PyExpLabSys,代码行数:57,代码来源:monitor.py

示例5: main

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
def main():
    """ Main method for the websocket server """
    LOG.info('main: Start')
    global LIVESOCKET  # pylint: disable=global-statement
    names = ['wss_hosts_defined', 'wss_hosts', 'wss_clients']
    LIVESOCKET = LiveSocket('websocketserver', names, sane_interval=1.0)
    LIVESOCKET.start()

    udp_steward = UDPConnectionSteward()
    udp_steward.start()

    # Uncomment these two to get log from twisted
    #import sys
    #log.startLogging(sys.stdout)
    # Create context factor with key and certificate
    context_factory = ssl.DefaultOpenSSLContextFactory(
        '/home/kenni/certs/fysik.dtu.dk.key',
        '/home/kenni/certs/fysik.dtu.dk.crt'
    )
    # Form the webserver factory
    factory = WebSocketServerFactory("wss://localhost:9001", debug=True)
    # Set the handler
    factory.protocol = CinfWebSocketHandler
    # Listen for incoming WebSocket connections: wss://localhost:9001
    listenWS(factory, context_factory)

    try:
        reactor.run()  # pylint: disable=E1101
        time.sleep(1)
        LOG.info('main: Keyboard interrupt, websocket reactor stopped')
        udp_steward.stop()
        time.sleep(1)
        LOG.info('main: UPD Steward stopped')
        LIVESOCKET.stop()
        time.sleep(1)
        LOG.info('main: Own livesocket stoppped')
    except Exception as exception_:
        LOG.exception(exception_)
        raise exception_

    LOG.info('main: Ended')
    raw_input('All stopped. Press enter to exit')
开发者ID:neilanderson,项目名称:PyExpLabSys,代码行数:44,代码来源:websocket_server.py

示例6: test_live_init

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
def test_live_init():
    codenames = ['name1', 'name2']
    live_socket = LiveSocket(NAME, codenames, 1.0)
    live_socket.start()

    # Check that the port default is 8000
    assert(live_socket.port == 8000)

    data = PyExpLabSys.common.sockets.DATA
    # Check that data and last served are initialized and not with the same
    # objects
    for codename in codenames:
        assert(data[8000]['data'][codename] ==
               data[8000]['last_served'][codename])
        assert(not (data[8000]['data'][codename] is
               data[8000]['last_served'][codename]))

    # Check tha codenams and sane_interval is set correctly
    assert(data[8000]['codenames'] == codenames)
    assert(data[8000]['sane_interval'] - 1.0 < 1E-8)

    live_socket.stop()
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:24,代码来源:test_live_socket.py

示例7: GasAlarmMonitor

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
class GasAlarmMonitor(object):
    """Class that monitors the gas alarm the building 312"""

    def __init__(self):
        # Start logger
        codenames = list(CONF_TO_NAME.values())
        self.db_saver = ContinuousDataSaver(
            continuous_data_table='dateplots_b312gasalarm',
            username=credentials.USERNAME,
            password=credentials.PASSWORD,
            measurement_codenames=codenames,
        )
        self.db_saver.start()
        LOGGER.info('Logger started')

        # Init live socket
        self.live_socket = LiveSocket(name='gas_alarm_312_live',
                                      codenames=codenames)
        self.live_socket.start()
        LOGGER.info('Live socket started')

        # Start driver
        self.vortex = Vortex('/dev/serial/by-id/usb-FTDI_USB-RS485_Cable_FTWGRKRA-if00-port0', 1)
        LOGGER.info('Vortex driver opened')

        # Init database connection
        self.db_connection = MySQLdb.connect(
            host='servcinf-sql', user=credentials.USERNAME,
            passwd=credentials.PASSWORD, db='cinfdata')
        self.db_cursor = self.db_connection.cursor()

        # Initiate static information. All information about the except for
        # the list of their numbers are placed in dicts because the numbering
        # starts at 1.
        # Detector numbers: [1, 2, 3, ..., 12]
        self.detector_numbers = range(1, self.vortex.get_number_installed_detectors() + 1)
        self.detector_info = {detector_num: self.vortex.detector_configuration(detector_num)
                              for detector_num in self.detector_numbers}
        # trip_levels are the differences that are required to force a log
        # The levels are set to 2 * the communication resolution
        # (1000 values / full range)
        self.trip_levels = {detector_num: info.range * 2.0 / 1000.0 for
                            detector_num, info in self.detector_info.items()}

        # Initiate last measured values and their corresponding times
        self.detector_levels_last_values = \
            {detector_num: - (10 ** 9)
             for detector_num in self.detector_numbers}
        self.detector_levels_last_times = \
            {detector_num: 0 for detector_num in self.detector_numbers}
        self.detector_status_last_values = \
            {detector_num: {'inhibit': False, 'status': ['OK'],
                            'codename': self.detector_info[detector_num].identity}
             for detector_num in self.detector_numbers}
        self.detector_status_last_times = \
            {detector_num: 0 for detector_num in self.detector_numbers}

        # Initiate variables for system power status
        self.central_power_status_last_value = 'OK'
        self.central_power_status_last_time = - (10 ** 9)

        # Initiate variables for system status
        self.central_status_last_value = ['All OK']
        self.central_status_last_time = 0

    def close(self):
        """Close the logger and the connection to the Vortex"""
        self.db_saver.stop()
        LOGGER.info('Logger stopped')
        self.live_socket.stop()
        LOGGER.info('Live socket stopped')
        self.vortex.close()
        LOGGER.info('Vortex driver closed')

    @staticmethod
    def conf_to_codename(conf):
        """Convert the identity the sensor returns to the codename used in the
        database
        """
        conf = '{conf.number} {conf.identity} {conf.unit}'.format(conf=conf)
        return CONF_TO_NAME[conf]

    def main(self):
        """Main monitoring and logging loop"""
        # Each iteration takes about 5 sec
        while True:
            # Log detectors
            for detector_num in self.detector_numbers:
                self.log_detector(detector_num)

            # Log Vortex unit status (force log every 24 hours)
            self.log_central_unit()

    def log_detector(self, detector_num):
        """Get the levels from one detector and log if required"""
        # Get detector info and levels for this detector
        conf = self.detector_info[detector_num]
        codename = self.conf_to_codename(conf)
        LOGGER.debug('Use detector {} \'{}\''.format(detector_num, codename))
        levels = self.vortex.get_detector_levels(detector_num)
#.........这里部分代码省略.........
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:103,代码来源:monitor_H2_CO.py

示例8: main

# 需要导入模块: from PyExpLabSys.common.sockets import LiveSocket [as 别名]
# 或者: from PyExpLabSys.common.sockets.LiveSocket import stop [as 别名]
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
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:64,代码来源:data_logger.py


注:本文中的PyExpLabSys.common.sockets.LiveSocket.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。