Hi Jacob,
I'm trying to get the same PMT form as output from a Message_Strobe, i.e. not a pair. See below for what I am expecting. Thanks :) --- Barry Duggan ---- On Thu, 06 Jul 2023 10:43:39 -0500 jacob <jacobgilb...@protonmail.com> wrote --- Hey Barry, PDUs are a specific type of PMT object, PDUs are defined to be a PMT pair of a PMT dictionary and PMT uniform vector. pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff))) The above object generates a PMT pair type object of an empty dictionary (PMT_NIL) and what is hopefully a uniform vector. Using to_pmt() can PMT-ify any type of object and doing so from a weakly typed language is a little risky, I'd use pmt.init_u8vector() or the expected type instead of to_pmt() but the idea is the same. The PMT_NIL, the uniform vector, and the pair are all individually PMT type objects themselves. Is there a particular type of PMT object you are trying to turn the PDUs into? Jacob ------- Original Message ------- On Thursday, July 6th, 2023 at 8:55 AM, Barry Duggan <mailto:ba...@dcsmail.net> wrote: Jeff, Thank you for your corrections. However, based on my debug information, a PMT message as output from a Message_Strobe is: PST_SYMBOL = 0x02 UVI_U8 = 0x00 length of symbols symbol vector whereas a PDU has a form: PST_PAIR PST_NULL PST_UNIFORM_VECTOR etc. Using the string "GNU Radio", a PMT generates: 2 0 9 71 78 85 32 82 97 100 105 111 and a PDU generates: 7 6 10 0 0 0 0 9 1 0 71 78 85 32 82 97 100 105 111 So the construct of `pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))` seems to generate a PDU. What is the construct for a PMT? Thanks! --- Barry Duggan ---- On Thu, 06 Jul 2023 08:03:26 -0500 Jeff Long <mailto:willco...@gmail.com> wrote --- 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 <mailto:ba...@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 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)) 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