Hello,

I am trying to create a python equivalent of tx_samples.cc -- to transmit 
samples captured with usrp2_rx_cfile.py.  When running my program, I receive 
the following error:

Traceback (most recent call last):
  File "./usrp2_tx_cfile.py", line 151, in <module>
    tb = tx_cfile_block(options, filename)
  File "./usrp2_tx_cfile.py", line 80, in __init__
    self.connect(self._src, self._u);
  File "/usr/lib/python2.6/dist-packages/gnuradio/gr/top_block.py", line 124, 
in connect
    self._connect(points[i-1], points[i])
  File "/usr/lib/python2.6/dist-packages/gnuradio/gr/top_block.py", line 130, 
in _connect
    dst_block.basic_block(), dst_port)
  File 
"/usr/lib/python2.6/dist-packages/gnuradio/gr/gnuradio_swig_py_runtime.py", 
line 1443, in connect
    return _gnuradio_swig_py_runtime.gr_top_block_sptr_connect(*args)
ValueError: itemsize mismatch: file_source(2):0 using 2, usrp2_sink_16sc(1):0 
using 4

>From the error, it appears that the connect() call is failing, but I am not 
>sure why.

This is what my usrp2_tx_cfile.py looks like.

Thank you for your help.
Ilya


#!/usr/bin/env python
#
# Copyright 2004,2005,2007,2008,2009 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio 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, or (at your option)
# any later version.
#
# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

"""
Read samples from the USRP2 and write to file formatted as binary
outputs single precision complex float values or complex short values
(interleaved 16 bit signed short integers).
"""

from gnuradio import gr, eng_notation
from gnuradio import usrp2
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import sys

n2s = eng_notation.num_to_str

class tx_cfile_block(gr.top_block):

                def __init__(self, options, filename):
                                gr.top_block.__init__(self)

                                # Create a USRP2 source
                                if options.input_shorts:
                                                self._u = 
usrp2.sink_16sc(options.interface, options.mac_addr)
                                                #the last True is to restart 
the file when it is done
                                                self._src = 
gr.file_source(gr.sizeof_short,filename,True)
                                else:
                                                self._u = 
usrp2.sink_32fc(options.interface, options.mac_addr)
                                                #the last True is to restart 
the file when it is done
                                                self._src = 
gr.file_source(gr.sizeof_gr_complex, filename, True)

                                # Set transmitter interpolation rate
                                self._u.set_interp(options.interp)

                                # Set transmit daughterboard gain
                                if options.gain is None:
                                                g = self._u.gain_range()
                                                options.gain = 
float(g[0]+g[1])/2
                                                print "Using mid-point gain 
of", options.gain, "(", g[0], "-", g[1], ")"
                                #set the gain
                                self.amp = 10 ** (options.gain / 20 )
                                self._u.set_gain(self.amp)

                                # Set transmit frequency
                                if options.lo_offset is not None:
                                                
self._u.set_lo_offset(options.lo_offset)

                                tr = self._u.set_center_freq(options.freq)
                                if tr == None:
                                                sys.stderr.write('Failed to set 
center frequency\n')
                                                raise SystemExit, 1


                                #set output rate
                                output_rate = self._u.dac_rate() / 
self._u.interp()

                                #Filter if bandwidth was specified
                                if options.bandwidth is None:
                                                #self.connect(self._src, 
self.amp, self._u);
                                                self.connect(self._src, 
self._u);
                                else:
                                                lp_coeffs = gr.firdes.lowpass(
                                                                                
1,                                                                              
              #gain
                                                                                
output_rate,                                      #sampling frequency
                                                                                
options.bandwidth/2,   #cutoff frequency
                                                                                
options.bandwidth/2)   #transition width
                                                #if samples are shorts, convert 
to floats to do filtering
                                                if options.input_shorts:
                                                                self.s2c = 
gr.interleaved_short_to_complex();
                                                                self.lp = 
gr.fir_filter_ccf(1,lp_coeffs)
                                                                self.c2s = 
gr.complex_to_interleaved_short()
                                                                
self.connect(self._src, self.s2c, self.lp, self.amp, self.c2s,
                                                                                
                self._u)
                                                else:
                                                                self.lp = 
gr.fir_filter_ccf(1,lp_coeffs)
                                                                
self.connect(self._src, self.lp, self.amp, self._u)

                                if options.verbose:
                                                print "Network interface:", 
options.interface
                                                print "USRP2 address:", 
self._u.mac_addr()
                                                print "Using TX d'board id 
0x%04X" % (self._u.daughterboard_id(),)
                                                print "Tx gain:", options.gain
                                                print "Tx baseband frequency:", 
n2s(tr.baseband_freq)
                                                print "Tx DDC frequency:", 
n2s(tr.dxc_freq)
                                                print "Tx residual frequency:", 
n2s(tr.residual_freq)
                                                print "Tx interpolation rate:", 
options.interp
                                                print "Tx sample rate:", 
n2s(output_rate)
                                                if options.input_shorts:
                                                                print "Writing 
16-bit complex shorts"
                                                else:
                                                                print "Writing 
32-bit complex floats"
                                                print "Output filename:", 
filename

def get_options():
                usage="%prog: [options] input_filename"
                parser = OptionParser(option_class=eng_option, usage=usage)
                parser.add_option("-e", "--interface", type="string", 
default="eth0",
                                                help="use specified Ethernet 
interface [default=%default]")
                parser.add_option("-m", "--mac-addr", type="string", default="",
                                                help="use USRP2 at specified 
MAC address [default=None]")
                parser.add_option("-i", "--interp", type="int", default=32,
                                                help="set fgpa interpolation 
rate to INTERP [default=%default]")
                parser.add_option("-f", "--freq", type="eng_float", 
default=None,
                                                help="set frequency to FREQ", 
metavar="FREQ")
                parser.add_option("-g", "--gain", type="eng_float", 
default=None,
                                                help="set gain in dB (default 
is midpoint)")
                parser.add_option( "-s","--input-shorts", action="store_true", 
default=False,
                                                help="input interleaved shorts 
instead of complex floats")
                parser.add_option( "-b","--bandwidth", type="eng_float", 
default=None,
                                                help="bandwidth of signal to 
transmit [default=no filtering]")
                parser.add_option("-v", "--verbose", action="store_true", 
default=False,
                                                help="verbose output")
                parser.add_option("", "--lo-offset", type="eng_float", 
default=None,
                                                help="set daughterboard LO 
offset to OFFSET [default=hw default]")

                (options, args) = parser.parse_args ()
                if len(args) != 1:
                                parser.print_help()
                                raise SystemExit, 1

                if options.freq is None:
                                parser.print_help()
                                sys.stderr.write('You must specify the 
frequency with -f FREQ\n');
                                raise SystemExit, 1

                return (options, args[0])


if __name__ == '__main__':
                (options, filename) = get_options()
                tb = tx_cfile_block(options, filename)

                try:
                                tb.run()
                except KeyboardInterrupt:
                                pass
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to