discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] Using the UHD API for Python Programming


From: Alexander Olihovik
Subject: [Discuss-gnuradio] Using the UHD API for Python Programming
Date: Fri, 22 Jun 2012 10:33:47 -0400

Hi all,
I'm having some trouble using the C++ UHD API for writing Python code.
I understand that the code has been SWIG'd from C++ to Python.


Specifically, the C++ code I want to convert to Python is:
---------------------------------------
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
stream_cmd.num_samps = samps_to_recv;
stream_cmd.stream_now = false;
stream_cmd.time_spec = time_to_recv;
usrp->issue_stream_cmd(stream_cmd);
 
uhd::time_spec_t cmd_time = usrp->get_time_now() + uhd::time_spec_t(0.1);
usrp->set_command_time(cmd_time);
usrp->set_rx_freq(1.03e9, 0/*ch0*/);
usrp->set_rx_freq(1.03e9, 1/*ch1*/);
usrp->set_clear_time();
----------------------------------------


With my attempt at Python:
---------------------------------------
self.stream_cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.stream_mode_t.STREAM_MODE_NUM_SAMPS_AND_DONE)
self.stream_cmd.num_samps = samps_to_recv;
self.stream_cmd.stream_now = false;
self.stream_cmd.time_spec = time_to_recv;
self.uhd_usrp_source_0.issue_stream_cmd(self.stream_cmd)

cmd_time = self.uhd_usrp_source_0.get_time_now() + uhd.time_spec_t(0.1)
self.uhd_usrp_source_0.set_command_time(cmd_time)         
self.uhd_usrp_source_0.set_rx_freq(1.03e9, 0)
self.uhd_usrp_source_0.set_rx_freq(1.03e9, 1)
self.uhd_usrp_source_0.set_clear_time()
-----------------------------------------

Running this, I get the error:
AttributeError: 'module' object has no attribute 'stream_cmd_t'

What is this struct called after it has been swigged into Python, and how do I access it?
As a follow up, does anyone have any general guidelines to follow when writing code from the C++ UHD API into Python?
I've checked the gr-uhd source tree examples, but they didn't provide the insight needed to access the full C++ API.


-Alex

reply via email to

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