如何在GNU Radio Python Block中向Debug Block发送PMT字符串
解决GNU Radio Python Block发送字符串到Message Debug Block的问题
GNU Radio的消息系统基于PMT(多态类型)实现,Python字符串需要先转换为PMT兼容类型,再通过已注册的消息端口发送。在你的work函数中添加以下代码即可实现:
test_str = "This is a test" # 将Python字符串转换为PMT符号类型(Message Debug可直接显示) pmt_str = pmt.intern(test_str) # 通过注册的端口发送消息 self.message_port_pub(pmt.intern(self.portName1), pmt_str)
补充说明
pmt.intern()会把Python字符串转为PMT的**符号(symbol)**类型,这是调试场景下最便捷的方式,Message Debug Block能直接解析并显示内容。- 如果需要发送原生字节形式的字符串,也可以用
pmt.string_to_u8vector()转换为字节向量,同样能被Message Debug Block识别:pmt_bytes = pmt.string_to_u8vector(test_str) self.message_port_pub(pmt.intern(self.portName1), pmt_bytes)
内容的提问来源于stack exchange,提问作者SteveJP
相关产品推荐
相关产品推荐

