discuss-gnuradio
[Top][All Lists]
Advanced

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

Stream Tag in Embedded Python Blocks


From: Solomon Tan
Subject: Stream Tag in Embedded Python Blocks
Date: Sun, 9 May 2021 16:06:08 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

Dear all,

I was following the GRC Wiki tutorial on Stream Tags. In the example
flowgraph, stream tags were added to the example QPSK de-modulator
using Python code. I was unable to replicate the behavior in an embedded
python block. How do I tell what port number to add the stream tag to?
How do I use `add_item_tag` with an embedded python block?


```
self.add_item_tag(0, # Port number
                 self.nitems_written(0) + i, # Offset
                 pmt.intern("amplitude_recovered"), # Key
                 pmt.PMT_T # Value
    )
```

My entire `work` function code is shown below. It just creates a tag
whenever the input signal magnitude falls below 0.01, and when it rises
again above 0.01.

```
def work(self, input_items, output_items):
    for i in range(0, len(input_items[0])):
        if abs(input_items[0][i]) < 0.01 and not self.d_low_ampl_state:
            self.add_item_tag(0,self.nitems_written(0)+i,
                         pmt.intern("amplitude_warning"),

                         pmt.from_double(
                             numpy.double(abs(input_items[0][i]))
                         )
            )
            self.d_low_ampl_state = True
        elif abs(input_items[0][i]) >= 0.01 and self.d_low_ampl_state:
            self.add_item_tag(0,self.nitems_written(0)+i,
pmt.intern("amplitude_recovered"),
pmt.from_double(numpy.double(abs(input_items[0][i]))))
            self.d_low_ampl_state = False
        output_items[0][:] = abs(input_items[0])
        return len(output_items[0])

```

Indentation is edited to fit the 72 char limit. The error I got was a
runtime error (ie return -6). There was no error if I commented out the
`add_item_tag` function calls.

Thank you.
Cheers,
Sol


reply via email to

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