Skip to content
Snippets Groups Projects
Commit 7fe600e5 authored by Thomas Oster's avatar Thomas Oster
Browse files

Fix: HTTP Upload, Smoothie specific identification line.

parent 5eafb648
No related branches found
No related tags found
No related merge requests found
...@@ -315,12 +315,10 @@ public class GenericGcodeDriver extends LaserCutter { ...@@ -315,12 +315,10 @@ public class GenericGcodeDriver extends LaserCutter {
out.flush(); out.flush();
if (isWaitForOKafterEachLine()) if (isWaitForOKafterEachLine())
{ {
String line = in.readLine(); String line = waitForLine();
//TODO: Remove
System.out.println("< "+line);
if (!"ok".equals(line)) if (!"ok".equals(line))
{ {
throw new IOException("Lasercutter did not respond 'ok'"); throw new IOException("Lasercutter did not respond 'ok', but '"+line+"'instead.");
} }
} }
} }
...@@ -334,6 +332,37 @@ public class GenericGcodeDriver extends LaserCutter { ...@@ -334,6 +332,37 @@ public class GenericGcodeDriver extends LaserCutter {
{ {
throw new IOException("Error during POST Request"); throw new IOException("Error during POST Request");
} }
System.out.println("Response: "+response.toString());//TODO: Remove
}
protected String waitForLine() throws IOException
{
String line = "";
while ("".equals(line))
{//skip empty lines
line = in.readLine();
}
System.out.println("< "+line);//TODO: remove
return line;
}
/**
* Waits for the Identification line and returns null if it's allright
* Otherwise it returns the wrong line
* @return
* @throws IOException
*/
protected String waitForIdentificationLine() throws IOException
{
if (getIdentificationLine() != null && getIdentificationLine().length() > 0)
{
String line = waitForLine();
if (!getIdentificationLine().equals(line))
{
return line;
}
}
return null;
} }
protected String connect_serial(CommPortIdentifier i, ProgressListener pl) throws PortInUseException, IOException, UnsupportedCommOperationException protected String connect_serial(CommPortIdentifier i, ProgressListener pl) throws PortInUseException, IOException, UnsupportedCommOperationException
...@@ -351,17 +380,12 @@ public class GenericGcodeDriver extends LaserCutter { ...@@ -351,17 +380,12 @@ public class GenericGcodeDriver extends LaserCutter {
} }
out = new PrintStream(port.getOutputStream(), true, "US-ASCII"); out = new PrintStream(port.getOutputStream(), true, "US-ASCII");
in = new BufferedReader(new InputStreamReader(port.getInputStream())); in = new BufferedReader(new InputStreamReader(port.getInputStream()));
if (getIdentificationLine() != null && getIdentificationLine().length() > 0) if (waitForIdentificationLine() != null)
{ {
in.close();
String line = in.readLine(); out.close();
if (!getIdentificationLine().equals(line)) port.close();
{ return "Does not seem to be a "+getModelName()+" on "+i.getName();
in.close();
out.close();
port.close();
return ("Does not seem to be a smoothieboard on "+i.getName());
}
} }
portIdentifier = i; portIdentifier = i;
return null; return null;
...@@ -397,6 +421,13 @@ public class GenericGcodeDriver extends LaserCutter { ...@@ -397,6 +421,13 @@ public class GenericGcodeDriver extends LaserCutter {
socket.connect(new InetSocketAddress(getHost(), 23), 1000); socket.connect(new InetSocketAddress(getHost(), 23), 1000);
in = new BufferedReader(new InputStreamReader(socket.getInputStream())); in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintStream(socket.getOutputStream(), true, "US-ASCII"); out = new PrintStream(socket.getOutputStream(), true, "US-ASCII");
String line = waitForIdentificationLine();
if (line != null)
{
in.close();
out.close();
throw new IOException("Wrong identification Line: "+line+"\n instead of "+getIdentificationLine());
}
} }
else if (getComport() != null && !getComport().equals("")) else if (getComport() != null && !getComport().equals(""))
{ {
...@@ -444,12 +475,12 @@ public class GenericGcodeDriver extends LaserCutter { ...@@ -444,12 +475,12 @@ public class GenericGcodeDriver extends LaserCutter {
} }
} }
protected void disconnect() throws IOException, URISyntaxException protected void disconnect(String jobname) throws IOException, URISyntaxException
{ {
if (outputBuffer != null) if (outputBuffer != null)
{ {
out.close(); out.close();
http_upload(new URI(getHttpUploadUrl()), outputBuffer.toString("UTF-8"), "VisiCut.gcode"); http_upload(new URI(getHttpUploadUrl()), outputBuffer.toString("UTF-8"), jobname);
} }
else else
{ {
...@@ -505,7 +536,7 @@ public class GenericGcodeDriver extends LaserCutter { ...@@ -505,7 +536,7 @@ public class GenericGcodeDriver extends LaserCutter {
pl.progressChanged(this, 20 + (int) (i*(double) 60/max)); pl.progressChanged(this, 20 + (int) (i*(double) 60/max));
} }
writeShutdownCode(); writeShutdownCode();
disconnect(); disconnect(job.getName()+".gcode");
pl.taskChanged(this, "sent."); pl.taskChanged(this, "sent.");
pl.progressChanged(this, 100); pl.progressChanged(this, 100);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
**/ **/
package com.t_oster.liblasercut.drivers; package com.t_oster.liblasercut.drivers;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -37,7 +38,32 @@ public class SmoothieBoard extends GenericGcodeDriver { ...@@ -37,7 +38,32 @@ public class SmoothieBoard extends GenericGcodeDriver {
setBaudRate(115200); setBaudRate(115200);
setLineend("CRLF"); setLineend("CRLF");
} }
@Override
public String getIdentificationLine()
{
if (getHost() == null || "".equals(getHost()))
{
return "Smoothie";
}
else
{
return "Smoothie command shell";
}
}
@Override
protected String waitForLine() throws IOException
{
String line = super.waitForLine();
//The telnet interface for smoothie prepends lines with '> '
if (getHost() != null && !"".equals(getHost()) && line.startsWith("> "))
{
return line.substring(2);
}
return line;
}
@Override @Override
public String[] getPropertyKeys() public String[] getPropertyKeys()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment