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
a50ebb02
Commit
a50ebb02
authored
May 27, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'experimental' of github.com:kliment/Printrun into experimental
parents
5d559db6
89c0a242
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
12 deletions
+66
-12
printcore.py
printcore.py
+47
-6
gcview.py
printrun/gcview.py
+0
-1
actors.py
printrun/libtatlin/actors.py
+19
-5
No files found.
printcore.py
View file @
a50ebb02
...
...
@@ -17,9 +17,11 @@
from
serial
import
Serial
,
SerialException
from
threading
import
Thread
from
select
import
error
as
SelectError
from
select
import
error
as
SelectError
,
select
import
time
,
getopt
,
sys
import
platform
,
os
import
socket
# Network
import
re
# Regex
from
collections
import
deque
from
printrun.GCodeAnalyzer
import
GCodeAnalyzer
from
printrun
import
gcoder
...
...
@@ -38,6 +40,9 @@ def enable_hup(port):
def
disable_hup
(
port
):
control_ttyhup
(
port
,
True
)
def
is_socket
(
printer
):
return
(
type
(
printer
)
==
socket
.
_socketobject
)
class
printcore
():
def
__init__
(
self
,
port
=
None
,
baud
=
None
):
"""Initializes a printcore instance. Pass the port and baud rate to connect immediately
...
...
@@ -102,8 +107,15 @@ class printcore():
if
baud
is
not
None
:
self
.
baud
=
baud
if
self
.
port
is
not
None
and
self
.
baud
is
not
None
:
disable_hup
(
self
.
port
)
self
.
printer
=
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
baud
,
timeout
=
0.25
)
# Connect to socket if "port" is an IP, device if not
p
=
re
.
compile
(
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
\
.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
)
if
p
.
match
(
port
):
self
.
printer
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
timeout
=
0.25
self
.
printer
.
connect
((
port
,
baud
))
else
:
disable_hup
(
self
.
port
)
self
.
printer
=
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
baud
,
timeout
=
0.25
)
self
.
stop_read_thread
=
False
self
.
read_thread
=
Thread
(
target
=
self
.
_listen
)
self
.
read_thread
.
start
()
...
...
@@ -111,14 +123,27 @@ class printcore():
def
reset
(
self
):
"""Reset the printer
"""
if
self
.
printer
:
if
self
.
printer
and
not
is_socket
(
self
.
printer
)
:
self
.
printer
.
setDTR
(
1
)
time
.
sleep
(
0.2
)
self
.
printer
.
setDTR
(
0
)
def
_readline
(
self
):
try
:
line
=
self
.
printer
.
readline
()
# Read line if socket
if
is_socket
(
self
.
printer
):
line
=
''
ready
=
select
([
self
.
printer
],
[],
[],
self
.
timeout
)
if
ready
[
0
]:
while
not
"
\n
"
in
line
:
chunk
=
self
.
printer
.
recv
(
1
)
if
chunk
==
''
:
raise
RuntimeError
(
"socket connection broken"
)
line
=
line
+
chunk
# Read if tty
else
:
line
=
self
.
printer
.
readline
()
if
len
(
line
)
>
1
:
self
.
log
.
append
(
line
)
if
self
.
recvcb
:
...
...
@@ -140,6 +165,8 @@ class printcore():
return
None
def
_listen_can_continue
(
self
):
if
is_socket
(
self
.
printer
):
return
not
self
.
stop_read_thread
and
self
.
printer
return
not
self
.
stop_read_thread
and
self
.
printer
and
self
.
printer
.
isOpen
()
def
_listen_until_online
(
self
):
...
...
@@ -267,6 +294,8 @@ class printcore():
self
.
pauseE
=
self
.
analyzer
.
e
-
self
.
analyzer
.
eOffset
;
self
.
pauseF
=
self
.
analyzer
.
f
;
self
.
pauseRelative
=
self
.
analyzer
.
relative
;
def
resume
(
self
):
"""Resumes a paused print.
...
...
@@ -428,9 +457,21 @@ class printcore():
try
:
self
.
sendcb
(
command
)
except
:
pass
try
:
self
.
printer
.
write
(
str
(
command
+
"
\n
"
))
# If the printer is connected via Ethernet, use send
if
is_socket
(
self
.
printer
):
msg
=
str
(
command
+
"
\n
"
)
totalsent
=
0
while
totalsent
<
len
(
msg
):
sent
=
self
.
printer
.
send
(
msg
[
totalsent
:])
if
sent
==
0
:
raise
RuntimeError
(
"socket connection broken"
)
totalsent
=
totalsent
+
sent
else
:
self
.
printer
.
write
(
str
(
command
+
"
\n
"
))
except
SerialException
,
e
:
print
"Can't write to printer (disconnected?)."
except
RuntimeError
,
e
:
print
"Socket connection broken, disconnected."
if
__name__
==
'__main__'
:
baud
=
115200
...
...
printrun/gcview.py
View file @
a50ebb02
...
...
@@ -26,7 +26,6 @@ pyglet.options['debug_gl'] = True
from
pyglet.gl
import
*
from
pyglet
import
gl
from
pyglet.graphics.vertexbuffer
import
create_buffer
from
printrun
import
gcoder
from
printrun
import
stltool
...
...
printrun/libtatlin/actors.py
View file @
a50ebb02
...
...
@@ -23,7 +23,7 @@ import sys
from
pyglet.gl
import
*
from
pyglet
import
gl
from
pyglet.graphics.vertexbuffer
import
create_buffer
from
pyglet.graphics.vertexbuffer
import
create_buffer
,
VertexBufferObject
from
.
import
vector
...
...
@@ -339,7 +339,11 @@ class GcodeModel(Model):
def
_display_movements
(
self
,
mode_2d
=
False
):
self
.
vertex_buffer
.
bind
()
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
None
)
has_vbo
=
isinstance
(
self
.
vertex_buffer
,
VertexBufferObject
)
if
has_vbo
:
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
None
)
else
:
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
self
.
vertex_buffer
.
ptr
)
if
mode_2d
:
glScale
(
1.0
,
1.0
,
0.0
)
# discard z coordinates
...
...
@@ -360,7 +364,10 @@ class GcodeModel(Model):
glEnableClientState
(
GL_COLOR_ARRAY
)
self
.
vertex_color_buffer
.
bind
()
glColorPointer
(
4
,
GL_FLOAT
,
0
,
None
)
if
has_vbo
:
glColorPointer
(
4
,
GL_FLOAT
,
0
,
None
)
else
:
glColorPointer
(
4
,
GL_FLOAT
,
0
,
self
.
vertex_color_buffer
.
ptr
)
start
=
max
(
self
.
printed_until
,
0
)
end
=
end
-
start
...
...
@@ -372,10 +379,17 @@ class GcodeModel(Model):
def
_display_arrows
(
self
):
self
.
arrow_buffer
.
bind
()
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
None
)
has_vbo
=
isinstance
(
self
.
arrow_buffer
,
VertexBufferObject
)
if
has_vbo
:
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
None
)
else
:
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
self
.
arrow_buffer
.
ptr
)
self
.
arrow_color_buffer
.
bind
()
glColorPointer
(
4
,
GL_FLOAT
,
0
,
None
)
if
has_vbo
:
glColorPointer
(
4
,
GL_FLOAT
,
0
,
None
)
else
:
glColorPointer
(
4
,
GL_FLOAT
,
0
,
self
.
arrow_color_buffer
.
ptr
)
start
=
(
self
.
layer_stops
[
self
.
num_layers_to_draw
-
1
]
//
2
)
*
3
end
=
(
self
.
layer_stops
[
self
.
num_layers_to_draw
]
//
2
)
*
3
...
...
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