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
6cf08006
Commit
6cf08006
authored
Mar 14, 2013
by
fsantini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indentation fixes, start pronterface modification
parent
b335a4cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
130 deletions
+154
-130
GCodeAnalyzer.py
GCodeAnalyzer.py
+150
-130
printcore.py
printcore.py
+4
-0
No files found.
GCodeAnalyzer.py
View file @
6cf08006
...
@@ -33,32 +33,35 @@
...
@@ -33,32 +33,35 @@
import
re
import
re
class
GCodeAnalyzer
():
class
GCodeAnalyzer
():
def
__init__
(
self
):
def
__init__
(
self
):
self
.
x
=
0
self
.
x
=
0
self
.
y
=
0
self
.
y
=
0
self
.
z
=
0
self
.
z
=
0
self
.
e
=
0
self
.
e
=
0
self
.
emax
=
0
self
.
emax
=
0
self
.
f
=
1000
self
.
f
=
1000
self
.
lastX
=
0
self
.
lastX
=
0
self
.
lastY
=
0
self
.
lastY
=
0
self
.
lastZ
=
0
self
.
lastZ
=
0
self
.
lastE
=
0
self
.
lastE
=
0
self
.
xOffset
=
0
self
.
xOffset
=
0
self
.
yOffset
=
0
self
.
yOffset
=
0
self
.
zOffset
=
0
self
.
zOffset
=
0
self
.
eOffset
=
0
self
.
eOffset
=
0
self
.
lastZPrint
=
0
self
.
lastZPrint
=
0
self
.
layerZ
=
0
self
.
layerZ
=
0
self
.
relative
=
False
self
.
relative
=
False
self
.
eRelative
=
False
self
.
eRelative
=
False
self
.
homeX
=
0
self
.
homeX
=
0
self
.
homeY
=
0
self
.
homeY
=
0
self
.
homeZ
=
0
self
.
homeZ
=
0
self
.
maxX
=
150
self
.
maxX
=
150
self
.
maxY
=
150
self
.
maxY
=
150
self
.
maxZ
=
150
self
.
maxZ
=
150
self
.
hasHomeX
=
False
self
.
hasHomeY
=
False
self
.
hasHomeZ
=
False
# find a code in a gstring line
# find a code in a gstring line
def
findCode
(
self
,
gcode
,
codeStr
):
def
findCode
(
self
,
gcode
,
codeStr
):
...
@@ -66,112 +69,129 @@ class GCodeAnalyzer():
...
@@ -66,112 +69,129 @@ class GCodeAnalyzer():
m
=
re
.
match
(
pattern
,
gcode
)
m
=
re
.
match
(
pattern
,
gcode
)
if
m
==
None
:
if
m
==
None
:
return
None
return
None
else
else
:
return
m
.
group
(
1
)
return
m
.
group
(
1
)
def
Analyze
(
self
,
gcode
):
def
Analyze
(
self
,
gcode
):
code_g
=
self
.
findCode
(
gcode
,
"G"
)
code_g
=
self
.
findCode
(
gcode
,
"G"
)
code_m
=
self
.
findCode
(
gcode
,
"M"
)
code_m
=
self
.
findCode
(
gcode
,
"M"
)
# we have a g_code
if
code_g
!=
None
:
code_g
=
int
(
code_g
)
#get movement codes
if
code_g
==
0
or
code_g
==
1
or
code_g
==
2
or
code_g
==
3
:
self
.
lastX
=
self
.
x
self
.
lastY
=
self
.
y
self
.
lastZ
=
self
.
z
self
.
lastE
=
self
.
e
eChanged
=
false
;
code_f
=
self
.
findCode
(
gcode
,
"F"
)
if
code_f
!=
None
:
self
.
f
=
float
(
code_f
)
code_x
=
self
.
findCode
(
gcode
,
"X"
)
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
code_e
=
self
.
findCode
(
gcode
,
"E"
)
# we have a g_code
if
self
.
relative
:
if
code_g
!=
None
:
if
code_x
!=
None
:
self
.
x
+=
float
(
code_x
)
code_g
=
int
(
code_g
)
if
code_y
!=
None
:
self
.
y
+=
float
(
code_y
)
if
code_z
!=
None
:
self
.
z
+=
float
(
code_z
)
#get movement codes
if
code_e
!=
None
:
if
code_g
==
0
or
code_g
==
1
or
code_g
==
2
or
code_g
==
3
:
e
=
float
(
code_e
)
eChanged
=
false
;
if
e
!=
0
:
code_f
=
self
.
findCode
(
gcode
,
"F"
)
eChanged
=
True
if
code_f
!=
None
:
self
.
e
+=
e
self
.
f
=
float
(
code_f
)
else
:
#absolute coordinates
code_x
=
self
.
findCode
(
gcode
,
"X"
)
if
code_x
!=
None
:
self
.
x
=
self
.
xOffset
+
float
(
code_x
)
code_y
=
self
.
findCode
(
gcode
.
"Y"
)
if
code_y
!=
None
:
self
.
y
=
self
.
yOffset
+
float
(
code_y
)
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
if
code_z
!=
None
:
self
.
z
=
self
.
zOffset
+
float
(
code_z
)
code_e
=
self
.
findCode
(
gcode
,
"E"
)
if
code_e
!=
None
:
e
=
float
(
code_e
)
if
self
.
relative
:
if
self
.
eRelative
:
if
code_x
!=
None
:
self
.
x
+=
float
(
code_x
)
if
e
!=
0
:
if
code_y
!=
None
:
self
.
y
+=
float
(
code_y
)
eChanged
=
True
if
code_z
!=
None
:
self
.
z
+=
float
(
code_z
)
self
.
e
+=
e
if
code_e
!=
None
:
else
:
e
=
float
(
code_e
)
# e is absolute. Is it changed?
if
e
!=
0
:
if
self
.
e
!=
self
.
eOffset
+
e
:
eChanged
=
True
eChanged
=
True
self
.
e
+=
e
self
.
e
=
self
.
eOffset
+
e
else
:
#Repetier has a bunch of limit-checking code here and time calculations: we are leaving them for now
#absolute coordinates
elif
code_g
==
28
or
code_g
==
161
:
if
code_x
!=
None
:
self
.
x
=
self
.
xOffset
+
float
(
code_x
)
self
.
lastX
=
self
.
x
if
code_y
!=
None
:
self
.
y
=
self
.
yOffset
+
float
(
code_y
)
self
.
lastY
=
self
.
y
if
code_z
!=
None
:
self
.
z
=
self
.
zOffset
+
float
(
code_z
)
self
.
lastZ
=
self
.
z
if
code_e
!=
None
:
self
.
lastE
=
self
.
e
e
=
float
(
code_e
)
code_x
=
self
.
findCode
(
gcode
,
"X"
)
if
self
.
eRelative
:
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
if
e
!=
0
:
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
eChanged
=
True
code_e
=
self
.
findCode
(
gcode
,
"E"
)
self
.
e
+=
e
homeAll
=
False
else
:
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
# e is absolute. Is it changed?
if
code_x
!=
None
or
homeAll
:
if
self
.
e
!=
self
.
eOffset
+
e
:
self
.
hasHomeX
=
True
eChanged
=
True
self
.
xOffset
=
0
self
.
e
=
self
.
eOffset
+
e
self
.
x
=
self
.
homeX
#Repetier has a bunch of limit-checking code here and time calculations: we are leaving them for now
if
code_y
!=
None
or
homeAll
:
self
.
hasHomeY
=
True
elif
code_g
==
28
or
code_g
==
161
:
self
.
yOffset
=
0
code_x
=
self
.
findCode
(
gcode
,
"X"
)
self
.
y
=
self
.
homeY
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
if
code_z
!=
None
or
homeAll
:
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
self
.
hasHomeZ
=
True
code_e
=
self
.
findCode
(
gcode
,
"E"
)
self
.
zOffset
=
0
homeAll
=
False
self
.
z
=
self
.
homeZ
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
if
code_e
!=
None
:
if
code_x
!=
None
or
homeAll
:
self
.
eOffset
=
0
self
.
xOffset
=
0
self
.
e
=
0
self
.
x
=
self
.
homeX
elif
code_g
==
162
:
if
code_y
!=
None
or
homeAll
:
self
.
lastX
=
self
.
x
self
.
yOffset
=
0
self
.
lastY
=
self
.
y
self
.
y
=
self
.
homeY
self
.
lastZ
=
self
.
z
if
code_z
!=
None
or
homeAll
:
self
.
lastE
=
self
.
e
self
.
zOffset
=
0
code_x
=
self
.
findCode
(
gcode
,
"X"
)
self
.
z
=
self
.
homeZ
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
if
code_e
!=
None
:
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
self
.
eOffset
=
0
homeAll
=
False
self
.
e
=
0
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
elif
code_g
==
162
:
if
code_x
!=
None
or
homeAll
:
code_x
=
self
.
findCode
(
gcode
,
"X"
)
self
.
hasHomeX
=
True
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
self
.
xOffset
=
0
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
self
.
x
=
self
.
maxX
homeAll
=
False
if
code_y
!=
None
or
homeAll
:
if
code_x
==
None
and
code_y
==
None
and
code_z
==
None
:
homeAll
=
True
self
.
hasHomeY
=
True
if
code_x
!=
None
or
homeAll
:
self
.
yOffset
=
0
self
.
xOffset
=
0
self
.
y
=
self
.
maxY
self
.
x
=
self
.
maxX
if
code_z
!=
None
or
homeAll
:
if
code_y
!=
None
or
homeAll
:
self
.
hasHomeZ
=
True
self
.
yOffset
=
0
self
.
zOffset
=
0
self
.
y
=
self
.
maxY
self
.
z
=
self
.
maxZ
if
code_z
!=
None
or
homeAll
:
elif
code_g
==
90
:
self
.
relative
=
False
self
.
zOffset
=
0
elif
code_g
==
91
:
self
.
relative
=
True
self
.
z
=
self
.
maxZ
elif
code_g
==
92
:
elif
code_g
==
90
:
self
.
relative
=
False
code_x
=
self
.
findCode
(
gcode
,
"X"
)
elif
code_g
==
91
:
self
.
relative
=
True
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
elif
code_g
==
92
:
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
code_x
=
self
.
findCode
(
gcode
,
"X"
)
code_e
=
self
.
findCode
(
gcode
,
"E"
)
code_y
=
self
.
findCode
(
gcode
,
"Y"
)
if
code_x
!=
None
:
code_z
=
self
.
findCode
(
gcode
,
"Z"
)
self
.
xOffset
=
self
.
x
-
float
(
code_x
)
code_e
=
self
.
findCode
(
gcode
,
"E"
)
self
.
x
=
self
.
xOffset
if
code_x
!=
None
:
if
code_y
!=
None
:
self
.
xOffset
=
self
.
x
-
float
(
code_x
)
self
.
yOffset
=
self
.
y
-
float
(
code_y
)
self
.
x
=
self
.
xOffset
self
.
y
=
self
.
yOffset
if
code_y
!=
None
:
if
code_z
!=
None
:
self
.
yOffset
=
self
.
y
-
float
(
code_y
)
self
.
zOffset
=
self
.
z
-
float
(
code_z
)
self
.
y
=
self
.
yOffset
self
.
z
=
self
.
zOffset
if
code_z
!=
None
:
if
code_e
!=
None
:
self
.
zOffset
=
self
.
z
-
float
(
code_z
)
self
.
xOffset
=
self
.
e
-
float
(
code_e
)
self
.
z
=
self
.
zOffset
self
.
e
=
self
.
eOffset
if
code_e
!=
None
:
self
.
xOffset
=
self
.
e
-
float
(
code_e
)
self
.
e
=
self
.
eOffset
#End code_g != None
#End code_g != None
if
code_m
!=
None
:
if
code_m
!=
None
:
code_m
=
int
(
code_m
)
code_m
=
int
(
code_m
)
if
code_m
==
82
:
self
.
eRelative
=
False
if
code_m
==
82
:
self
.
eRelative
=
False
elif
code_m
==
83
:
self
.
eRelative
=
True
elif
code_m
==
83
:
self
.
eRelative
=
True
\ No newline at end of file
\ No newline at end of file
printcore.py
View file @
6cf08006
...
@@ -20,6 +20,7 @@ from threading import Thread
...
@@ -20,6 +20,7 @@ from threading import Thread
from
select
import
error
as
SelectError
from
select
import
error
as
SelectError
import
time
,
getopt
,
sys
import
time
,
getopt
,
sys
import
platform
,
os
import
platform
,
os
from
GCodeAnalyzer
import
GCodeAnalyzer
def
control_ttyhup
(
port
,
disable_hup
):
def
control_ttyhup
(
port
,
disable_hup
):
"""Controls the HUPCL"""
"""Controls the HUPCL"""
...
@@ -70,6 +71,8 @@ class printcore():
...
@@ -70,6 +71,8 @@ class printcore():
if
port
is
not
None
and
baud
is
not
None
:
if
port
is
not
None
and
baud
is
not
None
:
self
.
connect
(
port
,
baud
)
self
.
connect
(
port
,
baud
)
self
.
analyzer
=
GCodeAnalyzer
()
def
disconnect
(
self
):
def
disconnect
(
self
):
"""Disconnects from printer and pauses the print
"""Disconnects from printer and pauses the print
"""
"""
...
@@ -335,6 +338,7 @@ class printcore():
...
@@ -335,6 +338,7 @@ class printcore():
self
.
sentlines
[
lineno
]
=
command
self
.
sentlines
[
lineno
]
=
command
if
self
.
printer
:
if
self
.
printer
:
self
.
sent
.
append
(
command
)
self
.
sent
.
append
(
command
)
self
.
analyzer
.
Analyze
(
command
)
# run the command through the analyzer
if
self
.
loud
:
if
self
.
loud
:
print
"SENT: "
,
command
print
"SENT: "
,
command
if
self
.
sendcb
:
if
self
.
sendcb
:
...
...
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