|
From: | Barry Duggan |
Subject: | Re: Convert PDU message to a PMT message |
Date: | Thu, 06 Jul 2023 09:55:27 -0500 |
User-agent: | Zoho Mail |
b_len is defined in the try block, and is out of scope by the time it is checked below.This code should work. The routine returns in the except clause and b_len is set after the try/except.import numpy as np
from gnuradio import gr
import pmt
import array
class blk(gr.sync_block):
def __init__(self):
gr.sync_block.__init__(
self,
name='EPB: Packet to PMT', # will show up in GRC
in_sig=None,
out_sig=None)
self.message_port_register_in(pmt.intern('msg_in'))
self.message_port_register_out(pmt.intern('msg_out'))
self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg)
def handle_msg(self, msg):
_debug = 0 # set to zero to turn off diagnostics
try:
buff = pmt.to_python(pmt.cdr(msg))
except Exception as e:
gr.log.error("Error with message conversion: %s" % str(e))
return
b_len = len (buff)
if (_debug):
print ("new_val =", buff, b_len)
if (b_len != 52):
self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))
elif ((buff[0] != 37) and (buff[51] != 93)):
self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))On Wed, Jul 5, 2023 at 6:11 PM Barry Duggan <barry@dcsmail.net> wrote:I would like to receive a PDU message containing a string using an Embedded Python Block and, after discarding certain messages, send a PMT message with that string to the output message port. My efforts so far have not produced a valid PMT format. My current code is:```import numpy as npfrom gnuradio import grimport pmtimport arrayclass blk(gr.sync_block):def __init__(self):gr.sync_block.__init__(self,name='EPB: Packet to PMT', # will show up in GRCin_sig=None,out_sig=None)self.message_port_register_in(pmt.intern('msg_in'))self.message_port_register_out(pmt.intern('msg_out'))self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg)def handle_msg(self, msg):_debug = 0 # set to zero to turn off diagnosticstry:buff = pmt.to_python(pmt.cdr(msg))b_len = len (buff)except Exception as e:gr.log.error("Error with message conversion: %s" % str(e))if (_debug):print ("new_val =", buff, b_len)if (b_len != 52):self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))elif ((buff[0] != 37) and (buff[51] != 93)):self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))```Any help will be appreciated!---Barry Duggan
[Prev in Thread] | Current Thread | [Next in Thread] |