Quantcast

Problem writing custom null sync block

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem writing custom null sync block

maiconkist
Hi list,

I'm writing a custom null sync block called "file_writer". What I want to do is dump (to file or screen) what my null sync is receiving).

The problem is that if I use the file_writer in a flow graph, after the "work" function is executed a few times it starts to receive the same input forever.

I created a simple flow graph in gnuradio-companion that shows the FFT of the signal received in a USRP source.
When I modify the generated python code and insert the file_writer right after a stream_to_vector block, the flow graph "hangs" and process the same data over and over again.

Any suggestions of what is missing ?

Here's the code of my simple block:

####
class file_writer(gr.sync_block):
        ## CTOR
        #
        def __init__(self, filename, vec_size):
                gr.sync_block.__init__(
                                self,
                                "file name block",
                                in_sig = [np.dtype((np.float32, vec_size))],
                                out_sig = None
                                )

                self._fd = open(filename, 'w')
                self._filename = filename


        def work(self, input_items, output_items):
                in0 = input_items[0]

                print "###### ",  len(in0)
                print in0
               
                return len(output_items)


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem writing custom null sync block

Tom Rondeau-2
On Fri, Feb 22, 2013 at 8:42 AM, maiconkist <[hidden email]> wrote:

> Hi list,
>
> I'm writing a custom null sync block called "file_writer". What I want to do
> is dump (to file or screen) what my null sync is receiving).
>
> The problem is that if I use the file_writer in a flow graph, after the
> "work" function is executed a few times it starts to receive the same input
> forever.
>
> I created a simple flow graph in gnuradio-companion that shows the FFT of
> the signal received in a USRP source.
> When I modify the generated python code and insert the file_writer right
> after a stream_to_vector block, the flow graph "hangs" and process the same
> data over and over again.
>
> Any suggestions of what is missing ?
>
> Here's the code of my simple block:
>
> ####
> class file_writer(gr.sync_block):
>         ## CTOR
>         #
>         def __init__(self, filename, vec_size):
>                 gr.sync_block.__init__(
>                                 self,
>                                 "file name block",
>                                 in_sig = [np.dtype((np.float32, vec_size))],
>                                 out_sig = None
>                                 )
>
>                 self._fd = open(filename, 'w')
>                 self._filename = filename
>
>
>         def work(self, input_items, output_items):
>                 in0 = input_items[0]
>
>                 print "###### ",  len(in0)
>                 print in0
>
>                 return len(output_items)

What is the length of output_items? Because you don't have an output
buffer attached to this block, I'd be concerned that len(output_items)
== 0, so you're telling the scheduler that you aren't consuming any
data. Maybe just replace that last line with 'return
len(input_items)'?

Tom

_______________________________________________
Discuss-gnuradio mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem writing custom null sync block

Martin Braun (CEL)
On Fri, Feb 22, 2013 at 09:09:19AM -0500, Tom Rondeau wrote:

> > ####
> > class file_writer(gr.sync_block):
> >         ## CTOR
> >         #
> >         def __init__(self, filename, vec_size):
> >                 gr.sync_block.__init__(
> >                                 self,
> >                                 "file name block",
> >                                 in_sig = [np.dtype((np.float32, vec_size))],
> >                                 out_sig = None
> >                                 )
> >
> >                 self._fd = open(filename, 'w')
> >                 self._filename = filename
> >
> >
> >         def work(self, input_items, output_items):
> >                 in0 = input_items[0]
> >
> >                 print "###### ",  len(in0)
> >                 print in0
> >
> >                 return len(output_items)
>
> What is the length of output_items? Because you don't have an output
> buffer attached to this block, I'd be concerned that len(output_items)
> == 0, so you're telling the scheduler that you aren't consuming any
> data. Maybe just replace that last line with 'return
> len(input_items)'?
It's probably 'len(in0)', as len(input_items) would return the number of
input ports. 'len(output_items[0])' would probably also work.

MB

--
Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin Braun
Research Associate

Kaiserstra├če 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT -- University of the State of Baden-W├╝rttemberg and
National Laboratory of the Helmholtz Association

_______________________________________________
Discuss-gnuradio mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem writing custom null sync block

maiconkist
Hi,

you're right. Using "return len(in0)" solve my problem.

Thanks
Loading...