GNU无线电ZMQ块代表 - REQ
我正在尝试使用GR ZMQ REP / REQ块将GNU收音机连接到Python脚本。 GR在路由器地址上的Raspberry Pi 4上运行192.168.1.25。 Python脚本位于单独的计算机上,我可以成功地ping 192.168.1.25。我正在在55555和55556的单独端口上设置REQ-REP对。
import pmt
import zmq
# create a REQ socket
req_address = 'tcp://192.168.1.25:55555'
req_context = zmq.Context()
req_sock = req_context.socket (zmq.REQ)
rc = req_sock.connect (req_address)
# create a REP socket
rep_address = 'tcp://192.168.1.25:55556'
rep_context = zmq.Context()
rep_sock = rep_context.socket (zmq.REP)
rc = rep_sock.connect (rep_address)
while True:
data = req_sock.recv()
print(data)
rep_sock.send (b'1')
运行此代码会导致以下错误: ZMQERROR:操作无法在当前状态下完成
该错误在此行上标记: data = req_sock.recv()
您可以评论错误原因吗?我知道有一个严格的req-rep,req-rep ..关系,但是我找不到我的错误。
I am trying to connect GNU Radio to a python script using the GR ZMQ REP / REQ blocks. GR is running on a Raspberry Pi 4 on router address 192.168.1.25. The python script is on a separate computer, from which I can successfully ping 192.168.1.25. I am setting up the REQ-REP pairs on separate ports, 55555 and 55556.
import pmt
import zmq
# create a REQ socket
req_address = 'tcp://192.168.1.25:55555'
req_context = zmq.Context()
req_sock = req_context.socket (zmq.REQ)
rc = req_sock.connect (req_address)
# create a REP socket
rep_address = 'tcp://192.168.1.25:55556'
rep_context = zmq.Context()
rep_sock = rep_context.socket (zmq.REP)
rc = rep_sock.connect (rep_address)
while True:
data = req_sock.recv()
print(data)
rep_sock.send (b'1')
Running this code leads to the following error:
ZMQError: Operation cannot be accomplished in current state
The error is flagged at this line:
data = req_sock.recv()
Can you comment on the cause of the error? I know there is a strict REQ-REP, REQ-REP.. relationship, but I cannot find my error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前的代码有两个问题:
您调用
req_socket.recv()
,但随后您调用rep_sock.send()
:这不是Req/Rep Pair作品。您只需要创建一个套接字(req套接字);它连接到遥控插座。创建REQ套接字时,您需要在收到答复之前发送请求。
此外,即使您有多个插座,也只能创建一个ZMQ上下文。
您的代码的功能版本可能是这样的:
我针对以下GNU无线电配置测试了上述代码:
Your current code has two problems:
You call
req_socket.recv()
, but then you callrep_sock.send()
: that's not how a REQ/REP pair works. You only need to create one socket (the REQ socket); it connects to a remote REP socket.When you create a REQ socket, you need to send a REQuest before you receive a REPly.
Additionally, you should only create a single ZMQ context, even if you have multiple sockets.
A functional version of your code might look like this:
I tested the above code against the following GNU Radio config: