using ZMQ with ser2net

85 Views Asked by At

Hi I'm trying to use the hello world example of ZMQ over a serial radio using ser2net. However, when binding to the port it complains "port is already in use", the only other application using that is ser2net which, from my understanding, is providing that port. The client works as expected, its just the server that complains.

How would I configure ser2net over two serial ports say /dev/ttyUSB0 and /dev/ttyUSB1 such that zmq can properly bind to the provided ports. My ser2net.conf file:

localhost,5557:raw:0:/dev/ttyUSB0:57600 8DATABITS NONE 1STOPBIT
localhost,5556:raw:0:/dev/ttyUSB1:57600 8DATABITS NONE 1STOPBIT

The zmq client and server are: server.py

import time
import zmq

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5557")

while True:
    #  Wait for next request from client
    message = socket.recv()
    print(f"Received request: {message}")

    #  Do some 'work'
    time.sleep(1)

    #  Send reply back to client
    socket.send_string("World")

client.py:

import zmq

context = zmq.Context()

#  Socket to talk to server
print("Connecting to hello world server...")
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5556")

#  Do 10 requests, waiting each time for a response
for request in range(10):
    print(f"Sending request {request} ...")
    socket.send_string("Hello")

    #  Get the reply.
    message = socket.recv()
    print(f"Received reply {request} [ {message} ]")

1

There are 1 best solutions below

1
rocklegend On

thanks to @larsks comment. ser2net is not used for this application. Using pppd instead. I also had to use two separate computers for this test as routing was direct if both serial ports were connected to the one computer

pppd configure: Terminal 1:

sudo pppd /dev/ttyUSB0 57600 noauth nodetach  192.168.5.1:192.168.5.2

Terminal 2:

sudo sudo pppd /dev/ttyUSB1 57600 noauth nodetach  192.168.5.2:192.168.5.1

If I run ifconfig these two interfaces show up:

$ ifconfig
ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 192.168.5.2  netmask 255.255.255.255  destination 192.168.5.1
        ppp  txqueuelen 3  (Point-to-Point Protocol)
        RX packets 307  bytes 48004 (48.0 KB)
        RX errors 2  dropped 0  overruns 0  frame 0
        TX packets 308  bytes 49722 (49.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ppp1: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 192.168.5.1  netmask 255.255.255.255  destination 192.168.5.2
        ppp  txqueuelen 3  (Point-to-Point Protocol)
        RX packets 306  bytes 48407 (48.4 KB)
        RX errors 2  dropped 0  overruns 0  frame 0
        TX packets 308  bytes 49722 (49.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

So reconfigure my server and client (just showing the line that changed): Server.py

socket.bind("tcp://192.168.5.2:5557")

client.py

socket.connect("tcp://192.168.5.2:5557")