예제 #1
0
def setup(request):
    conn_type, *args = request.param

    if conn_type == "spi":
        client = SPIClient()
        sensor = 1
    elif conn_type == "uart":
        port = args[0] or autodetect_serial_port()
        client = UARTClient(port)
        sensor = 1
    elif conn_type == "socket":
        client = SocketClient(args[0])
        sensor = int(args[1])
    else:
        pytest.fail()

    client.connect()
    yield (client, sensor)
    client.disconnect()
예제 #2
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        print("Using detectors is only supported with the XM112 module")
        sys.exit()
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    config = configs.DistancePeakDetectorConfig()
    config.sensor = args.sensors
    config.range_interval = [0.1, 0.7]
    config.sweep_rate = 60
    config.gain = 0.5

    client.setup_session(config)

    pg_updater = PGUpdater(config)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        try:
            pg_process.put_data(data)
        except PGProccessDiedException:
            break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()