Created
May 20, 2023 19:55
-
-
Save kongmunist/9e2836ffe7164d37ab3906833f88707c to your computer and use it in GitHub Desktop.
Serial Logging class written for Java/Processing, integrates cleanly on UNIX/MacOS since it relies on unix style system commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SerialLogger { | |
public String portname; | |
public String filename; | |
public Process p; | |
SerialLogger(String portname, String filename) { | |
this.portname = portname; | |
this.filename = sketchPath() + "/data/" + filename + ".csv"; | |
} | |
void beginRecording() { | |
ProcessBuilder builder = new ProcessBuilder("cat", portname); | |
builder.redirectOutput(new File(this.filename)); | |
try { | |
p = builder.start(); // may throw IOException | |
} | |
catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
void endRecording() { | |
p.destroyForcibly(); | |
} | |
void beginStreaming(){ | |
exec("sh", "-c", "echo a > " + portname); | |
} | |
void endStreaming(){ | |
exec("sh", "-c", "echo a > " + portname); | |
} | |
void begin(){ | |
beginStreaming(); | |
beginRecording(); | |
} | |
void end(){ | |
endStreaming(); | |
endRecording(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment