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
585bad62
Commit
585bad62
authored
Oct 10, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log errors using errorcb in printcore
parent
8002d268
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
21 deletions
+25
-21
printcore.py
printrun/printcore.py
+25
-21
No files found.
printrun/printcore.py
View file @
585bad62
...
@@ -107,6 +107,13 @@ class printcore():
...
@@ -107,6 +107,13 @@ class printcore():
self
.
z_feedrate
=
None
self
.
z_feedrate
=
None
self
.
pronterface
=
None
self
.
pronterface
=
None
def
logError
(
self
,
error
):
if
self
.
errorcb
:
try
:
self
.
errorcb
(
error
)
except
:
pass
else
:
logging
.
error
(
error
)
@
locked
@
locked
def
disconnect
(
self
):
def
disconnect
(
self
):
"""Disconnects from printer and pauses the print
"""Disconnects from printer and pauses the print
...
@@ -165,7 +172,7 @@ class printcore():
...
@@ -165,7 +172,7 @@ class printcore():
self
.
printer_tcp
.
settimeout
(
self
.
timeout
)
self
.
printer_tcp
.
settimeout
(
self
.
timeout
)
self
.
printer
=
self
.
printer_tcp
.
makefile
()
self
.
printer
=
self
.
printer_tcp
.
makefile
()
except
socket
.
error
as
e
:
except
socket
.
error
as
e
:
logging
.
e
rror
(
_
(
"Could not connect to
%
s:
%
s:"
)
%
(
hostname
,
port
)
+
self
.
logE
rror
(
_
(
"Could not connect to
%
s:
%
s:"
)
%
(
hostname
,
port
)
+
"
\n
"
+
_
(
"Socket error
%
s:"
)
%
e
.
errno
+
"
\n
"
+
_
(
"Socket error
%
s:"
)
%
e
.
errno
+
"
\n
"
+
e
.
strerror
)
"
\n
"
+
e
.
strerror
)
self
.
printer
=
None
self
.
printer
=
None
...
@@ -179,7 +186,7 @@ class printcore():
...
@@ -179,7 +186,7 @@ class printcore():
baudrate
=
self
.
baud
,
baudrate
=
self
.
baud
,
timeout
=
0.25
)
timeout
=
0.25
)
except
SerialException
as
e
:
except
SerialException
as
e
:
logging
.
e
rror
(
_
(
"Could not connect to
%
s at baudrate
%
s:"
)
%
(
self
.
port
,
self
.
baud
)
+
self
.
logE
rror
(
_
(
"Could not connect to
%
s at baudrate
%
s:"
)
%
(
self
.
port
,
self
.
baud
)
+
"
\n
"
+
_
(
"Serial error:
%
s"
)
%
e
)
"
\n
"
+
_
(
"Serial error:
%
s"
)
%
e
)
self
.
printer
=
None
self
.
printer
=
None
return
return
...
@@ -214,21 +221,21 @@ class printcore():
...
@@ -214,21 +221,21 @@ class printcore():
return
line
return
line
except
SelectError
as
e
:
except
SelectError
as
e
:
if
'Bad file descriptor'
in
e
.
args
[
1
]:
if
'Bad file descriptor'
in
e
.
args
[
1
]:
logging
.
e
rror
(
_
(
u"Can't read from printer (disconnected?) (SelectError {0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
logE
rror
(
_
(
u"Can't read from printer (disconnected?) (SelectError {0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
return
None
return
None
else
:
else
:
logging
.
e
rror
(
_
(
u"SelectError ({0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
logE
rror
(
_
(
u"SelectError ({0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
raise
raise
except
SerialException
as
e
:
except
SerialException
as
e
:
logging
.
e
rror
(
_
(
u"Can't read from printer (disconnected?) (SerialException): {0}"
)
.
format
(
decode_utf8
(
str
(
e
))))
self
.
logE
rror
(
_
(
u"Can't read from printer (disconnected?) (SerialException): {0}"
)
.
format
(
decode_utf8
(
str
(
e
))))
return
None
return
None
except
socket
.
error
as
e
:
except
socket
.
error
as
e
:
logging
.
e
rror
(
_
(
u"Can't read from printer (disconnected?) (Socket error {0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
logE
rror
(
_
(
u"Can't read from printer (disconnected?) (Socket error {0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
return
None
return
None
except
OSError
as
e
:
except
OSError
as
e
:
if
e
.
errno
==
errno
.
EAGAIN
:
# Not a real error, no data was available
if
e
.
errno
==
errno
.
EAGAIN
:
# Not a real error, no data was available
return
""
return
""
logging
.
e
rror
(
_
(
u"Can't read from printer (disconnected?) (OS Error {0}): {1}"
)
.
format
(
e
.
errno
,
e
.
strerror
))
self
.
logE
rror
(
_
(
u"Can't read from printer (disconnected?) (OS Error {0}): {1}"
)
.
format
(
e
.
errno
,
e
.
strerror
))
return
None
return
None
def
_listen_can_continue
(
self
):
def
_listen_can_continue
(
self
):
...
@@ -285,10 +292,7 @@ class printcore():
...
@@ -285,10 +292,7 @@ class printcore():
try
:
self
.
tempcb
(
line
)
try
:
self
.
tempcb
(
line
)
except
:
pass
except
:
pass
elif
line
.
startswith
(
'Error'
):
elif
line
.
startswith
(
'Error'
):
if
self
.
errorcb
:
self
.
logError
(
line
)
#callback for errors
try
:
self
.
errorcb
(
line
)
except
:
pass
# Teststrings for resend parsing # Firmware exp. result
# Teststrings for resend parsing # Firmware exp. result
# line="rs N2 Expected checksum 67" # Teacup 2
# line="rs N2 Expected checksum 67" # Teacup 2
if
line
.
lower
()
.
startswith
(
"resend"
)
or
line
.
startswith
(
"rs"
):
if
line
.
lower
()
.
startswith
(
"resend"
)
or
line
.
startswith
(
"rs"
):
...
@@ -434,7 +438,7 @@ class printcore():
...
@@ -434,7 +438,7 @@ class printcore():
else
:
else
:
self
.
priqueue
.
put_nowait
(
command
)
self
.
priqueue
.
put_nowait
(
command
)
else
:
else
:
logging
.
e
rror
(
_
(
"Not connected to printer."
))
self
.
logE
rror
(
_
(
"Not connected to printer."
))
def
send_now
(
self
,
command
,
wait
=
0
):
def
send_now
(
self
,
command
,
wait
=
0
):
"""Sends a command to the printer ahead of the command queue, without a
"""Sends a command to the printer ahead of the command queue, without a
...
@@ -442,7 +446,7 @@ class printcore():
...
@@ -442,7 +446,7 @@ class printcore():
if
self
.
online
:
if
self
.
online
:
self
.
priqueue
.
put_nowait
(
command
)
self
.
priqueue
.
put_nowait
(
command
)
else
:
else
:
logging
.
e
rror
(
_
(
"Not connected to printer."
))
self
.
logE
rror
(
_
(
"Not connected to printer."
))
def
_print
(
self
,
resuming
=
False
):
def
_print
(
self
,
resuming
=
False
):
self
.
_stop_sender
()
self
.
_stop_sender
()
...
@@ -451,7 +455,7 @@ class printcore():
...
@@ -451,7 +455,7 @@ class printcore():
#callback for printing started
#callback for printing started
try
:
self
.
startcb
(
resuming
)
try
:
self
.
startcb
(
resuming
)
except
:
except
:
logging
.
e
rror
(
_
(
"Print start callback failed with:"
)
+
self
.
logE
rror
(
_
(
"Print start callback failed with:"
)
+
"
\n
"
+
traceback
.
format_exc
())
"
\n
"
+
traceback
.
format_exc
())
while
self
.
printing
and
self
.
printer
and
self
.
online
:
while
self
.
printing
and
self
.
printer
and
self
.
online
:
self
.
_sendnext
()
self
.
_sendnext
()
...
@@ -462,10 +466,10 @@ class printcore():
...
@@ -462,10 +466,10 @@ class printcore():
#callback for printing done
#callback for printing done
try
:
self
.
endcb
()
try
:
self
.
endcb
()
except
:
except
:
logging
.
e
rror
(
_
(
"Print end callback failed with:"
)
+
self
.
logE
rror
(
_
(
"Print end callback failed with:"
)
+
"
\n
"
+
traceback
.
format_exc
())
"
\n
"
+
traceback
.
format_exc
())
except
:
except
:
logging
.
e
rror
(
_
(
"Print thread died due to the following error:"
)
+
self
.
logE
rror
(
_
(
"Print thread died due to the following error:"
)
+
"
\n
"
+
traceback
.
format_exc
())
"
\n
"
+
traceback
.
format_exc
())
finally
:
finally
:
self
.
print_thread
=
None
self
.
print_thread
=
None
...
@@ -553,8 +557,8 @@ class printcore():
...
@@ -553,8 +557,8 @@ class printcore():
# run the command through the analyzer
# run the command through the analyzer
try
:
self
.
analyzer
.
Analyze
(
command
)
try
:
self
.
analyzer
.
Analyze
(
command
)
except
:
except
:
logging
.
error
(
_
(
"Warning: c
ould not analyze command
%
s:"
)
%
command
+
logging
.
warning
(
_
(
"C
ould not analyze command
%
s:"
)
%
command
+
"
\n
"
+
traceback
.
format_exc
())
"
\n
"
+
traceback
.
format_exc
())
if
self
.
loud
:
if
self
.
loud
:
logging
.
info
(
"SENT:
%
s"
%
command
)
logging
.
info
(
"SENT:
%
s"
%
command
)
if
self
.
sendcb
:
if
self
.
sendcb
:
...
@@ -565,11 +569,11 @@ class printcore():
...
@@ -565,11 +569,11 @@ class printcore():
if
self
.
printer_tcp
:
self
.
printer
.
flush
()
if
self
.
printer_tcp
:
self
.
printer
.
flush
()
self
.
writefailures
=
0
self
.
writefailures
=
0
except
socket
.
error
as
e
:
except
socket
.
error
as
e
:
logging
.
e
rror
(
_
(
u"Can't write to printer (disconnected?) (Socket error {0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
logE
rror
(
_
(
u"Can't write to printer (disconnected?) (Socket error {0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
writefailures
+=
1
self
.
writefailures
+=
1
except
SerialException
as
e
:
except
SerialException
as
e
:
logging
.
e
rror
(
_
(
u"Can't write to printer (disconnected?) (SerialException): {0}"
)
.
format
(
decode_utf8
(
str
(
e
))))
self
.
logE
rror
(
_
(
u"Can't write to printer (disconnected?) (SerialException): {0}"
)
.
format
(
decode_utf8
(
str
(
e
))))
self
.
writefailures
+=
1
self
.
writefailures
+=
1
except
RuntimeError
as
e
:
except
RuntimeError
as
e
:
logging
.
e
rror
(
_
(
u"Socket connection broken, disconnected. ({0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
logE
rror
(
_
(
u"Socket connection broken, disconnected. ({0}): {1}"
)
.
format
(
e
.
errno
,
decode_utf8
(
e
.
strerror
)))
self
.
writefailures
+=
1
self
.
writefailures
+=
1
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