1

I'm currently trying to send data from a python code to a GNUradio SUB Message block but I've an issue. I think I don't configure correctly my socket or my data must be preambled but I don't find any solutions from the web.

Here is my GNUradio blocks : GNUradio block

Here is my python code which generates an error :

import zmq
import time

ctx = zmq.Context()
socket = ctx.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:4444")

tab = [0xFF] * 256
tab = bytes(tab)
print("Starting loop...")
while True:
   socket.send(tab)
   time.sleep(5)

Here is my GNUradio error :

**Generating: '/home/X/test.py'
Executing: /usr/bin/python3 -u /home/X/test.py
Warning: failed to XInitThreads()
terminate called after throwing an instance of 'pmt::exception'
  what():  pmt::deserialize: malformed input stream, tag value = : 255
Done (return code -6)** 

  

If I try with this python code :

import zmq
import time

ctx = zmq.Context()
socket = ctx.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:4444")

tab = [0x00] * 256
tab = bytes(tab)
print("Starting loop...")
while True:
   socket.send(tab)
   time.sleep(5)

I've got this result on GNUradio :

**Generating: '/home/X/test.py' 
Executing: /usr/bin/python3 -u /home/X/test.py 
Warning: failed to XInitThreads()
******* MESSAGE DEBUG PRINT ********
#t
********************************************

I'm also seeing different result if I change tab = [0x00] * 256 to tab = [0x01] * 256 :

Generating: '/home/X/test.py'
Executing: /usr/bin/python3 -u /home/X/test.py
Warning: failed to XInitThreads()
******* MESSAGE DEBUG PRINT ********
#f
************************************ 

Can someone help me with this please?

Thanks a lot !

Edit :

With the advice of darth baba with this code it works properly :

import zmq
import time
import pmt

ctx = zmq.Context()
socket = ctx.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:4444")

tab = [0xFF] * 256
print("Starting loop...")
while True:
   socket.send (pmt.serialize_str(pmt.to_pmt(tab)))
   time.sleep(5)

I've got this result on GNUradio :

Generating: '/home/X/test.py'

Executing: /usr/bin/python3 -u /home/X/test.py

Warning: failed to XInitThreads()
******* MESSAGE DEBUG PRINT ********
#(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
************************************
babylone
  • 11
  • 3
  • what is the error please post the complete stacktrace? and don't post pictures of your code please read How to ask questions on StackOverflow. https://stackoverflow.com/help/how-to-ask – darth baba Sep 20 '21 at 10:16
  • Thanks for the advice, I've reedited the question. – babylone Sep 20 '21 at 14:47
  • try sending string tab (dont convert it to bytes) with: ```import pmt sock.send (pmt.serialize_str(pmt.to_pmt(tab)))``` – darth baba Sep 20 '21 at 19:04
  • 1
    Thank you dart baba it works properly i've reedited the question with the solution. Thanks a lot ! – babylone Sep 21 '21 at 07:06
  • Thanks @babylone! For future reference, feel free to "answer" your own question. That way, people can easily see the answer separated from the question. :-) – pianoJames May 27 '22 at 19:57

0 Answers0