echo.py 518 B

123456789101112131415161718192021
  1. #!/usr/bin/python
  2. import zmq
  3. from pydrk import serial
  4. context = zmq.Context()
  5. socket = context.socket(zmq.REQ)
  6. #self.socket.setsockopt(zmq.IPV6, True)
  7. #socket.connect(f"tcp://127.0.0.1:9484")
  8. socket.connect(f"tcp://192.168.1.20:9484")
  9. req_cmd = bytearray()
  10. serial.write_u8(req_cmd, 0)
  11. payload = bytearray()
  12. socket.send_multipart([req_cmd, payload])
  13. errc, reply = socket.recv_multipart()
  14. errc = int.from_bytes(errc, "little")
  15. cursor = serial.Cursor(reply)
  16. response = serial.decode_str(cursor)
  17. print(errc, response)