Hi Luis Felipe - So section 3.1.5 is meant to show you some of the
functionality of GRC and Python scripting. GRC is used as the primary
means to create the flowgraph visually, and then to generate a Python
script that can be executed. In this specific case, the tutorial is
asking you to also edit the generated Python to show alternative
functionality -- editing lines 74-80 roughly. The resulting lines should
read like those found after the text "Thus we can go back and modify our
probe function with the if-else statement to give power to our friend.".
Note that the tutorial authors also made a copy of the generated Python
script ... original is "if_else.py", and they copy it to
"if_else_mod.py". I'd recommend doing so, to avoid overwriting from
within GRC.
Yet another item to notice is that if your file "if_else_mod.py" reads
like that found immediately after the text "Full code copied below:",
then it will rarely execute cleanly (when running via "python
if_else_mod.py" or the like; I'd actually recommend using "python2.7
if_else_mod.py" on Mac OS X, just to be clear). The error will read
something like:{{{
% python2.7 /tmp/if_else_mod.py
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib-
  /python2.7/threading.py", line 801, in __bootstrap_inner    self.run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib-
  /python2.7/threading.py", line 754, in run    self.__target(*self.__args, 
**self.__kwargs)
  File "/tmp/if_else_mod.py", line 81, in
  _variable_function_probe_0_probe    self.set_ampl(.3)
  File "/tmp/if_else_mod.py", line 177, in set_ampl
    self.analog_sig_source_x_1.set_amplitude(self.ampl)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib-
  /python2.7/site-packages/gnuradio/gr/hier_block2.py", line 92, in
  __getattr__    return getattr(self._impl, name)
AttributeError: 'top_block_sptr' object has no attribute 
'analog_sig_source_x_1'}}}

The reason for the error is the changes made for this tutorial result in
a variable (self.analog_sig_source_x_1) being accessed before it is
created. A fix is to move the section of code with:{{{
        def _variable_function_probe_0_probe():
            [snip]
         _variable_function_probe_0_thread =
         threading.Thread(target=_variable_function_probe_0_probe)         
_variable_function_probe_0_thread.daemon = True
         _variable_function_probe_0_thread.start()
}}}
to just before the text "# QT sink close method reimplementation" and at
the same indentation level. The error comes about because the thread is
started (the last line), and the thread starts executing & then calls
"set_ampl" which in turn references the variable
"self.analog_sig_source_x_1" which won't be created until later in the
Python script from when this thread is started.
Hope this is useful (to you & others trying this tutorial). - MLD

On Sun, Sep 24, 2017, at 02:26 PM, Luis Felipe Albarracin Sanchez wrote:> I get 
o tried to do that "python  file" manually, but It did not work.
> Maybe I am doing it wrong. I opened opened a terminal in the folder
> where the python file is and I placed the manual commands that are on
> the tutorial, but the console shows an error. Do you know how to do
> this the rigth way?
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to