def run(self): print("#### New thread for %s" % self.name) args = self._demo_ctrl.streaming_client_args print("args:", args) utils.config_logging(args) if args.socket_addr: client = SocketClient(args.socket_addr) else: port = args.serial_port or utils.autodetect_serial_port() client = UARTClient(port) try: client.connect() except Exception as e: print("Got exception:", e) session_info = client.setup_session(self.config) print("Session info:\n", session_info, "\n") client.start_session() while not self.terminating: sweep_info, sweep_data = client.get_next() d = self.process_data(sweep_data) if d is not None: self._demo_ctrl.put_cmd(str(d)) if self.terminating: break client.disconnect()
def main(): args = utils.ExampleArgumentParser().parse_args() utils.config_logging(args) if args.socket_addr: client = SocketClient(args.socket_addr) elif args.spi: client = SPIClient() else: port = args.serial_port or utils.autodetect_serial_port() client = UARTClient(port) config = configs.EnvelopeServiceConfig() config.sensor = args.sensors print(config) connect_info = client.connect() print("connect info:") print_dict(connect_info) session_info = client.start_session(config) print("session_info:") print_dict(session_info) data_info, data = client.get_next() print("data_info:") print_dict(data_info) client.disconnect()
def main(): # To simplify the examples, we use a generic argument parser. It # lets you choose between UART/SPI/socket, set which sensor(s) to # use, and the verbosity level of the logging. args = utils.ExampleArgumentParser().parse_args() # The client logs using the logging module with a logger named # acconeer.exptool.*. We call another helper function which sets up # the logging according to the verbosity level set in the arguments: # -q or --quiet: ERROR (typically not used) # default: WARNING # -v or --verbose: INFO # -vv or --debug: DEBUG utils.config_logging(args) # Pick client depending on whether socket, SPI, or UART is used if args.socket_addr: client = SocketClient(args.socket_addr) elif args.spi: client = SPIClient() else: port = args.serial_port or utils.autodetect_serial_port() client = UARTClient(port) # Create a configuration to run on the sensor. A good first choice # is the envelope service, so let's pick that one. config = configs.EnvelopeServiceConfig() # In all examples, we let you set the sensor(s) via the command line config.sensor = args.sensors # Set the measurement range [meter] config.range_interval = [0.2, 0.3] # Set the target measurement rate [Hz] config.update_rate = 10 # Other configuration options might be available. Check out the # example for the corresponding service/detector to see more. client.connect() # In most cases, explicitly calling connect is not necessary as # setup_session below will call connect if not already connected. # Set up the session with the config we created. If all goes well, # some information/metadata for the configured session is returned. session_info = client.setup_session(config) print("Session info:\n", session_info, "\n") # Now would be the time to set up plotting, signal processing, etc. # Start the session. This call will block until the sensor has # confirmed that it has started. client.start_session() # Alternatively, start_session can be given the config instead. In # that case, the client will call setup_session(config) for you # before starting the session. For example: # session_info = client.start_session(config) # As this will call setup_session in the background, this will also # connect if not already connected. # In this simple example, we just want to get a couple of sweeps. # To get a sweep, call get_next. get_next will block until the sweep # is recieved. Some information/metadata is returned together with # the data. f = open("demo.txt","a"); for i in range(3): data_info, data = client.get_next() print("Sweep {}:\n".format(i + 1), data_info, "\n", data, "\n") f.write(numpy.array2string(data) + "\n") f.close() # We're done, stop the session. All buffered/waiting data is thrown # away. This call will block until the server has confirmed that the # session has ended. client.stop_session() # Calling stop_session before disconnect is not necessary as # disconnect will call stop_session if a session is started. # Remember to always call disconnect to do so gracefully client.disconnect()