I spoke too soon – general blocks seem to be well-supported in python. My memory might come from a time where gr_modtool didn't have a template for general blocks. So, yeah, you're right, we have the magic in place needed to let Python classes build upon the simple block (non-fixed-rate).
So, what I did was use gr_modtool to make a new module, and then went ahead and used `gr_modtool add -l python -t general` to add a new python general block. Best regards, Marcus On 05/26/2017 02:22 AM, Zach Morris wrote: > Hmm, interesting. The code below suggests that the Python interface > used to support general blocks. I wonder if it could still be > implemented by extending basic_block. > > Do you know if there are any good tutorials on using the consume() or > forecast() functions in Python? The Python tutorials I've seen seem to > stop right after mentioning that those blocks exist. > > Zach > > On May 25, 2017 2:25 PM, "Marcus Müller" <marcus.muel...@ettus.com > <mailto:marcus.muel...@ettus.com>> wrote: > > Hi Zach, > > not sure the Python interface supports general blocks (ie. blocks > where > the number of output items is not a multiple of the input items), > I hope > someone else can comment; I'd recommend implementing this as a C++ > block; the "Guided Tutorials" on http://tutorials.gnuradio.org should > prepare you to do that. > > Best regards, > > Marcus > > > On 25.05.2017 18 <tel:25.05.2017%2018>:08, Zach Morris wrote: > > Hello Marcus, > > > > I realize this is a couple years later but I am attempting to do > the same > > type of arbitrary ratio block, where samples above a threshold > are passed > > and samples below that threshold are dropped. > > > > When I tried to subclass gr.block (as below, and in this > tutorial from 2014 > > > > <https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide#arbitrary-ratio-block > > <https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide#arbitrary-ratio-block>> > > ) in an embedded Python block, GRC threw an error saying > gr.block could not > > be found. Does this method still work, or is there an updated > method with > > basic_block to implement arbitrary ratio blocks in Python? > > > > Greetings from Menlo Park, CA, > > > > Zach > > > > > > > > Marcus Müller-3 wrote > >> Hi Bob, > >> > >> I think you've introduced the "j" variable to keep count of how > many > >> items you're going to produce, but then just tell the scheduler > you've > >> produced as many items as he offered you to do. Replace > >> self.produce(0,len(out0)) > >> by > >> self.produce(0,j). > >> Also, you consume ninput_items every for loop iteration, so > >> ninput_items^2 per work run. That's not right; do it only once, > after > >> the loop. > >> > >> Greetings, > >> > >> Marcus > >> > >> On 12/24/2014 12:21 PM, bob wole wrote: > >>> Hi list, > >>> > >>> I am writing a custom python block that should take complex input, > >>> check magnitude of incoming samples and if the magnitude is > greater > >>> than a threshold value, the block should pass that sample > otherwise > >>> the block just drop the samples. As this is an arbitrary ratio > block I > >>> derived it from gr.block and set_auto_consume(False). > >>> > >>> However I get intermittent zeros in output stream of my custom > block. > >>> Below is the code > >>> > >>> from gnuradio import gr > >>> import gnuradio.extras > >>> import math > >>> import numpy as np > >>> > >>> > >>> class sdr_pass_valid(gr.block): > >>> """ > >>> """ > >>> def __init__(self,threshold): > >>> gr.block.__init__( > >>> self, > >>> name = "VALID", > >>> in_sig = [np.complex64], > >>> out_sig = [np.complex64], > >>> ) > >>> self.set_auto_consume(False) > >>> > >>> self.threshold = threshold > >>> def forecast (self,noutput_items,ninput_items_required): > >>> for i in range(len(ninput_items_required)): > >>> ninput_items_required[i] = noutput_items > >>> > >>> def work(self, input_items, output_items): > >>> > >>> in0 = input_items[0][:len(output_items[0])] > >>> out0= output_items[0] > >>> nread = self.nitems_read(0) #number of items read on > port 0 > >>> ninput_items = len(in0) > >>> j=0 > >>> for i in range(0,ninput_items): > >>> if np.absolute(in0[i]) >= self.threshold : > >>> out0[j] = in0[i] > >>> j = j + 1 > >>> self.consume(0,ninput_items) > >>> self.produce(0,len(out0)) > >>> return 0 > >>> > >>> > >>> -- > >>> Bob > >>> > >>> > >>> _______________________________________________ > >>> Discuss-gnuradio mailing list > >>> > >> Discuss-gnuradio@ > >>> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > <https://lists.gnu.org/mailman/listinfo/discuss-gnuradio> > >> > >> _______________________________________________ > >> Discuss-gnuradio mailing list > >> Discuss-gnuradio@ > >> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > <https://lists.gnu.org/mailman/listinfo/discuss-gnuradio> > > > > > > > > > > -- > > View this message in context: > http://gnuradio.4.n7.nabble.com/Python-block-help-tp51706p64046.html > <http://gnuradio.4.n7.nabble.com/Python-block-help-tp51706p64046.html> > > Sent from the GnuRadio mailing list archive at Nabble.com. > > > > _______________________________________________ > > Discuss-gnuradio mailing list > > Discuss-gnuradio@gnu.org <mailto:Discuss-gnuradio@gnu.org> > > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > <https://lists.gnu.org/mailman/listinfo/discuss-gnuradio> > > > _______________________________________________ > Discuss-gnuradio mailing list > Discuss-gnuradio@gnu.org <mailto:Discuss-gnuradio@gnu.org> > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio > <https://lists.gnu.org/mailman/listinfo/discuss-gnuradio> > >
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio