printrun-src/testtools/mock-printer.py

Tue, 19 Jan 2021 20:45:09 +0100

author
mdd
date
Tue, 19 Jan 2021 20:45:09 +0100
changeset 45
c82943fb205f
permissions
-rwxr-xr-x

updated main files to new github master version

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

mercurial