Re: [Discuss-gnuradio] Python Tutorial for MAC OS 10.12
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_innerself.run() File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib- /python2.7/threading.py", line 754, in runself.__target(*self.__args, **self.__kwargs) File "/tmp/if_else_mod.py", line 81, in _variable_function_probe_0_probeself.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
Re: [Discuss-gnuradio] Python Tutorial for MAC OS 10.12
Hello everyone, Thanks for the responses, they are helpful. Michael, 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? Thanks again. El sept. 24, 2017 12:20 PM, "Michael Dickens"escribió: > Hi Luis Felipe - OK; thanks for clarifying. When you click the button > "generate the flowgraph", GRC creates the Python file -- overwriting > anything that might be there already. So, any changes to the Python file > are lost when you have GRC generate the flowgraph. Note that, at the very > end of 3.1.5, you execute the (new) Python script by hand: "python > if_else_mod.py". So, do the file edits, save the Python script, but -do > not- click the button "generate the flowgraph". Hope this helps! - MLD > > On Sun, Sep 24, 2017, at 01:00 PM, Luis Felipe Albarracin Sanchez wrote: > > Thank you for the quick response, > > I think you are rigth, i need to clarify better my problem, i started > from scratch the Tutorial, and i placed all blocks according to the > Tutorial. After that i clicked on "generate the flowgraph". Once i did this > in the folder where the GRC is saved Python file was created. I opened this > file to edit it as proposed in the section 3.1.5 of the Tutorial and wrote > the lines that in the tutorial said should be added to make Flowgraph work > taking into account the two signals. I did this, i wrote the new code i > saved it on python (the same file), and then i clicked again on "Generate > the flowgraph" hoping that the "flowgraph" will take the changes on the > python files, but it did not happend; what it happend is that it created > again a Python file overwritting the one the one that i did changes on. i > am kind of lost. How can i make the flowgraphs to take Python script once > it have change it? > > > ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Python Tutorial for MAC OS 10.12
Hi Luis Felipe - OK; thanks for clarifying. When you click the button "generate the flowgraph", GRC creates the Python file -- overwriting anything that might be there already. So, any changes to the Python file are lost when you have GRC generate the flowgraph. Note that, at the very end of 3.1.5, you execute the (new) Python script by hand: "python if_else_mod.py". So, do the file edits, save the Python script, but -do not- click the button "generate the flowgraph". Hope this helps! - MLD On Sun, Sep 24, 2017, at 01:00 PM, Luis Felipe Albarracin Sanchez wrote:> Thank you for the quick response, > > I think you are rigth, i need to clarify better my problem, i > started from scratch the Tutorial, and i placed all blocks according > to the Tutorial. After that i clicked on "generate the flowgraph". > Once i did this in the folder where the GRC is saved Python file was > created. I opened this file to edit it as proposed in the section > 3.1.5 of the Tutorial and wrote the lines that in the tutorial said > should be added to make Flowgraph work taking into account the two > signals. I did this, i wrote the new code i saved it on python (the > same file), and then i clicked again on "Generate the flowgraph" > hoping that the "flowgraph" will take the changes on the python files, > but it did not happend; what it happend is that it created again a > Python file overwritting the one the one that i did changes on. i am > kind of lost. How can i make the flowgraphs to take Python script once > it have change it? ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Python Tutorial for MAC OS 10.12
On Sun, Sep 24, 2017 at 10:00 AM, Luis Felipe Albarracin Sanchez < lfasanc...@gmail.com> wrote: > i started from scratch the Tutorial, and i placed all blocks according > to the Tutorial. After that i clicked on "generate the flowgraph". Once i > did this in the folder where the GRC is saved Python file was created. I > opened this file to edit it as proposed in the section 3.1.5 of the > Tutorial and wrote the lines that in the tutorial said should be added to > make Flowgraph work taking into account the two signals. I did this, i > wrote the new code i saved it on python (the same file), and then i clicked > again on "Generate the flowgraph" hoping that the "flowgraph" will take the > changes on the python files, but it did not happend; what it happend is > that it created again a Python file overwritting the one the one that i did > changes on. i am kind of lost. How can i make the flowgraphs to take Python > script once it have change it? > GNU Radio Companion does not ever read the Python file. The point of modifying the Python file is to accomplish things that you *cannot* put into GRC. Once you have modified it you need to keep it separately from GRC and edit it by hand for any further changes you want to make. One way to make this easier to deal with is to use hierarchical blocks so that the parts that GRC can do are done in GRC, and the amount of hand-maintained Python code is smaller. You can either have GRC make a hierarchical block instead of a top block and use that from Python, or you can write a hierarchical block containing your custom code and use that from GRC. ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Python Tutorial for MAC OS 10.12
Hello Michael, Thank you for the quick response, I think you are rigth, i need to clarify better my problem, i started from scratch the Tutorial, and i placed all blocks according to the Tutorial. After that i clicked on "generate the flowgraph". Once i did this in the folder where the GRC is saved Python file was created. I opened this file to edit it as proposed in the section 3.1.5 of the Tutorial and wrote the lines that in the tutorial said should be added to make Flowgraph work taking into account the two signals. I did this, i wrote the new code i saved it on python (the same file), and then i clicked again on "Generate the flowgraph" hoping that the "flowgraph" will take the changes on the python files, but it did not happend; what it happend is that it created again a Python file overwritting the one the one that i did changes on. i am kind of lost. How can i make the flowgraphs to take Python script once it have change it? Thanks again. Kind regards. On Sun, Sep 24, 2017 at 11:48 AM, Michael Dickenswrote: > Hi Luis Felipe - Nice to hear from another MacOS X user of GNU Radio; > there are actually quite a few of us "out there"... > > Maybe you can clarify what you mean by "goes back to the original". Step > 3.1.5 has you modify the GRC flowgraph, which will in turn generate an > updated Python script; you view the changes in the Python script to get an > idea of the connection between the GRC representation of a flowgraph and > the Python version (among other connections). If you succeed in the GRC > flowgraph changes, when you click the button "Generate the flow graph" then > the flowgraph's Python script will be updated. > > I hope this is useful! If not, ask more questions! - MLD > > On Sun, Sep 24, 2017, at 12:00 PM, Luis Felipe Albarracin Sanchez wrote: > > Is mi first time here, and i am just learning about how to work with > GNURadio on MAC OS. > > I am following this tutorial: > > https://wiki.gnuradio.org/index.php/Guided_Tutorial_GNU_Radio_in_Python > > And when i reach the section 3.1.5, i rewrite the code and save it on > Python, but once i hit "Execute the flowgraph" the code goes back to the > original. > > Would anyone please tell me how can i execute the flowgraph and make the > new code in python be accepted for the flowgraph. > > > -- Eng. Luis Felipe Albarracin PMP CCNA/CCDA/CCNP/CCDP/CCIP ITIL v3 Foundation Msc. Telematics / MBA "Die Grenzen meiner Sprache bedeuten die Grenzen meiner Welt" ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Python Tutorial for MAC OS 10.12
Hi Luis Felipe - Nice to hear from another MacOS X user of GNU Radio; there are actually quite a few of us "out there"... Maybe you can clarify what you mean by "goes back to the original". Step 3.1.5 has you modify the GRC flowgraph, which will in turn generate an updated Python script; you view the changes in the Python script to get an idea of the connection between the GRC representation of a flowgraph and the Python version (among other connections). If you succeed in the GRC flowgraph changes, when you click the button "Generate the flow graph" then the flowgraph's Python script will be updated. I hope this is useful! If not, ask more questions! - MLD On Sun, Sep 24, 2017, at 12:00 PM, Luis Felipe Albarracin Sanchez wrote:> Is mi first time here, and i am just learning about how to work with > GNURadio on MAC OS.> > I am following this tutorial: > > https://wiki.gnuradio.org/index.php/Guided_Tutorial_GNU_Radio_in_Python> > And when i reach the section 3.1.5, i rewrite the code and save it > on Python, but once i hit "Execute the flowgraph" the code goes back > to the original.> > Would anyone please tell me how can i execute the flowgraph and make > the new code in python be accepted for the flowgraph. ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio