I am using two TVRx modules on the same motherboard to write a 1 second
sample every minute for 30mins. theoretically I should have 60 sample sets,
collectively.

I am able to write the first sample set succesfully but all writes after
that fail!

Please take a moment to look at what I may be doing wrong.

with thanks.

+++++++++++++++++++++++++++++++++++++++++++++++++

class my_top_block(gr.top_block):

    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename0 output_filename1 "

        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R", "--rx-subdev-spec0", type="subdev",
default=None,
                        help="first channel select USRP Rx side A or B
(default=A)")
        parser.add_option("-r", "--rx-subdev-spec1", type="subdev",
default=None,
                        help="second channel select USRP Rx side A or B
(default=A)")
        parser.add_option("-d", "--decim", type="int", default=256,
                        help="set fgpa decimation rate to DECIM
[default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=100e6,
                        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("-N", "--nsamples", type="eng_float",
default=9600000,
                        help="number of samples to collect
[default=9600000]")
        parser.add_option("-t", "--time", type="eng_float", default=0,
                        help="length of recording in seconds [default=0]")

        (options, args) = parser.parse_args ()

        decim_rate = options.decim

        if options.time:
            options.nsamples = int(float(options.time) * 64e6 /
float(decim_rate))
        else:
            options.time = float(options.nsamples / (64e6 /
float(decim_rate)) )

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

        # setup USRP source
        self.u = usrp.source_c(decim_rate = options.decim, nchan = 2)

        # set up daughterboard positions and subdevices
        if options.rx_subdev_spec0 is None:
            options.rx_subdev_spec0 = (0,0)

        if options.rx_subdev_spec1 is None:
            options.rx_subdev_spec1 = (1,0)

        # determine the daughterboard subdevice we're using
        self.subdev0 = usrp.selected_subdev(self.u, options.rx_subdev_spec0)
        self.subdev1 = usrp.selected_subdev(self.u, options.rx_subdev_spec1)

        #setup Mux
        mux_val0 = usrp.determine_rx_mux_value(self.u,
options.rx_subdev_spec0)
        mux_val1 = usrp.determine_rx_mux_value(self.u,
options.rx_subdev_spec1)
        mux_val0 |= (mux_val1 <<  8) & 0xff00
        self.u.set_mux(mux_val0)


        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g0 = self.subdev0.gain_range()
            g1 = self.subdev1.gain_range()
            options.gain = float(g0[0]+g0[1])/2

        self.subdev0.set_gain(options.gain)
        self.subdev1.set_gain(options.gain)

        ddc = -19.9e6
        self.subdev = (self.subdev0, self.subdev1)


        #Tune daughterboards
        for n in range(2):
            ok, baseband_freq = self.subdev[n].set_freq(options.freq)
            print "baseband Freq is: %s" %
(eng_notation.num_to_str(baseband_freq))
            dxc_freq, inverted = usrp.calc_dxc_freq(options.freq,
baseband_freq,
                                                    self.u.converter_rate())
            print "dxc Freq is: %s" % (eng_notation.num_to_str(dxc_freq))
            print "ddc Freq is: %s" % (eng_notation.num_to_str(ddc))
            self.u.set_rx_freq(n, ddc)

        input_rate = self.u.adc_freq() / self.u.decim_rate()
        print "Using RX d'board %s" % (self.subdev0.side_and_name(),)
        print "Using RX d'board %s" % (self.subdev1.side_and_name(),)
        print "USB sample rate: %s" % (eng_notation.num_to_str(input_rate))
        print "Freq is set to: %s" % (eng_notation.num_to_str(options.freq))
        print "Recording time is: %ss" % (options.time)
        print "Mux value is: %x" % (mux_val0 & 65535)

        self.num_samples = options.nsamples

        #return (self, num_samples)


    def __del__(self):
    # Avoid weak reference error
        del self.subdev

    def write_file(self, file_num, file_size):


        # deinterleave two channels from FPGA
        self.di = gr.deinterleave(gr.sizeof_gr_complex)

        self.skiphead0 = gr.skiphead(gr.sizeof_gr_complex, 1000)
        self.skiphead1 = gr.skiphead(gr.sizeof_gr_complex, 1000)

        self.head0 = gr.head(gr.sizeof_gr_complex, file_size)
        self.head1 = gr.head(gr.sizeof_gr_complex, file_size)

        self.dst0 = gr.file_sink(gr.sizeof_gr_complex, ('moda%s' %
file_num))
        self.dst1 = gr.file_sink(gr.sizeof_gr_complex, ('modb%s' %
file_num))

        # wire up the head of the chain
        self.connect(self.u, self.di)
        self.connect((self.di,0), self.skiphead0, self.head0, self.dst0)
        self.connect((self.di,1), self.skiphead1, self.head1, self.dst1)



if __name__ == '__main__':

    total_time = 3
    t = 0
    n_s = 0

    tb = my_top_block()
    n_s = tb.num_samples

    try:

        while t < total_time:
            t = t+1

            print "setup graph"
            tb.write_file(t, n_s)
            print "run graph"
            tb.start()
            #tb.run()
            print "graph terminated"
            print "sleep on"
            time.sleep(60)
            tb.stop()
            tb.wait()
            print "sleep off"

    except KeyboardInterrupt:
        pass

++++++++++++++++++++++++++++++++++++++++++++++++++
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to