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
cc59bbd2
Commit
cc59bbd2
authored
Jul 30, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:kliment/Printrun
parents
2bdbc84c
fdcdb8be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
40 deletions
+36
-40
prontserve.py
prontserve.py
+36
-40
No files found.
prontserve.py
View file @
cc59bbd2
...
...
@@ -109,12 +109,17 @@ class Prontserve(pronsole.pronsole, EventEmitter):
dir
=
os
.
path
.
dirname
(
__file__
)
self
.
server
=
ConstructServer
(
printer
=
self
,
settings
=
self
.
settings
,
settings
=
dict
(
pause_between_prints
=
self
.
settings
.
pause_between_prints
,
sensor_poll_rate
=
self
.
settings
.
sensor_poll_rate
*
1000
),
components
=
dict
(
temps
=
[
"e0"
,
"b"
],
fans
=
[
"f0"
],
conveyors
=
[
"c0"
],
axes
=
[
"x"
,
"y"
,
"z"
]
axes
=
[]
# In the far off future we may have axes like these for position data:
# axes= ["x", "y", "z"]
),
server_settings
=
dict
(
template_path
=
os
.
path
.
join
(
dir
,
"printrun"
,
"server"
,
"templates"
),
...
...
@@ -147,11 +152,12 @@ class Prontserve(pronsole.pronsole, EventEmitter):
def
start
(
self
):
try
:
# Connect to the printer
if
self
.
dry_run
==
False
:
# Attempt to connect to the printer
self
.
do_connect
(
""
)
if
self
.
p
.
printer
==
None
:
sys
.
exit
(
1
)
print
"Connecting to printer..."
# Wait for the attempt to succeed or timeout
for
x
in
range
(
0
,
50
-
1
):
if
self
.
p
.
online
==
True
:
break
sys
.
stdout
.
write
(
"."
)
...
...
@@ -183,13 +189,13 @@ class Prontserve(pronsole.pronsole, EventEmitter):
def
post_process_print_job
(
self
,
filename
,
filebody
):
return
FastGCode
(
filebody
.
split
(
"
\n
"
))
def
print_progress
(
self
):
if
(
self
.
p
.
printing
):
return
100
*
float
(
self
.
p
.
queueindex
)
/
len
(
self
.
p
.
mainqueue
)
if
(
self
.
sdprinting
):
return
self
.
percentdone
def
current_print_line
(
self
):
if
(
self
.
p
.
printing
):
return
(
self
.
p
.
queueindex
)
return
0
def
total_print_lines
(
self
,
job_body
):
return
len
(
job_body
)
def
start_print_job
(
self
,
job
):
self
.
p
.
startprint
(
job
[
'body'
])
self
.
p
.
paused
=
False
...
...
@@ -229,7 +235,7 @@ class Prontserve(pronsole.pronsole, EventEmitter):
# Not thread safe; must be run from the ioloop thread.
def
reset
(
self
):
self
.
async
(
self
.
server
.
set_
waiting_to_reach_temp
,
None
)
self
.
async
(
self
.
server
.
set_
blocking_temps
,
[]
)
# pause the print job if any is printing
if
self
.
p
.
printing
:
pronsole
.
pronsole
.
do_pause
(
self
,
""
)
...
...
@@ -242,28 +248,27 @@ class Prontserve(pronsole.pronsole, EventEmitter):
self
.
p
.
printing
=
False
def
on_target_temp_changed
(
self
,
target
=
None
,
value
=
None
):
def
on_temp_target_change
(
self
,
parent_path
,
component
,
value
):
target
=
parent_path
[
0
]
gcode
=
"M104"
if
target
==
"b"
:
gcode
=
"M140"
if
not
target
in
[
"b"
,
"e0"
]:
gcode
+=
" p
%
i"
%
(
int
(
target
[
1
:]))
gcode
+=
" S
%
f"
%
float
(
value
)
self
.
p
.
send_now
(
gcode
)
def
on_fan_enabled_change
d
(
self
,
target
=
None
,
value
=
Non
e
):
update_fan
()
def
on_fan_enabled_change
(
self
,
parent_path
,
component
,
valu
e
):
update_fan
(
component
)
def
on_fan_speed_change
d
(
self
,
target
=
None
,
value
=
Non
e
):
update_fan
()
def
on_fan_speed_change
(
self
,
parent_path
,
component
,
valu
e
):
update_fan
(
component
)
def
update_fan
(
self
):
if
self
.
fan_enabled
==
False
:
speed
=
0
else
:
speed
=
int
(
self
.
server
.
c_get
(
"f0"
,
"fan_speed"
))
def
update_fan
(
self
,
component
):
speed
=
int
(
component
[
'speed'
])
if
component
[
'enabled'
]
==
False
:
speed
=
0
print
"M106 S
%
i"
%
speed
self
.
p
.
send_now
(
"M106 S
%
i"
%
speed
)
def
on_motors_enabled_change
d
(
self
,
target
=
None
,
value
=
Non
e
):
def
on_motors_enabled_change
(
self
,
parent_path
,
component
,
valu
e
):
self
.
p
.
send_now
({
True
:
"M17"
,
False
:
"M18"
}[
value
])
def
request_sensor_update
(
self
):
...
...
@@ -278,7 +283,7 @@ class Prontserve(pronsole.pronsole, EventEmitter):
l
=
l
.
rstrip
()
#print l
if
self
.
server
.
waiting_to_reach_temp
and
(
"ok"
in
l
):
self
.
async
(
self
.
server
.
set_
waiting_to_reach_temp
,
None
)
self
.
async
(
self
.
server
.
set_
blocking_temps
,
[]
)
if
(
"T:"
in
l
):
self
.
async
(
self
.
_receive_sensor_update
,
l
)
if
l
!=
"ok"
and
not
l
.
startswith
(
"ok T"
)
and
not
l
.
startswith
(
"T:"
):
...
...
@@ -293,10 +298,10 @@ class Prontserve(pronsole.pronsole, EventEmitter):
if
" P"
in
l
:
target
=
"e
%
i"
%
(
int
(
re
.
search
(
' P([0-9]+)'
,
l
)
.
group
(
1
)))
else
:
target
=
"b"
self
.
async
(
self
.
server
.
c_set
,
target
,
"target_temp"
,
temp
,
internal
=
True
)
self
.
async
(
self
.
server
.
c_set
,
[
target
,
"target_temp"
]
,
temp
,
internal
=
True
)
if
(
"M109"
in
l
)
or
(
"M190"
in
l
)
or
(
"M116"
in
l
):
if
(
"M116"
in
l
):
target
=
"e0"
self
.
async
(
self
.
server
.
set_
waiting_to_reach_temp
,
[
target
])
self
.
async
(
self
.
server
.
set_
blocking_temps
,
[
target
])
# Adds a callback to the ioloop to run a method later on in the server thread
def
async
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -311,24 +316,15 @@ class Prontserve(pronsole.pronsole, EventEmitter):
for
key
,
value
in
d
.
iteritems
():
if
key
==
"t"
:
key
=
"e0"
if
not
key
in
self
.
server
.
components
:
continue
self
.
server
.
c_set
(
key
,
"current_temp"
,
float
(
value
),
internal
=
True
)
self
.
server
.
c_set
(
[
key
,
"current_temp"
]
,
float
(
value
),
internal
=
True
)
# Fire a event if the extruder is giving us a countdown till it's online
# see: TEMP_RESIDENCY_TIME (via the googles)
# see: https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/Marlin_main.cpp#L1191
if
(
"w"
in
d
):
percent
=
0
if
not
d
[
"w"
]
==
"?"
:
w_val
=
float
(
d
[
"w"
])
if
w_val
>
self
.
max_w_val
:
self
.
max_w_val
=
w_val
percent
=
(
100
-
w_val
*
100
/
self
.
max_w_val
)
progress
=
{
'eta'
:
w_val
,
'percent'
:
percent
}
else
:
progress
=
{
'percent'
:
percent
}
for
target
in
(
self
.
server
.
waiting_to_reach_temp
):
self
.
server
.
c_set
(
target
,
"target_temp_progress"
,
progress
,
internal
=
True
)
if
(
"w"
in
d
)
and
(
not
d
[
"w"
]
==
"?"
):
w
=
float
(
d
[
"w"
])
*
1000
for
target
in
(
self
.
server
.
blockers
):
self
.
server
.
c_set
([
target
,
"target_temp_countdown"
],
w
,
internal
=
True
)
except
Exception
as
ex
:
print
traceback
.
format_exc
()
...
...
@@ -336,9 +332,9 @@ class Prontserve(pronsole.pronsole, EventEmitter):
msg
=
''
.
join
(
str
(
i
)
for
i
in
msg
)
msg
.
replace
(
"
\r
"
,
""
)
print
msg
self
.
server
.
broadcast
([
dict
(
type
=
"log"
,
data
=
dict
(
msg
=
msg
,
level
=
"debug"
))
])
#
self.server.broadcast([
#
dict(type= "log", data= dict(msg= msg, level= "debug"))
#
])
def
logError
(
self
,
*
msg
):
print
u""
.
join
(
unicode
(
i
)
for
i
in
msg
)
...
...
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