11 # GNU General Public License for more details. |
11 # GNU General Public License for more details. |
12 # |
12 # |
13 # You should have received a copy of the GNU General Public License |
13 # You should have received a copy of the GNU General Public License |
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>. |
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>. |
15 |
15 |
16 from SimpleXMLRPCServer import SimpleXMLRPCServer |
16 from xmlrpc.server import SimpleXMLRPCServer |
17 from threading import Thread |
17 from threading import Thread |
18 import socket |
18 import socket |
19 import logging |
19 import logging |
20 |
20 |
21 from .utils import install_locale, parse_temperature_report |
21 from .utils import install_locale, parse_temperature_report |
22 install_locale('pronterface') |
22 install_locale('pronterface') |
23 |
23 |
24 RPC_PORT = 7978 |
24 RPC_PORT = 7978 |
25 |
25 |
26 class ProntRPC(object): |
26 class ProntRPC: |
27 |
27 |
28 server = None |
28 server = None |
29 |
29 |
30 def __init__(self, pronsole, port = RPC_PORT): |
30 def __init__(self, pronsole, port = RPC_PORT): |
31 self.pronsole = pronsole |
31 self.pronsole = pronsole |
43 used_port += 1 |
43 used_port += 1 |
44 continue |
44 continue |
45 else: |
45 else: |
46 raise |
46 raise |
47 self.server.register_function(self.get_status, 'status') |
47 self.server.register_function(self.get_status, 'status') |
|
48 self.server.register_function(self.set_extruder_temperature,'settemp') |
|
49 self.server.register_function(self.set_bed_temperature,'setbedtemp') |
|
50 self.server.register_function(self.load_file,'load_file') |
|
51 self.server.register_function(self.startprint,'startprint') |
|
52 self.server.register_function(self.pauseprint,'pauseprint') |
|
53 self.server.register_function(self.resumeprint,'resumeprint') |
|
54 self.server.register_function(self.sendhome,'sendhome') |
|
55 self.server.register_function(self.connect,'connect') |
|
56 self.server.register_function(self.disconnect, 'disconnect') |
|
57 self.server.register_function(self.send, 'send') |
48 self.thread = Thread(target = self.run_server) |
58 self.thread = Thread(target = self.run_server) |
49 self.thread.start() |
59 self.thread.start() |
50 |
60 |
51 def run_server(self): |
61 def run_server(self): |
52 self.server.serve_forever() |
62 self.server.serve_forever() |
74 "progress": progress, |
84 "progress": progress, |
75 "eta": eta, |
85 "eta": eta, |
76 "temps": temps, |
86 "temps": temps, |
77 "z": z, |
87 "z": z, |
78 } |
88 } |
|
89 def set_extruder_temperature(self, targettemp): |
|
90 if self.pronsole.p.online: |
|
91 self.pronsole.p.send_now("M104 S" + targettemp) |
|
92 |
|
93 def set_bed_temperature(self,targettemp): |
|
94 if self.pronsole.p.online: |
|
95 self.pronsole.p.send_now("M140 S" + targettemp) |
|
96 |
|
97 def load_file(self,filename): |
|
98 self.pronsole.do_load(filename) |
|
99 |
|
100 def startprint(self): |
|
101 self.pronsole.do_print("") |
|
102 |
|
103 def pauseprint(self): |
|
104 self.pronsole.do_pause("") |
|
105 |
|
106 def resumeprint(self): |
|
107 self.pronsole.do_resume("") |
|
108 def sendhome(self): |
|
109 self.pronsole.do_home("") |
|
110 def connect(self): |
|
111 self.pronsole.do_connect("") |
|
112 def disconnect(self): |
|
113 self.pronsole.do_disconnect("") |
|
114 def send(self, command): |
|
115 self.pronsole.p.send_now(command) |