discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] Fwd: Write a source block in python


From: Martin Braun
Subject: Re: [Discuss-gnuradio] Fwd: Write a source block in python
Date: Fri, 23 Jan 2015 10:54:34 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

On 01/22/2015 11:53 PM, Thanasis Balafoutis wrote:
> Thank you Doug!
> 
> return -1 indeed cause the flowgraph to exit. Is there any trick to stop
> also the execution on my program (after 1 sec)?

You can exit whenever you like. E.g. run a timer until 1 sec is over and
then return -1.

When you return -1, the FG *should* shut down by itself.

> Another problem I have is that the output is always 32768 bytes

You have no problem: Your output *buffer* is of this size. Your output
size is whatever you return (something like return len(test) would be
what you want).

M

> def work(self, input_items, output_items):
> ........
> return len(output_items[0])
> 
> If I change it to this:
>    return len(output_items[0][:len(test)])
> my output becomes empty
> Is it possible to get in the output the exact number of bytes of my
> helloMsg parameter?
> 
> 2015-01-22 23:31 GMT+02:00 Anderson, Douglas J.
> <address@hidden <mailto:address@hidden>>:
> 
>     I think having the work fn return "-1" will cause the flowgraph to
>     exit, so you could potentially have a "self.count = 1" in __init__
>     and then when you've output >= self.count, have work return -1
> 
>     -Doug
> 
>     *Douglas Anderson**| Intern*
>     DOC/NTIA/ITS-T | 325 Broadway St., Boulder, CO 80305 | P: 303 497
>     3582 <tel:303%20497%203582>
>     ------------------------------------------------------------------------
>     *From:* address@hidden
>     <mailto:address@hidden>
>     address@hidden
>     <mailto:address@hidden>] on behalf of Thanasis Balafoutis
>     address@hidden <mailto:address@hidden>]
>     *Sent:* Thursday, January 22, 2015 2:12 PM
>     *To:* address@hidden <mailto:address@hidden>
>     *Subject:* [Discuss-gnuradio] Fwd: Write a source block in python
> 
>     Hi
> 
>     I wrote a simple source block that reads a string (as a parameter)
>     and outputs the corresponding array of bytes.
>     Here is the code:
> 
>     class myblock(gr.sync_block):
> 
>         def __init__(self, helloMsg):
>             gr.sync_block.__init__(self,
>                 name="myblock",
>                 in_sig=None,
>                 out_sig=[numpy.byte])
>             self.helloMsg = helloMsg
> 
>         def work(self, input_items, output_items):
>             out = output_items[0]
>            
>             test = array.array('B',self.helloMsg)
>             for j in range(len(test)):
>                out[j] = test[j]
>             return len(output_items[0][:len(test)])
> 
>     In the output I repeatedly get the helloMsg. (it seems that the
>     work() function is always running)
>     Is it possible to get in the output my helloMsg only one time (or a
>     specific amount of times) and then stop the execution of the flowgraph?
> 
>     Thank you in advance!
>     Thanasis
> 
> 
> 
> 
> _______________________________________________
> Discuss-gnuradio mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
> 




reply via email to

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