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
a6df0acf
Commit
a6df0acf
authored
Aug 03, 2012
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup and refactor a little
parent
ee5e41bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
63 deletions
+49
-63
printcore.py
printrun/printcore.py
+49
-63
No files found.
printrun/printcore.py
View file @
a6df0acf
...
@@ -109,84 +109,70 @@ class printcore():
...
@@ -109,84 +109,70 @@ class printcore():
self
.
printer
.
setDTR
(
1
)
self
.
printer
.
setDTR
(
1
)
self
.
printer
.
setDTR
(
0
)
self
.
printer
.
setDTR
(
0
)
def
_readline
(
self
):
try
:
line
=
self
.
printer
.
readline
()
return
line
except
SelectError
,
e
:
if
'Bad file descriptor'
in
e
.
args
[
1
]:
print
"Can't read from printer (disconnected?)."
return
None
else
:
raise
except
SerialException
,
e
:
print
"Can't read from printer (disconnected?)."
return
None
except
OSError
,
e
:
print
"Can't read from printer (disconnected?)."
return
None
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
self
.
printer
.
inWaiting
():
# flush receive buffer
if
not
self
.
printing
:
self
.
printer
.
read
(
self
.
printer
.
inWaiting
())
while
not
self
.
printer
.
inWaiting
():
# wait for new data to read
time
.
sleep
(
0.5
)
if
(
not
self
.
online
and
not
self
.
printing
):
# send M105 to initiate connection
self
.
_send
(
"M105"
)
self
.
_send
(
"M105"
)
while
(
True
):
time
.
sleep
(
1
)
if
self
.
stop_read_thread
:
while
not
self
.
stop_read_thread
and
self
.
printer
and
self
.
printer
.
isOpen
():
return
line
=
self
.
_readline
()
if
(
not
self
.
printer
or
not
self
.
printer
.
isOpen
):
if
line
==
None
:
break
try
:
line
=
self
.
printer
.
readline
()
except
SelectError
,
e
:
if
'Bad file descriptor'
in
e
.
args
[
1
]:
print
"Can't read from printer (disconnected?)."
break
else
:
raise
except
SerialException
,
e
:
print
"Can't read from printer (disconnected?)."
break
except
OSError
,
e
:
print
"Can't read from printer (disconnected?)."
break
break
if
len
(
line
)
>
1
:
if
(
len
(
line
)
>
1
):
self
.
log
.
append
(
line
)
self
.
log
+=
[
line
]
if
self
.
recvcb
:
if
self
.
recvcb
is
not
None
:
try
:
self
.
recvcb
(
line
)
try
:
except
:
pass
self
.
recvcb
(
line
)
if
self
.
loud
:
print
"RECV: "
,
line
.
rstrip
()
except
:
if
line
.
startswith
(
'DEBUG_'
):
pass
if
self
.
loud
:
print
"RECV: "
,
line
.
rstrip
()
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
(
tuple
(
self
.
greetings
))
or
line
.
startswith
(
'ok'
)
or
"T:"
in
line
:
if
(
not
self
.
online
or
line
.
startswith
(
tuple
(
self
.
greetings
)))
and
self
.
onlinecb
is
not
None
:
if
(
not
self
.
online
or
line
.
startswith
(
tuple
(
self
.
greetings
)))
and
self
.
onlinecb
is
not
None
:
try
:
try
:
self
.
onlinecb
()
self
.
onlinecb
()
except
:
pass
except
:
self
.
online
=
True
pass
if
line
.
startswith
(
'ok'
):
self
.
online
=
True
if
(
line
.
startswith
(
'ok'
)):
#self.resendfrom=-1
#self.resendfrom=-1
#put temp handling here
#put temp handling here
if
"T:"
in
line
and
self
.
tempcb
is
not
None
:
if
"T:"
in
line
and
self
.
tempcb
is
not
None
:
try
:
#callback for temp, status, whatever
self
.
tempcb
(
line
)
try
:
self
.
tempcb
(
line
)
except
:
except
:
pass
pass
elif
line
.
startswith
(
'Error'
):
#callback for temp, status, whatever
elif
(
line
.
startswith
(
'Error'
)):
if
self
.
errorcb
is
not
None
:
if
self
.
errorcb
is
not
None
:
try
:
#callback for errors
self
.
errorcb
(
line
)
try
:
self
.
errorcb
(
line
)
except
:
except
:
pass
pass
#callback for errors
pass
if
line
.
lower
()
.
startswith
(
"resend"
)
or
line
.
startswith
(
"rs"
):
if
line
.
lower
()
.
startswith
(
"resend"
)
or
line
.
startswith
(
"rs"
):
try
:
try
:
toresend
=
int
(
line
.
replace
(
"N:"
,
" "
)
.
replace
(
"N"
,
" "
)
.
replace
(
":"
,
" "
)
.
split
()[
-
1
])
toresend
=
int
(
line
.
replace
(
"N:"
,
" "
)
.
replace
(
"N"
,
" "
)
.
replace
(
":"
,
" "
)
.
split
()[
-
1
])
except
:
except
:
if
line
.
startswith
(
"rs"
):
if
line
.
startswith
(
"rs"
):
toresend
=
int
(
line
.
split
()[
1
])
toresend
=
int
(
line
.
split
()[
1
])
self
.
resendfrom
=
toresend
self
.
resendfrom
=
toresend
self
.
clear
=
True
self
.
clear
=
True
self
.
clear
=
True
self
.
clear
=
True
#callback for disconnect
def
_checksum
(
self
,
command
):
def
_checksum
(
self
,
command
):
return
reduce
(
lambda
x
,
y
:
x
^
y
,
map
(
ord
,
command
))
return
reduce
(
lambda
x
,
y
:
x
^
y
,
map
(
ord
,
command
))
...
...
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