(Python) Source Block Outputs All 0's

Hi All,

I have implemented a python source block:

def __init__(self, kA1=4,kB1=4,k2=4,NA1=8,NB1=8,N2=8,M=8):
    gr.sync_block.__init__(self,
        name="blsd_enc_b",
        in_sig=None,
        out_sig=[numpy.uint8,numpy.uint8])

but I can’t get it to output anything but 0’s…

def work(self, input_items, output_items):
    out_cA = output_items[0]
    out_cB = output_items[1]

    out_cA = [ 5, 6, 7, 8, 9, 10 ] #cA[0]
    out_cB = [ 5, 6, 7, 8, 9, 10 ] #cB[0]
    self.produce(0,len(out_cA))
    self.produce(1,len(out_cB))
    print 'out_cA = ', out_cA, ', len(out_cA) = ', len(out_cA)
    print 'out_cB = ', out_cB, ', len(out_cB) = ', len(out_cB)
    return -1 #-2

I connect both outputs to a file sync of type byte, and it stores 6
bytes but its all “\00\00\00\00\00\00”

The print lines give:

out_cA = [5, 6, 7, 8, 9, 10] , len(out_cA) = 6
out_cB = [5, 6, 7, 8, 9, 10] , len(out_cB) = 6

as expected.

Any advice?

Regards,

David


NOTE: The information in this email and any attachments may be
confidential and/or legally privileged. This message may be read, copied
and used only by the intended recipient. If you are not the intended
recipient, please destroy this message, delete any copies held on your
system and notify the sender immediately.

Toshiba Research Europe Limited, registered in England and Wales
(2519556). Registered Office 208 Cambridge Science Park, Milton Road,
Cambridge CB4 0GZ, England. Web: www.toshiba.eu/research/trl

On Tue, Feb 18, 2014 at 12:50 PM, David Halls
[email protected] wrote:

print 'out_cA = ', out_cA, ', len(out_cA) = ', len(out_cA)
out_cB = [5, 6, 7, 8, 9, 10] , len(out_cB) = 6

as expected.

Any advice?

Regards,

David

David,

The problem here is that you’re not inserting items in to the out_cA
(and out_cB) arrays, you’re actually reassigning out_cA to be this new
list.

Honestly, I’ve never written a python block, but my understanding is
that you’d have to do something like this http://dpaste.com/1634971/

The items in the out_items list are actually numpy arrays, and they
need to be indexed. The [:] indexing is a shortcut of indexing the
entire array.

Another thing I’m not really sure about is whether the -1 will work or
not. I think you might have to return 6 so that the scheduler knows
there are 6 items to work on, and then the next time work is called
you return -1 ( assuming you’re wanting to stop the flowgraph here?).
Somebody else might chime in here if I’m wrong.

Nathan

Hi Nathan,

Thanks for your reply :slight_smile:

I’ve done little python before, am trying to incorporate a collaborators
code into my system and he’s used python.

I am used to C, where it would copy the pointer. I understand your
advice - thanks, I will look at the link.

The return value is mimicking the WORK_CALLED_PRODUCE (-2) and WORK_DONE
return values that can be used when you have multiple outputs which may
output different number of items and the produce function is used.

I am not sure why the block keeps repeating if I use -2 as I use
successfully in many c++ blocks - I’m not used to writing source
blocks… maybe others have comments?

David


From: West, Nathan [[email protected]]
Sent: 18 February 2014 21:06
To: David Halls
Cc: GNURadio D.ion List
Subject: Re: [Discuss-gnuradio] (Python) Source Block Outputs All 0’s

On Tue, Feb 18, 2014 at 12:50 PM, David Halls
[email protected] wrote:

print 'out_cA = ', out_cA, ', len(out_cA) = ', len(out_cA)
out_cB = [5, 6, 7, 8, 9, 10] , len(out_cB) = 6

as expected.

Any advice?

Regards,

David

David,

The problem here is that you’re not inserting items in to the out_cA
(and out_cB) arrays, you’re actually reassigning out_cA to be this new
list.

Honestly, I’ve never written a python block, but my understanding is
that you’d have to do something like this http://dpaste.com/1634971/

The items in the out_items list are actually numpy arrays, and they
need to be indexed. The [:] indexing is a shortcut of indexing the
entire array.

Another thing I’m not really sure about is whether the -1 will work or
not. I think you might have to return 6 so that the scheduler knows
there are 6 items to work on, and then the next time work is called
you return -1 ( assuming you’re wanting to stop the flowgraph here?).
Somebody else might chime in here if I’m wrong.

Nathan


NOTE: The information in this email and any attachments may be
confidential and/or legally privileged. This message may be read, copied
and used only by the intended recipient. If you are not the intended
recipient, please destroy this message, delete any copies held on your
system and notify the sender immediately.

Toshiba Research Europe Limited, registered in England and Wales
(2519556). Registered Office 208 Cambridge Science Park, Milton Road,
Cambridge CB4 0GZ, England. Web: www.toshiba.eu/research/trl

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs