Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
c942bc6e
Commit
c942bc6e
authored
Jun 11, 2013
by
D1plo1d
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring pronsole logging so that prontserve can send useful errors over websockets
parent
03295e11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
58 deletions
+67
-58
pronsole.py
pronsole.py
+57
-54
prontserve.py
prontserve.py
+10
-4
No files found.
pronsole.py
View file @
c942bc6e
...
...
@@ -390,6 +390,9 @@ class pronsole(cmd.Cmd):
def
log
(
self
,
*
msg
):
print
u""
.
join
(
unicode
(
i
)
for
i
in
msg
)
def
logError
(
self
,
*
msg
):
print
u""
.
join
(
unicode
(
i
)
for
i
in
msg
)
def
promptf
(
self
):
"""A function to generate prompts so that we can do dynamic prompts. """
if
self
.
in_macro
:
...
...
@@ -517,7 +520,7 @@ class pronsole(cmd.Cmd):
macro_def
+=
self
.
cur_macro_def
self
.
save_in_rc
(
macro_key
,
macro_def
)
else
:
self
.
log
(
"Empty macro - cancelled"
)
self
.
log
Error
(
"Empty macro - cancelled"
)
del
self
.
cur_macro_name
,
self
.
cur_macro_def
def
parseusercmd
(
self
,
line
):
...
...
@@ -536,7 +539,7 @@ class pronsole(cmd.Cmd):
def
compile_macro
(
self
,
macro_name
,
macro_def
):
if
macro_def
.
strip
()
==
""
:
self
.
log
(
"Empty macro - cancelled"
)
self
.
log
Error
(
"Empty macro - cancelled"
)
return
pycode
=
"def macro(self,*arg):
\n
"
if
"
\n
"
not
in
macro_def
.
strip
():
...
...
@@ -550,7 +553,7 @@ class pronsole(cmd.Cmd):
def
start_macro
(
self
,
macro_name
,
prev_definition
=
""
,
suppress_instructions
=
False
):
if
not
self
.
processing_rc
and
not
suppress_instructions
:
self
.
log
(
"Enter macro using indented lines, end with empty line"
)
self
.
log
Error
(
"Enter macro using indented lines, end with empty line"
)
self
.
cur_macro_name
=
macro_name
self
.
cur_macro_def
=
""
self
.
onecmd
=
self
.
hook_macro
# override onecmd temporarily
...
...
@@ -565,7 +568,7 @@ class pronsole(cmd.Cmd):
if
not
self
.
processing_rc
and
not
self
.
processing_args
:
self
.
save_in_rc
(
"macro "
+
macro_name
,
""
)
else
:
self
.
log
(
"Macro '"
+
macro_name
+
"' is not defined"
)
self
.
log
Error
(
"Macro '"
+
macro_name
+
"' is not defined"
)
def
do_macro
(
self
,
args
):
if
args
.
strip
()
==
""
:
self
.
print_topics
(
"User-defined macros"
,
self
.
macros
.
keys
(),
15
,
80
)
...
...
@@ -573,7 +576,7 @@ class pronsole(cmd.Cmd):
arglist
=
args
.
split
(
None
,
1
)
macro_name
=
arglist
[
0
]
if
macro_name
not
in
self
.
macros
and
hasattr
(
self
.
__class__
,
"do_"
+
macro_name
):
self
.
log
(
"Name '"
+
macro_name
+
"' is being used by built-in command"
)
self
.
log
Error
(
"Name '"
+
macro_name
+
"' is being used by built-in command"
)
return
if
len
(
arglist
)
==
2
:
macro_def
=
arglist
[
1
]
...
...
@@ -610,7 +613,7 @@ class pronsole(cmd.Cmd):
else
:
self
.
log
(
"Macro '"
+
macro_name
+
"' defined as: '"
+
macro_def
+
"'"
)
else
:
self
.
log
(
"Macro '"
+
macro_name
+
"' is not defined"
)
self
.
log
Error
(
"Macro '"
+
macro_name
+
"' is not defined"
)
def
set
(
self
,
var
,
str
):
try
:
...
...
@@ -619,9 +622,9 @@ class pronsole(cmd.Cmd):
if
not
self
.
processing_rc
and
not
self
.
processing_args
:
self
.
save_in_rc
(
"set "
+
var
,
"set
%
s
%
s"
%
(
var
,
value
))
except
AttributeError
:
self
.
log
(
"Unknown variable '
%
s'"
%
var
)
self
.
log
Error
(
"Unknown variable '
%
s'"
%
var
)
except
ValueError
,
ve
:
self
.
log
(
"Bad value for variable '
%
s', expecting
%
s (
%
s)"
%
(
var
,
repr
(
t
)[
1
:
-
1
],
ve
.
args
[
0
]))
self
.
log
Error
(
"Bad value for variable '
%
s', expecting
%
s (
%
s)"
%
(
var
,
repr
(
t
)[
1
:
-
1
],
ve
.
args
[
0
]))
def
do_set
(
self
,
argl
):
args
=
argl
.
split
(
None
,
1
)
...
...
@@ -634,7 +637,7 @@ class pronsole(cmd.Cmd):
try
:
self
.
log
(
"
%
s =
%
s"
%
(
args
[
0
],
getattr
(
self
.
settings
,
args
[
0
])))
except
AttributeError
:
self
.
log
(
"Unknown variable '
%
s'"
%
args
[
0
])
self
.
log
Error
(
"Unknown variable '
%
s'"
%
args
[
0
])
return
self
.
set
(
args
[
0
],
args
[
1
])
...
...
@@ -729,7 +732,7 @@ class pronsole(cmd.Cmd):
#else:
# self.log("Removed '"+key+"' from '"+self.rc_filename+"'")
except
Exception
,
e
:
self
.
log
(
"Saving failed for "
,
key
+
":"
,
str
(
e
))
self
.
log
Error
(
"Saving failed for "
,
key
+
":"
,
str
(
e
))
finally
:
del
rci
,
rco
...
...
@@ -794,11 +797,11 @@ class pronsole(cmd.Cmd):
def
_do_load
(
self
,
filename
):
if
not
filename
:
self
.
log
(
"No file name given."
)
self
.
log
Error
(
"No file name given."
)
return
self
.
log
(
"Loading file: "
+
filename
)
self
.
log
Error
(
"Loading file: "
+
filename
)
if
not
os
.
path
.
exists
(
filename
):
self
.
log
(
"File not found!"
)
self
.
log
Error
(
"File not found!"
)
return
self
.
fgcode
=
gcoder
.
GCode
(
open
(
filename
))
self
.
filename
=
filename
...
...
@@ -823,10 +826,10 @@ class pronsole(cmd.Cmd):
filename
=
names
[
0
]
targetname
=
names
[
1
]
else
:
self
.
log
(
_
(
"Please enter target name in 8.3 format."
))
self
.
log
Error
(
_
(
"Please enter target name in 8.3 format."
))
return
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Not connected to printer."
))
self
.
log
Error
(
_
(
"Not connected to printer."
))
return
self
.
_do_load
(
filename
)
self
.
log
(
_
(
"Uploading as
%
s"
)
%
targetname
)
...
...
@@ -850,13 +853,13 @@ class pronsole(cmd.Cmd):
self
.
log
(
_
(
"Upload completed.
%
s should now be on the card."
)
%
targetname
)
return
except
:
self
.
log
(
_
(
"...interrupted!"
))
self
.
log
Error
(
_
(
"...interrupted!"
))
self
.
p
.
pause
()
self
.
p
.
send_now
(
"M29 "
+
targetname
)
time
.
sleep
(
0.2
)
self
.
p
.
clear
=
1
self
.
p
.
startprint
(
None
)
self
.
log
(
_
(
"A partial file named
%
s may have been written to the sd card."
)
%
targetname
)
self
.
log
Error
(
_
(
"A partial file named
%
s may have been written to the sd card."
)
%
targetname
)
def
complete_upload
(
self
,
text
,
line
,
begidx
,
endidx
):
s
=
line
.
split
()
...
...
@@ -879,10 +882,10 @@ class pronsole(cmd.Cmd):
def
do_print
(
self
,
l
):
if
not
self
.
fgcode
:
self
.
log
(
_
(
"No file loaded. Please use load first."
))
self
.
log
Error
(
_
(
"No file loaded. Please use load first."
))
return
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Not connected to printer."
))
self
.
log
Error
(
_
(
"Not connected to printer."
))
return
self
.
log
(
_
(
"Printing
%
s"
)
%
self
.
filename
)
self
.
log
(
_
(
"You can monitor the print with the monitor command."
))
...
...
@@ -893,7 +896,7 @@ class pronsole(cmd.Cmd):
self
.
p
.
send_now
(
"M25"
)
else
:
if
not
self
.
p
.
printing
:
self
.
log
(
_
(
"Not printing, cannot pause."
))
self
.
log
Error
(
_
(
"Not printing, cannot pause."
))
return
self
.
p
.
pause
()
self
.
paused
=
True
...
...
@@ -903,7 +906,7 @@ class pronsole(cmd.Cmd):
def
do_resume
(
self
,
l
):
if
not
self
.
paused
:
self
.
log
(
_
(
"Not paused, unable to resume. Start a print first."
))
self
.
log
Error
(
_
(
"Not paused, unable to resume. Start a print first."
))
return
self
.
paused
=
False
if
self
.
sdprinting
:
...
...
@@ -942,7 +945,7 @@ class pronsole(cmd.Cmd):
def
do_ls
(
self
,
l
):
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Printer is not online. Please connect to it first."
))
self
.
log
Error
(
_
(
"Printer is not online. Please connect to it first."
))
return
self
.
_do_ls
(
True
)
...
...
@@ -951,7 +954,7 @@ class pronsole(cmd.Cmd):
def
waitforsdresponse
(
self
,
l
):
if
"file.open failed"
in
l
:
self
.
log
(
_
(
"Opening file failed."
))
self
.
log
Error
(
_
(
"Opening file failed."
))
self
.
recvlisteners
.
remove
(
self
.
waitforsdresponse
)
return
if
"File opened"
in
l
:
...
...
@@ -1035,7 +1038,7 @@ class pronsole(cmd.Cmd):
self
.
log
(
"SENDING:"
+
l
)
self
.
p
.
send_now
(
l
)
else
:
self
.
log
(
_
(
"Printer is not online."
))
self
.
log
Error
(
_
(
"Printer is not online."
))
return
elif
l
[
0
]
in
self
.
commandprefixes
.
lower
():
if
self
.
p
and
self
.
p
.
online
:
...
...
@@ -1043,7 +1046,7 @@ class pronsole(cmd.Cmd):
self
.
log
(
"SENDING:"
+
l
.
upper
())
self
.
p
.
send_now
(
l
.
upper
())
else
:
self
.
log
(
_
(
"Printer is not online."
))
self
.
log
Error
(
_
(
"Printer is not online."
))
return
elif
l
[
0
]
==
"@"
:
if
self
.
p
and
self
.
p
.
online
:
...
...
@@ -1051,7 +1054,7 @@ class pronsole(cmd.Cmd):
self
.
log
(
"SENDING:"
+
l
[
1
:])
self
.
p
.
send_now
(
l
[
1
:])
else
:
self
.
log
(
"printer is not online."
)
self
.
log
Error
(
"printer is not online."
)
return
else
:
cmd
.
Cmd
.
default
(
self
,
l
)
...
...
@@ -1093,11 +1096,11 @@ class pronsole(cmd.Cmd):
self
.
p
.
send_now
(
"M104 S"
+
l
)
self
.
log
(
_
(
"Setting hotend temperature to
%
s degrees Celsius."
)
%
f
)
else
:
self
.
log
(
_
(
"Printer is not online."
))
self
.
log
Error
(
_
(
"Printer is not online."
))
else
:
self
.
log
(
_
(
"You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0."
))
self
.
log
Error
(
_
(
"You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0."
))
except
:
self
.
log
(
_
(
"You must enter a temperature."
))
self
.
log
Error
(
_
(
"You must enter a temperature."
))
def
help_settemp
(
self
):
self
.
log
(
_
(
"Sets the hotend temperature to the value entered."
))
...
...
@@ -1117,13 +1120,13 @@ class pronsole(cmd.Cmd):
if
f
>=
0
:
if
self
.
p
.
online
:
self
.
p
.
send_now
(
"M140 S"
+
l
)
self
.
log
(
_
(
"Setting bed temperature to
%
s degrees Celsius."
)
%
f
)
self
.
log
Error
(
_
(
"Setting bed temperature to
%
s degrees Celsius."
)
%
f
)
else
:
self
.
log
(
_
(
"Printer is not online."
))
self
.
log
Error
(
_
(
"Printer is not online."
))
else
:
self
.
log
(
_
(
"You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0."
))
self
.
log
Error
(
_
(
"You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0."
))
except
:
self
.
log
(
_
(
"You must enter a temperature."
))
self
.
log
Error
(
_
(
"You must enter a temperature."
))
def
help_bedtemp
(
self
):
self
.
log
(
_
(
"Sets the bed temperature to the value entered."
))
...
...
@@ -1136,13 +1139,13 @@ class pronsole(cmd.Cmd):
def
do_move
(
self
,
l
):
if
(
len
(
l
.
split
())
<
2
):
self
.
log
(
_
(
"No move specified."
))
self
.
log
Error
(
_
(
"No move specified."
))
return
if
self
.
p
.
printing
:
self
.
log
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
self
.
log
Error
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
return
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Printer is not online. Unable to move."
))
self
.
log
Error
(
_
(
"Printer is not online. Unable to move."
))
return
l
=
l
.
split
()
if
(
l
[
0
]
.
lower
()
==
"x"
):
...
...
@@ -1158,13 +1161,13 @@ class pronsole(cmd.Cmd):
feed
=
self
.
settings
.
e_feedrate
axis
=
"E"
else
:
self
.
log
(
_
(
"Unknown axis."
))
self
.
log
Error
(
_
(
"Unknown axis."
))
return
dist
=
0
try
:
dist
=
float
(
l
[
1
])
except
:
self
.
log
(
_
(
"Invalid distance"
))
self
.
log
Error
(
_
(
"Invalid distance"
))
return
try
:
feed
=
int
(
l
[
2
])
...
...
@@ -1199,22 +1202,22 @@ class pronsole(cmd.Cmd):
length
=
5
#default extrusion length
feed
=
self
.
settings
.
e_feedrate
#default speed
if
not
self
.
p
.
online
:
self
.
log
(
"Printer is not online. Unable to extrude."
)
self
.
log
Error
(
"Printer is not online. Unable to extrude."
)
return
if
self
.
p
.
printing
:
self
.
log
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
self
.
log
Error
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
return
ls
=
l
.
split
()
if
len
(
ls
):
try
:
length
=
float
(
ls
[
0
])
except
:
self
.
log
(
_
(
"Invalid length given."
))
self
.
log
Error
(
_
(
"Invalid length given."
))
if
len
(
ls
)
>
1
:
try
:
feed
=
int
(
ls
[
1
])
except
:
self
.
log
(
_
(
"Invalid speed given."
))
self
.
log
Error
(
_
(
"Invalid speed given."
))
if
override
is
not
None
:
length
=
override
feed
=
overridefeed
...
...
@@ -1239,22 +1242,22 @@ class pronsole(cmd.Cmd):
length
=
5
#default extrusion length
feed
=
self
.
settings
.
e_feedrate
#default speed
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Printer is not online. Unable to reverse."
))
self
.
log
Error
(
_
(
"Printer is not online. Unable to reverse."
))
return
if
self
.
p
.
printing
:
self
.
log
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
self
.
log
Error
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
return
ls
=
l
.
split
()
if
len
(
ls
):
try
:
length
=
float
(
ls
[
0
])
except
:
self
.
log
(
_
(
"Invalid length given."
))
self
.
log
Error
(
_
(
"Invalid length given."
))
if
len
(
ls
)
>
1
:
try
:
feed
=
int
(
ls
[
1
])
except
:
self
.
log
(
_
(
"Invalid speed given."
))
self
.
log
Error
(
_
(
"Invalid speed given."
))
self
.
do_extrude
(
""
,
length
*-
1.0
,
feed
)
def
help_reverse
(
self
):
...
...
@@ -1288,17 +1291,17 @@ class pronsole(cmd.Cmd):
def
do_monitor
(
self
,
l
):
interval
=
5
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Printer is not online. Please connect to it first."
))
self
.
log
Error
(
_
(
"Printer is not online. Please connect to it first."
))
return
if
not
(
self
.
p
.
printing
or
self
.
sdprinting
):
self
.
log
(
_
(
"Printer is not printing. Please print something before monitoring."
))
self
.
log
Error
(
_
(
"Printer is not printing. Please print something before monitoring."
))
return
self
.
log
(
_
(
"Monitoring printer, use ^C to interrupt."
))
if
len
(
l
):
try
:
interval
=
float
(
l
)
except
:
self
.
log
(
_
(
"Invalid period given."
))
self
.
log
Error
(
_
(
"Invalid period given."
))
self
.
log
(
_
(
"Updating values every
%
f seconds."
)
%
(
interval
,))
self
.
monitoring
=
1
prev_msg_len
=
0
...
...
@@ -1336,7 +1339,7 @@ class pronsole(cmd.Cmd):
def
do_skein
(
self
,
l
):
l
=
l
.
split
()
if
len
(
l
)
==
0
:
self
.
log
(
_
(
"No file name given."
))
self
.
log
Error
(
_
(
"No file name given."
))
return
settings
=
0
if
(
l
[
0
]
==
"set"
):
...
...
@@ -1344,7 +1347,7 @@ class pronsole(cmd.Cmd):
else
:
self
.
log
(
_
(
"Skeining file:
%
s"
)
%
l
[
0
])
if
not
(
os
.
path
.
exists
(
l
[
0
])):
self
.
log
(
_
(
"File not found!"
))
self
.
log
Error
(
_
(
"File not found!"
))
return
try
:
if
settings
:
...
...
@@ -1359,7 +1362,7 @@ class pronsole(cmd.Cmd):
self
.
log
(
_
(
"Loading sliced file."
))
self
.
do_load
(
l
[
0
]
.
replace
(
".stl"
,
"_export.gcode"
))
except
Exception
,
e
:
self
.
log
(
_
(
"Skeinforge execution failed:
%
s"
)
%
e
)
self
.
log
Error
(
_
(
"Skeinforge execution failed:
%
s"
)
%
e
)
def
complete_skein
(
self
,
text
,
line
,
begidx
,
endidx
):
s
=
line
.
split
()
...
...
@@ -1379,10 +1382,10 @@ class pronsole(cmd.Cmd):
def
do_home
(
self
,
l
):
if
not
self
.
p
.
online
:
self
.
log
(
_
(
"Printer is not online. Unable to move."
))
self
.
log
Error
(
_
(
"Printer is not online. Unable to move."
))
return
if
self
.
p
.
printing
:
self
.
log
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
self
.
log
Error
(
_
(
"Printer is currently printing. Please pause the print before you issue manual commands."
))
return
if
"x"
in
l
.
lower
():
self
.
p
.
send_now
(
"G28 X0"
)
...
...
prontserve.py
View file @
c942bc6e
...
...
@@ -196,11 +196,10 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
try
:
if
cmd
==
"set"
:
cmd
=
"construct_set"
response
=
getattr
(
prontserve
,
"do_
%
s"
%
cmd
)(
*
args
,
**
kwargs
)
print
response
if
response
is
not
None
:
self
.
write_message
(
response
)
except
:
self
.
write_message
({
"ack"
:
response
})
except
Exception
as
ex
:
print
traceback
.
format_exc
()
self
.
write_message
({
"error"
:
"bad command."
})
self
.
write_message
({
"error"
:
str
(
ex
)
})
else
:
self
.
write_message
({
"error"
:
"
%
s command does not exist."
%
cmd
})
...
...
@@ -253,6 +252,7 @@ class EventEmitter(object):
class
Prontserve
(
pronsole
.
pronsole
,
EventEmitter
):
def
__init__
(
self
,
**
kwargs
):
self
.
initializing
=
True
pronsole
.
pronsole
.
__init__
(
self
)
EventEmitter
.
__init__
(
self
)
self
.
settings
.
sensor_names
=
{
'T'
:
'extruder'
,
'B'
:
'bed'
}
...
...
@@ -273,6 +273,7 @@ class Prontserve(pronsole.pronsole, EventEmitter):
self
.
_sensor_update_received
=
True
self
.
init_mdns
()
self
.
jobs
.
listeners
.
add
(
self
)
self
.
initializing
=
False
def
init_mdns
(
self
):
sdRef
=
pybonjour
.
DNSServiceRegister
(
name
=
None
,
...
...
@@ -458,6 +459,11 @@ class Prontserve(pronsole.pronsole, EventEmitter):
print
msg
self
.
fire
(
"log"
,
{
'msg'
:
msg
,
'level'
:
"debug"
})
def
logError
(
self
,
*
msg
):
print
u""
.
join
(
unicode
(
i
)
for
i
in
msg
)
if
self
.
initializing
==
False
:
raise
Exception
(
u""
.
join
(
unicode
(
i
)
for
i
in
msg
))
def
write_prompt
(
self
):
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment