sendCommand.py 613 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. # tool to send commands to the FPGC
  3. # eg: echo "clear" | python3 sendCommand.py
  4. import socket
  5. import sys
  6. from time import sleep
  7. data = sys.stdin.read()
  8. if len(data) == 0:
  9. print("Empty data")
  10. exit(1)
  11. # init connection
  12. s = socket.socket()
  13. port = 3222
  14. for idx, attempt in enumerate(range(10)):
  15. try:
  16. s.connect(("192.168.0.213", port))
  17. bdata = data.encode()
  18. s.send(bdata)
  19. s.recv(len(bdata))
  20. except:
  21. sleep(0.1)
  22. else:
  23. break
  24. if idx == 9:
  25. print("ERROR: could not send", data)
  26. # close socket when done
  27. s.close()