From 22e24497a510c174e6de7718ad918a423d1973dd Mon Sep 17 00:00:00 2001 From: Andrej Rode Date: Thu, 9 Feb 2017 11:16:16 -0800 Subject: python: Initial commit of Python API Initial commit of the Python API using Boost.Python. Bind the MultiUSRP API for use in Python. Bindings intended to provide as complete coverage as possible. - Wrap most multi_usrp calls - Adding multi channel send/recv examples in examples/python - Adding setuptools support - Initial attempt at binding the UHD types and filters --- host/examples/python/pyuhd_rx_to_file.py | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 host/examples/python/pyuhd_rx_to_file.py (limited to 'host/examples/python/pyuhd_rx_to_file.py') diff --git a/host/examples/python/pyuhd_rx_to_file.py b/host/examples/python/pyuhd_rx_to_file.py new file mode 100755 index 000000000..0b4956b33 --- /dev/null +++ b/host/examples/python/pyuhd_rx_to_file.py @@ -0,0 +1,46 @@ +#! /usr/bin/env python +# +# Copyright 2017 Ettus Research LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + + +import numpy as np +import uhd +import argparse + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("-a", "--args", default="", type=str) + parser.add_argument("-o", "--output-file", type=str, required=True) + parser.add_argument("-f", "--freq", type=float, required=True) + parser.add_argument("-r", "--rate", default=1e6, type=float) + parser.add_argument("-d", "--duration", default=5.0, type=float) + parser.add_argument("-c", "--channels", default=0, nargs="+", type=int) + parser.add_argument("-g", "--gain", type=int, default=10) + return parser.parse_args() + +def main(): + args = parse_args() + usrp = uhd.multi_usrp(args.args) + num_samps = int(np.ceil(args.duration*args.rate)) + if not isinstance(args.channels, list): + args.channels = [args.channels] + samps = usrp.recv_num_samps(num_samps, args.freq, args.rate, args.channels, args.gain) + with open(args.output_file, 'wb') as f: + np.save(f, samps, allow_pickle=False, fix_imports=False) + +if __name__ == "__main__": + main() -- cgit v1.2.3