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
df7622cf
Commit
df7622cf
authored
Aug 04, 2012
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework listen loop
parent
48383711
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
20 deletions
+31
-20
printcore.py
printcore.py
+31
-20
No files found.
printcore.py
View file @
df7622cf
...
@@ -110,6 +110,12 @@ class printcore():
...
@@ -110,6 +110,12 @@ class printcore():
def
_readline
(
self
):
def
_readline
(
self
):
try
:
try
:
line
=
self
.
printer
.
readline
()
line
=
self
.
printer
.
readline
()
if
len
(
line
)
>
1
:
self
.
log
.
append
(
line
)
if
self
.
recvcb
:
try
:
self
.
recvcb
(
line
)
except
:
pass
if
self
.
loud
:
print
"RECV: "
,
line
.
rstrip
()
return
line
return
line
except
SelectError
,
e
:
except
SelectError
,
e
:
if
'Bad file descriptor'
in
e
.
args
[
1
]:
if
'Bad file descriptor'
in
e
.
args
[
1
]:
...
@@ -124,44 +130,49 @@ class printcore():
...
@@ -124,44 +130,49 @@ class printcore():
print
"Can't read from printer (disconnected?)."
print
"Can't read from printer (disconnected?)."
return
None
return
None
def
_listen_can_continue
(
self
):
return
not
self
.
stop_read_thread
and
self
.
printer
and
self
.
printer
.
isOpen
()
def
_listen_until_online
(
self
):
while
not
self
.
online
and
self
.
_listen_can_continue
():
self
.
_send
(
"M105"
)
while
self
.
_listen_can_continue
():
line
=
self
.
_readline
()
if
line
==
None
:
break
if
line
.
startswith
(
tuple
(
self
.
greetings
))
or
line
.
startswith
(
'ok'
):
if
self
.
onlinecb
:
try
:
self
.
onlinecb
()
except
:
pass
self
.
online
=
True
return
time
.
sleep
(
0.5
)
def
_listen
(
self
):
def
_listen
(
self
):
"""This function acts on messages from the firmware
"""This function acts on messages from the firmware
"""
"""
self
.
clear
=
True
self
.
clear
=
True
if
not
self
.
printing
:
if
not
self
.
printing
:
self
.
_send
(
"M105"
)
self
.
_listen_until_online
(
self
)
time
.
sleep
(
1
)
while
self
.
_listen_can_continue
():
while
not
self
.
stop_read_thread
and
self
.
printer
and
self
.
printer
.
isOpen
():
line
=
self
.
_readline
()
line
=
self
.
_readline
()
if
line
==
None
:
if
line
==
None
:
break
break
if
len
(
line
)
>
1
:
self
.
log
.
append
(
line
)
if
self
.
recvcb
:
try
:
self
.
recvcb
(
line
)
except
:
pass
if
self
.
loud
:
print
"RECV: "
,
line
.
rstrip
()
if
line
.
startswith
(
'DEBUG_'
):
if
line
.
startswith
(
'DEBUG_'
):
continue
continue
if
line
.
startswith
(
tuple
(
self
.
greetings
))
or
line
.
startswith
(
'ok'
):
if
line
.
startswith
(
tuple
(
self
.
greetings
))
or
line
.
startswith
(
'ok'
):
self
.
clear
=
True
self
.
clear
=
True
if
line
.
startswith
(
tuple
(
self
.
greetings
))
or
line
.
startswith
(
'ok'
)
or
"T:"
in
line
:
if
line
.
startswith
(
'ok'
)
and
"T:"
in
line
and
self
.
tempcb
:
if
(
not
self
.
online
or
line
.
startswith
(
tuple
(
self
.
greetings
)))
and
self
.
onlinecb
is
not
None
:
#callback for temp, status, whatever
try
:
self
.
onlinecb
(
)
try
:
self
.
tempcb
(
line
)
except
:
pass
except
:
pass
self
.
online
=
True
if
line
.
startswith
(
'ok'
):
#self.resendfrom=-1
if
"T:"
in
line
and
self
.
tempcb
is
not
None
:
#callback for temp, status, whatever
try
:
self
.
tempcb
(
line
)
except
:
pass
elif
line
.
startswith
(
'Error'
):
elif
line
.
startswith
(
'Error'
):
if
self
.
errorcb
is
not
None
:
if
self
.
errorcb
:
#callback for errors
#callback for errors
try
:
self
.
errorcb
(
line
)
try
:
self
.
errorcb
(
line
)
except
:
pass
except
:
pass
if
line
.
lower
()
.
startswith
(
"resend"
)
or
line
.
startswith
(
"rs"
):
if
line
.
lower
()
.
startswith
(
"resend"
)
or
line
.
startswith
(
"rs"
):
toresend
=
self
.
resendfrom
try
:
try
:
toresend
=
int
(
line
.
replace
(
"N:"
,
" "
)
.
replace
(
"N"
,
" "
)
.
replace
(
":"
,
" "
)
.
split
()[
-
1
])
toresend
=
int
(
line
.
replace
(
"N:"
,
" "
)
.
replace
(
"N"
,
" "
)
.
replace
(
":"
,
" "
)
.
split
()[
-
1
])
except
:
except
:
...
...
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