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
b679451a
Commit
b679451a
authored
May 26, 2011
by
kliment
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add callback support
parent
a1cbd121
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
printcore.py
printcore.py
+25
-0
No files found.
printcore.py
View file @
b679451a
...
@@ -22,6 +22,13 @@ class printcore():
...
@@ -22,6 +22,13 @@ class printcore():
self
.
sentlines
=
{}
self
.
sentlines
=
{}
self
.
log
=
[]
self
.
log
=
[]
self
.
sent
=
[]
self
.
sent
=
[]
self
.
tempcb
=
None
#impl (wholeline)
self
.
recvcb
=
None
#impl (wholeline)
self
.
sendcb
=
None
#impl (wholeline)
self
.
errorcb
=
None
#impl (wholeline)
self
.
startcb
=
None
#impl ()
self
.
endcb
=
None
#impl ()
self
.
onlinecb
=
None
#impl ()
self
.
loud
=
False
#emit sent and received lines to terminal
self
.
loud
=
False
#emit sent and received lines to terminal
if
port
is
not
None
and
baud
is
not
None
:
if
port
is
not
None
and
baud
is
not
None
:
#print port, baud
#print port, baud
...
@@ -63,18 +70,30 @@ class printcore():
...
@@ -63,18 +70,30 @@ class printcore():
line
=
self
.
printer
.
readline
()
line
=
self
.
printer
.
readline
()
if
(
len
(
line
)
>
1
):
if
(
len
(
line
)
>
1
):
self
.
log
+=
[
line
]
self
.
log
+=
[
line
]
if
self
.
recvcb
is
not
None
:
self
.
recvcb
(
line
)
if
self
.
loud
:
if
self
.
loud
:
print
"RECV: "
,
line
print
"RECV: "
,
line
if
(
line
.
startswith
(
'start'
)):
if
(
line
.
startswith
(
'start'
)):
self
.
clear
=
True
self
.
clear
=
True
if
not
self
.
online
and
self
.
onlinecb
is
not
None
:
self
.
onlinecb
()
self
.
online
=
True
self
.
online
=
True
elif
(
line
.
startswith
(
'ok'
)):
elif
(
line
.
startswith
(
'ok'
)):
self
.
clear
=
True
self
.
clear
=
True
if
not
self
.
online
and
self
.
onlinecb
is
not
None
:
self
.
onlinecb
()
self
.
online
=
True
self
.
online
=
True
self
.
resendfrom
=-
1
self
.
resendfrom
=-
1
#put temp handling here
#put temp handling here
if
"T:"
in
line
and
self
.
tempcb
is
not
None
:
self
.
tempcb
(
line
)
#callback for temp, status, whatever
#callback for temp, status, whatever
elif
(
line
.
startswith
(
'Error'
)):
elif
(
line
.
startswith
(
'Error'
)):
if
self
.
errorcb
is
not
None
:
self
.
errorcb
(
line
)
#callback for errors
#callback for errors
pass
pass
if
"Resend"
in
line
or
"rs"
in
line
:
if
"Resend"
in
line
or
"rs"
in
line
:
...
@@ -143,8 +162,12 @@ class printcore():
...
@@ -143,8 +162,12 @@ class printcore():
def
_print
(
self
):
def
_print
(
self
):
#callback for printing started
#callback for printing started
if
self
.
startcb
is
not
None
:
self
.
startcb
()
while
(
self
.
printing
and
self
.
printer
and
self
.
online
):
while
(
self
.
printing
and
self
.
printer
and
self
.
online
):
self
.
_sendnext
()
self
.
_sendnext
()
if
self
.
endcb
is
not
None
:
self
.
endcb
()
#callback for printing done
#callback for printing done
def
_sendnext
(
self
):
def
_sendnext
(
self
):
...
@@ -188,6 +211,8 @@ class printcore():
...
@@ -188,6 +211,8 @@ class printcore():
self
.
sent
+=
[
command
]
self
.
sent
+=
[
command
]
if
self
.
loud
:
if
self
.
loud
:
print
"SENT: "
,
command
print
"SENT: "
,
command
if
self
.
sendcb
is
not
None
:
self
.
sendcb
(
command
)
self
.
printer
.
write
(
command
+
"
\n
"
)
self
.
printer
.
write
(
command
+
"
\n
"
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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