Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibLaserCut
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Elektronikföreningen Admittansen
LibLaserCut
Commits
523bf1b2
Commit
523bf1b2
authored
9 years ago
by
Thomas Oster
Browse files
Options
Downloads
Patches
Plain Diff
Wait for "ok" after every line in interactive mode
parent
c0bf88f6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/com/t_oster/liblasercut/drivers/SmoothieBoard.java
+43
-34
43 additions, 34 deletions
src/com/t_oster/liblasercut/drivers/SmoothieBoard.java
with
43 additions
and
34 deletions
src/com/t_oster/liblasercut/drivers/SmoothieBoard.java
+
43
−
34
View file @
523bf1b2
...
...
@@ -20,10 +20,7 @@ package com.t_oster.liblasercut.drivers;
import
com.t_oster.liblasercut.*
;
import
com.t_oster.liblasercut.platform.Util
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.PrintStream
;
...
...
@@ -97,7 +94,7 @@ public class SmoothieBoard extends LaserCutter {
return
new
PowerSpeedFocusProperty
();
}
pr
ivate
void
writeVectorGCode
(
PrintStream
out
,
VectorPart
vp
,
double
resolution
)
throws
UnsupportedEncodingException
{
pr
otected
void
writeVectorGCode
(
VectorPart
vp
,
double
resolution
)
throws
UnsupportedEncodingException
,
IOException
{
for
(
VectorCommand
cmd
:
vp
.
getCommandList
())
{
switch
(
cmd
.
getType
())
{
case
MOVETO:
...
...
@@ -125,57 +122,70 @@ public class SmoothieBoard extends LaserCutter {
private
double
nextSpeed
=
-
1
;
private
double
currentFocus
=
0
;
pr
ivate
void
setSpeed
(
double
speedInPercent
)
{
pr
otected
void
setSpeed
(
double
speedInPercent
)
{
nextSpeed
=
speedInPercent
;
}
pr
ivate
void
setPower
(
double
powerInPercent
)
{
pr
otected
void
setPower
(
double
powerInPercent
)
{
nextPower
=
powerInPercent
;
}
pr
ivate
void
setFocus
(
PrintStream
out
,
double
focus
,
double
resolution
)
{
pr
otected
void
setFocus
(
PrintStream
out
,
double
focus
,
double
resolution
)
throws
IOException
{
if
(
currentFocus
!=
focus
)
{
out
.
printf
(
Locale
.
US
,
"G0 Z%f"
+
LINEEND
,
Util
.
px2mm
(
focus
,
resolution
));
sendLine
(
"G0 Z%f"
,
Util
.
px2mm
(
focus
,
resolution
));
currentFocus
=
focus
;
}
}
pr
ivate
void
move
(
PrintStream
out
,
int
x
,
int
y
,
double
resolution
)
{
out
.
printf
(
Locale
.
US
,
"G0 X%f Y%f"
+
LINEEND
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
));
pr
otected
void
move
(
PrintStream
out
,
int
x
,
int
y
,
double
resolution
)
throws
IOException
{
sendLine
(
"G0 X%f Y%f"
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
));
}
pr
ivate
void
line
(
PrintStream
out
,
int
x
,
int
y
,
double
resolution
)
{
out
.
printf
(
Locale
.
US
,
"G1 X%f Y%f"
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
))
;
pr
otected
void
line
(
PrintStream
out
,
int
x
,
int
y
,
double
resolution
)
throws
IOException
{
String
append
=
""
;
if
(
nextPower
!=
currentPower
)
{
out
.
printf
(
Locale
.
US
,
" S%f"
,
nextPower
);
append
+=
String
.
format
(
Locale
.
US
,
" S%f"
,
nextPower
);
currentPower
=
nextPower
;
}
if
(
nextSpeed
!=
currentSpeed
)
{
out
.
printf
(
Locale
.
US
,
" F%d"
,
(
int
)
(
max_speed
*
nextSpeed
/
100.0
));
append
+=
String
.
format
(
Locale
.
US
,
" F%d"
,
(
int
)
(
max_speed
*
nextSpeed
/
100.0
));
currentSpeed
=
nextSpeed
;
}
out
.
printf
(
Locale
.
US
,
LINEEND
);
sendLine
(
"G1 X%f Y%f"
+
append
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
)
);
}
private
void
writeInitializationCode
(
PrintStream
out
)
{
out
.
pr
in
t
(
"G21"
+
LINEEND
);
//units to mm
out
.
pr
in
t
(
"G
90"
+
LINEEND
);
//following coordinates are absolute
//out.pr
in
t
("G
0 X0 Y0"+LINEEND);//move to 0 0
private
void
writeInitializationCode
(
)
throws
IOException
{
sendL
in
e
(
"G21"
);
sendL
in
e
(
"G
21"
);
//units to mm
sendL
in
e
(
"G
90"
);
//following coordinates are absolute
}
private
void
writeShutdownCode
(
PrintStream
out
)
{
private
void
writeShutdownCode
(
)
throws
IOException
{
//back to origin and shutdown
//out.pr
in
t
("G0 X0 Y0
\n
");
//move to 0 0
sendL
in
e
(
"G0 X0 Y0"
);
}
private
Buffered
InputStream
in
;
private
BufferedOutpu
tStream
out
;
private
Buffered
Reader
in
;
private
Prin
tStream
out
;
private
Socket
socket
;
private
CommPort
port
;
private
CommPortIdentifier
portIdentifier
;
private
boolean
waitForOKafterEachLine
=
true
;
protected
void
sendLine
(
String
text
,
Object
...
parameters
)
throws
IOException
{
out
.
format
(
text
+
LINEEND
,
parameters
);
if
(
waitForOKafterEachLine
)
{
if
(!
"ok"
.
equals
(
in
.
readLine
()))
{
throw
new
IOException
(
"Smoothieboard did not respond 'ok'"
);
}
}
}
protected
String
connect_serial
(
CommPortIdentifier
i
,
ProgressListener
pl
)
throws
PortInUseException
,
IOException
{
...
...
@@ -185,10 +195,9 @@ public class SmoothieBoard extends LaserCutter {
try
{
port
=
i
.
open
(
"VisiCut"
,
1000
);
in
=
new
BufferedInputStream
(
port
.
getInputStream
());
out
=
new
BufferedOutputStream
(
port
.
getOutputStream
());
BufferedReader
rd
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
String
line
=
rd
.
readLine
();
out
=
new
PrintStream
(
port
.
getOutputStream
(),
true
,
"US-ASCII"
);
in
=
new
BufferedReader
(
new
InputStreamReader
(
port
.
getInputStream
()));
String
line
=
in
.
readLine
();
if
(!
"Smoothie"
.
equals
(
line
))
{
in
.
close
();
...
...
@@ -257,8 +266,8 @@ public class SmoothieBoard extends LaserCutter {
{
socket
=
new
Socket
();
socket
.
connect
(
new
InetSocketAddress
(
this
.
host
,
23
),
1000
);
in
=
new
BufferedInputStream
(
socket
.
getInputStream
());
out
=
new
BufferedOutpu
tStream
(
socket
.
getOutputStream
());
in
=
new
Buffered
Reader
(
new
InputStream
Reader
(
socket
.
getInputStream
())
)
;
out
=
new
Prin
tStream
(
socket
.
getOutputStream
()
,
true
,
"US-ASCII"
);
}
}
...
...
@@ -290,8 +299,7 @@ public class SmoothieBoard extends LaserCutter {
pl
.
taskChanged
(
this
,
"connecting..."
);
connect
(
pl
);
pl
.
taskChanged
(
this
,
"sending"
);
PrintStream
printstream
=
new
PrintStream
(
out
,
true
,
"US-ASCII"
);
writeInitializationCode
(
printstream
);
writeInitializationCode
();
pl
.
progressChanged
(
this
,
20
);
int
i
=
0
;
int
max
=
job
.
getParts
().
size
();
...
...
@@ -303,13 +311,14 @@ public class SmoothieBoard extends LaserCutter {
}
if
(
p
instanceof
VectorPart
)
{
writeVectorGCode
(
printstream
,
(
VectorPart
)
p
,
p
.
getDPI
());
//TODO: in direct mode use progress listener to indicate progress
//of individual job
writeVectorGCode
((
VectorPart
)
p
,
p
.
getDPI
());
}
i
++;
pl
.
progressChanged
(
this
,
20
+
(
int
)
(
i
*(
double
)
60
/
max
));
}
writeShutdownCode
(
printstream
);
printstream
.
flush
();
writeShutdownCode
();
disconnect
();
pl
.
taskChanged
(
this
,
"sent."
);
pl
.
progressChanged
(
this
,
100
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment