discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Python code error on Windows


From: Mark Colin
Subject: [Discuss-gnuradio] Python code error on Windows
Date: Thu, 7 Jul 2011 15:48:43 -0700 (PDT)

Hi list and Josh,

    I need your help. As Josh told me I CMake'ified this UCLA ZigBee project based on a similar structured project and made a gr-ucla folder with all needed files, I compiled it and got the gnuradio-UCLA.dll, gnuradio-UCLA.lib files; the swig interface file (UCLA.py, _UCLA.lib and _UCLA.pyd), I put everything into it's place, but I have some problems with the python code: when I ran test files I had some errors because it wasn't using the UHD driver, I changed code (usrp... to uhd...), now if I run test files the USRP is recognized, *rbf file is written to FPGA, it starts to execute python code and I get a big error:

cordic_freq = 434.845M
data_rate =  38.4k
samples_per_symbol =  8
fs =  307.2k
Sampling rate: 250000
Center frequency: 434845200
Traceback (most recent call last):
  File "C:\program files (x86)\gnuradio\ieee802_examples\uhd_cc1k_txtest.py", line 165, in <module>
    main ()
  File "C:\program files (x86)\gnuradio\ieee802_examples\uhd_cc1k_txtest.py", line 146, in main
    tb.start()
  File "c:\program files (x86)\gnuradio\lib\site-packages\gnuradio\gr\top_block.py", line 97, in start
    self._tb.start()
  File "c:\program files (x86)\gnuradio\lib\site-packages\gnuradio\gr\gnuradio_core_runtime.py", line 1476, in start
    return _gnuradio_core_runtime.gr_top_block_sptr_start(self)
RuntimeError: In hierarchical block cc1k_mod_pkts, input 0 is not connected internally

I want to use python to understand how all this USRP and GnuRadio thing works until I will make everything in C (interface and function calls).

Here is the source code:

from gnuradio import gr, eng_notation
from gnuradio import uhd
from gnuradio import audio
from gnuradio import ucla
from gnuradio.ucla_blks import cc1k_sos_pkt
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import math
import struct, time

##from gnuradio.wxgui import stdgui, fftsink, scopesink
##import wx

##def pick_subdevice(u):
##    """
##    The user didn't specify a subdevice on the command line.
##    If there's a daughterboard on A, select A.
##    If there's a daughterboard on B, select B.
##    Otherwise, select A.
##    """
##    if u.db[0][0].dbid() >= 0:       # dbid is < 0 if there's no d'board or a problem
##        return (0, 0)
##    if u.db[1][0].dbid() >= 0:
##        return (1, 0)
##    return (0, 0)

class transmit_path(gr.top_block):
    def __init__(self, options):
        gr.top_block.__init__(self)
        self.normal_gain = 8000

        self.data_rate = options.data_rate
        self.samples_per_symbol = 8
        self.fs = self.data_rate * self.samples_per_symbol
        payload_size = 128             # bytes

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "fs = ", eng_notation.num_to_str(self.fs)

        self.u = uhd.usrp_sink('type=usrp1',
                               io_type=uhd.io_type.COMPLEX_FLOAT32,
                               num_channels=1)
##        self.u.set_clock_config(uhd.clock_config.internal(), uhd.ALL_MBOARDS)
        u = self.u

        # Set and print sampling rate
        self._samp_rate = 200000
        self.u.set_samp_rate(self._samp_rate)
        input_rate = self.u.get_samp_rate()
        print "Sampling rate: %d" %(input_rate)

        # Set and print center frequency
        self.u.set_center_freq(options.cordic_freq)
        frekva = self.u.get_center_freq()
        print "Center frequency: %d" %(frekva)

        # transmitter
        self.packet_transmitter = cc1k_sos_pkt.cc1k_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2)
        self.amp = gr.multiply_const_cc (self.normal_gain)
        self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'tx_test.dat')

        self.connect(self.amp, self.filesink)
        self.connect(self.packet_transmitter, self.amp, self.u)

##        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
##        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching

    def set_gain(self, gain):
        self.gain = gain
        self.subdev.set_gain(gain)

    def set_auto_tr(self, enable):
        return self.subdev.set_auto_tr(enable)

    def send_pkt(self, payload='', eof=False):
        return self.packet_transmitter.send_pkt(am_group=1, module_src=128, module_dst=128, dst_addr=65535, src_addr=2, msg_type=32, payload=payload, eof=eof)

    def bitrate(self):
        return self._bitrate

    def spb(self):
        return self.spb

def main ():

    parser = OptionParser (option_class=eng_option)
    parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                      help="select USRP Tx side A or B (default=first one with a daughterboard)")
    parser.add_option ("-c", "--cordic-freq", type="eng_float", default=434845200,
                       help="set Tx cordic frequency to FREQ", metavar="FREQ")
    parser.add_option ("-r", "--data-rate", type="eng_float", default=38400)
    parser.add_option ("-f", "--filename", type="string",
                       default="rx.dat", help="write data to FILENAME")
    parser.add_option ("-g", "--gain", type="eng_float", default=0,
                       help="set Rx PGA gain in dB [0,20]")
    parser.add_option ("-N", "--no-gui", action="", default=False)

    (options, args) = parser.parse_args ()
    print "cordic_freq = %s" % (eng_notation.num_to_str(options.cordic_freq))

    tb = transmit_path(options)
    tb.start()

    for i in range(100):

        print "send message %d:"%(i+1,)
        tb.send_pkt(payload=struct.pack('9B', 0x1, 0x80, 0x80, 0xff, 0xff, 0x10, 0x0, 0x20, 0x0))
        time.sleep(0.1)

if __name__ == '__main__':
    main ()

Maybe I should learn more python, anyway I will use it only to learn how all these stuff works. Anyway I feel I'm close to make it work (maybe I'm wrong - I know it's one thing to make something and than another thing to debug it and make it work). Could anybody help me with some ideas, what to do, what's wrong.

One test file didn't report any error uhd_cc2420_txtest.py, and I can't figure out why this code has this error.

Thank you very much.

Mark.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]