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
27cbef59
Commit
27cbef59
authored
May 26, 2013
by
Elias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implented ethernet in printcore for the experimental branch
parent
42425257
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
9 deletions
+47
-9
printcore.py
printcore.py
+47
-9
No files found.
printcore.py
View file @
27cbef59
...
@@ -17,10 +17,12 @@
...
@@ -17,10 +17,12 @@
from
serial
import
Serial
,
SerialException
from
serial
import
Serial
,
SerialException
from
threading
import
Thread
from
threading
import
Thread
from
select
import
error
as
SelectError
from
select
import
error
as
SelectError
,
select
import
time
,
getopt
,
sys
import
time
,
getopt
,
sys
import
platform
,
os
import
platform
,
os
from
GCodeAnalyzer
import
GCodeAnalyzer
from
GCodeAnalyzer
import
GCodeAnalyzer
import
socket
# Network
import
re
# Regex
def
control_ttyhup
(
port
,
disable_hup
):
def
control_ttyhup
(
port
,
disable_hup
):
"""Controls the HUPCL"""
"""Controls the HUPCL"""
...
@@ -36,6 +38,9 @@ def enable_hup(port):
...
@@ -36,6 +38,9 @@ def enable_hup(port):
def
disable_hup
(
port
):
def
disable_hup
(
port
):
control_ttyhup
(
port
,
True
)
control_ttyhup
(
port
,
True
)
def
is_socket
(
printer
):
return
(
type
(
printer
)
==
socket
.
_socketobject
)
class
printcore
():
class
printcore
():
def
__init__
(
self
,
port
=
None
,
baud
=
None
):
def
__init__
(
self
,
port
=
None
,
baud
=
None
):
"""Initializes a printcore instance. Pass the port and baud rate to connect immediately
"""Initializes a printcore instance. Pass the port and baud rate to connect immediately
...
@@ -98,6 +103,13 @@ class printcore():
...
@@ -98,6 +103,13 @@ class printcore():
if
baud
is
not
None
:
if
baud
is
not
None
:
self
.
baud
=
baud
self
.
baud
=
baud
if
self
.
port
is
not
None
and
self
.
baud
is
not
None
:
if
self
.
port
is
not
None
and
self
.
baud
is
not
None
:
# 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
)
disable_hup
(
self
.
port
)
self
.
printer
=
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
baud
,
timeout
=
0.25
)
self
.
printer
=
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
baud
,
timeout
=
0.25
)
self
.
stop_read_thread
=
False
self
.
stop_read_thread
=
False
...
@@ -107,14 +119,27 @@ class printcore():
...
@@ -107,14 +119,27 @@ class printcore():
def
reset
(
self
):
def
reset
(
self
):
"""Reset the printer
"""Reset the printer
"""
"""
if
self
.
printer
:
if
self
.
printer
and
not
is_socket
(
self
.
printer
)
:
self
.
printer
.
setDTR
(
1
)
self
.
printer
.
setDTR
(
1
)
time
.
sleep
(
0.2
)
time
.
sleep
(
0.2
)
self
.
printer
.
setDTR
(
0
)
self
.
printer
.
setDTR
(
0
)
def
_readline
(
self
):
def
_readline
(
self
):
try
:
try
:
# 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
()
line
=
self
.
printer
.
readline
()
if
len
(
line
)
>
1
:
if
len
(
line
)
>
1
:
self
.
log
.
append
(
line
)
self
.
log
.
append
(
line
)
if
self
.
recvcb
:
if
self
.
recvcb
:
...
@@ -136,6 +161,8 @@ class printcore():
...
@@ -136,6 +161,8 @@ class printcore():
return
None
return
None
def
_listen_can_continue
(
self
):
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
()
return
not
self
.
stop_read_thread
and
self
.
printer
and
self
.
printer
.
isOpen
()
def
_listen_until_online
(
self
):
def
_listen_until_online
(
self
):
...
@@ -418,6 +445,17 @@ class printcore():
...
@@ -418,6 +445,17 @@ class printcore():
if
self
.
sendcb
:
if
self
.
sendcb
:
try
:
self
.
sendcb
(
command
)
try
:
self
.
sendcb
(
command
)
except
:
pass
except
:
pass
# 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
:
try
:
try
:
self
.
printer
.
write
(
str
(
command
+
"
\n
"
))
self
.
printer
.
write
(
str
(
command
+
"
\n
"
))
except
SerialException
,
e
:
except
SerialException
,
e
:
...
...
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