discuss-gnuradio
[Top][All Lists]
Advanced

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

RE: Re: Selector error - "IndexError: output_index must be < noutputs"


From: Jim Melton
Subject: RE: Re: Selector error - "IndexError: output_index must be < noutputs"
Date: Wed, 6 Sep 2023 17:52:47 +0000

My tool uses XMLRPC integrated from a web page to change the values. That is, a web page displays a control (in a form, but doesn’t matter). When the form is submitted, the back-end makes an XMLRPC call to set the value of the affected parameter. I already had a Python-based web server, so adding a page (with backend) was trivial.

 

In an interactive flowgraph, you can use Qt controls to do the same thing (my first prototype was Qt-based, but I couldn’t deploy Qt). Paul Atreides (muaddib in Matrix chat) is an excellent resource, and helped me a lot.

 

Your embedded python block could also invoke the callbacks, but you need to access the graph-instantiated selector and not create a new one. The key to programmatic access is getting a handle to the object you want to control. Sometimes this means creating delegator functions in your top block (it’s been a while, so I don’t remember what/how GRC exposes create blocks). Another option is a message port.

 

Here is the critical problem:

  • I want to set a select_wave variable used in the output_index of a selector in order to select the appropriate output. I want to set that variable from within another method. How do I do that?

 

From a basic programming perspective, the other method needs to be able to see the object that exposes the variable (either directly or through getter/setter methods). That’s on you. You can inject it (pass the other object to the one that needs to act on it); make it global; or have some other delegation service (an indirect way to do the same thing).

 

There are many ways to skin the cat. I’m sorry I can’t be more helpful, but my GRC-fu is rusty.

---

Jim Melton


Non-Sensitive

 

From: Elmore Family <wa4ywm@comcast.net>
Sent: Wednesday, September 6, 2023 11:34
To: discuss-gnuradio@gnu.org
Subject: [EXTERNAL] Re: Selector error - "IndexError: output_index must be < noutputs"

 

Jim,

 

Thanks for your comments. I think I have been going down the wrong road and need to refocus on using a callback to resolve my issue.

 

I have used callbacks all through my project which have been triggered by an action such as a toggle or a radio button selection. I need to trigger the callback in this case programmatically based on a time value. How do I do this?

 

In your code snippet how do you trigger the set_signal_choice callback from a program?

 

I want to set a select_wave variable used in the output_index of a selector in order to select the appropriate output. I want to set that variable from within another method. How do I do that?

 

Jim

 

From: Jim Melton

Sent: Tuesday, September 5, 2023 1:02 PM

Subject: RE: Re: Selector error - "IndexError: output_index must be < noutputs"

 

In your original,

 

import Receive Receive is a Hier Block which I import in to my Python file

blocks_selector_0 = Receive.blocks.selector(gr.sizeof_float*1,0,0) Instantiation of blocks_selector_0. The Selector block is in the Receive Hier Block.

 

I questioned the syntax. You said “Receive is a Hier Block” but then you do a module operation (not an instance operation), so it wasn’t clear what you are doing.

 

In your simplified example, your graph instantiates a selector, and your embedded python block instantiates a selector. The EPY block doesn’t connect the selector to anything, so selecting an output is very likely to give you an index error.

 

I created a signal generator, where I could mix in different waveforms with an input waveform, and used the selector to control which signal was being mixed in. As with a lot of my stuff, I used GRC for the initial prototype, then make the generated code more production-ready. I have these lines:

 

        self.source_selector = blocks.selector(gr.sizeof_gr_complex*1,signal_choice,0)

        self.source_selector.set_enabled(True)

// …

        self.connect((self.noise_throttle, 0), (self.source_selector, 0))

        self.connect((self, 0), (self.source_selector, 1))

        self.connect((self.source_selector, 0), (self.live_strength, 0))

        self.connect((self.source_selector, 0), (self, 2))

 

In your attached GRC file, you have flowgraph generated connections, but you don’t have any connections to the one created in your EPY block (probably your bug). As Paul suggested, you can use variables and callbacks to control your selector (which might be simpler than the EPY block). My hier block (referenced above) has this:

 

    def set_signal_choice(self, signal_choice):

        self.signal_choice = signal_choice

        self.source_selector.set_input_index(self.signal_choice)

 

and the associated GRC file has:

 

templates:

  imports: from gnuradio import inputs

  make: "inputs.siggen(\n    signal_choice=${ signal_choice },\n)"

  callbacks:

  - set_signal_choice(${ signal_choice })

 

(simplified for illustrative purposes).

 

Hope this helps.

---

Jim Melton


Non-Sensitive

 

From: Elmore's <wa4ywm@comcast.net>
Sent: Friday, September 1, 2023 20:28
To: discuss-gnuradio@gnu.org
Subject: [EXTERNAL] Re: Selector error - "IndexError: output_index must be < noutputs"

 

Jim,

 

I have attached a greatly simplified version of what I am trying to accomplish. I still get the same error. What am I doing wrong?

 

Jim

 

From: Jim Melton

Sent: Monday, August 28, 2023 12:01 PM

Subject: RE: Selector error - "IndexError: output_index must be < noutputs"

 

Don’t you need to instantiate “Receive”?

 

---

Jim Melton


Non-Sensitive

 

From: discuss-gnuradio-bounces+jim.melton=sncorp.com@gnu.org <discuss-gnuradio-bounces+jim.melton=sncorp.com@gnu.org> On Behalf Of Elmore's
Sent: Monday, August 28, 2023 09:15
To: discuss-gnuradio@gnu.org
Subject: [EXTERNAL] Selector error - "IndexError: output_index must be < noutputs"

 

I am attempting to use a Selector block with 2 outputs. I want to select the output programmatically. When I run the flowgraph, I get the subject error.

 

The following is my abbreviated code which is pertinent to the question interspersed with explanatory comments:

 

import Receive Receive is a Hier Block which I import in to my Python file

blocks_selector_0 = Receive.blocks.selector(gr.sizeof_float*1,0,0) Instantiation of blocks_selector_0. The Selector block is in the Receive Hier Block.

 

blocks_selector_0.set_output_index(0) I am trying to select the 0 output. This is where the error occurs.

 

0 is certainly less than 2 so what is happening?

 

Jim

 

 

Image removed by sender.

Virus-free.www.avg.com

 

CONFIDENTIALITY NOTICE - SNC EMAIL: This email and any attachments are confidential, may contain proprietary, protected, or export controlled information, and are intended for the use of the intended recipients only. Any review, reliance, distribution, disclosure, or forwarding of this email and/or attachments outside of Sierra Nevada Corporation (SNC) without express written approval of the sender, except to the extent required to further properly approved SNC business purposes, is strictly prohibited. If you are not the intended recipient of this email, please notify the sender immediately, and delete all copies without reading, printing, or saving in any manner. --- Thank You.


reply via email to

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