Files
wallter/SOFTWARE/plotter-app/websocket_test.py
2024-11-20 16:39:17 +01:00

25 lines
718 B
Python

import threading, websocket, time
ws = websocket.WebSocket()
ws.connect("ws://192.168.0.1:81")
# Reception needs to be done in a separate thread; you cannot
# assume that a given command will always result in exactly one
# response at a predictable time
# def receiver():
# while True:
# for l in ws.recv().splitlines():
# if isinstance(l, str):
# print(l)
# else:
# print(str(l, 'utf-8'))
# t = threading.Thread(target=receiver)
# t.start()
# ws.send("?") # realtime characters need no line terminator
# ws.send("$/axes/x\n") # line-oriented commands need \n at the end
ws.send("\r\n\r\n")
print(ws.recv())
ws.send("G0 X10\n")
print(ws.recv())