printrun-src/testtools/mock-printer.py

changeset 45
c82943fb205f
equal deleted inserted replaced
44:310be640a303 45:c82943fb205f
1 #!/usr/bin/env python3
2 # Test network communication without networked 3d printer
3 # Usage:
4 # bash1$ ./mock-printer.py
5 # bash2$ ./pronsole
6 # pronsole> connect localhost:8080
7 # ...> load sliced.gcode
8 # ...> print
9 # ...> etc...
10 import socket
11 with socket.socket() as s:
12 s.bind(('127.0.0.1', 8080))
13 s.listen(1)
14 c, addr = s.accept()
15 print(c)
16 temp = 0
17 try:
18 c.sendall(b'start\n')
19 while True:
20 msg = c.recv(1024)
21 if not msg:
22 break
23 print(msg)
24 if msg == b'M105\n':
25 c.sendall(('ok T:%d\n'%(20 + temp)).encode('ascii'))
26 temp = (temp + 1)%30
27 else:
28 c.sendall(b'ok\n')
29 finally:
30 c.close()

mercurial