Skip to content

Instantly share code, notes, and snippets.

@madhephaestus
Last active April 7, 2020 20:33
Show Gist options
  • Save madhephaestus/489b5cdd5efd380316927904974097ae to your computer and use it in GitHub Desktop.
Save madhephaestus/489b5cdd5efd380316927904974097ae to your computer and use it in GitHub Desktop.
serialTest.groovy
/serialTest.class
/.classpath
/.project
import gnu.io.NRSerialPort
String port = "";
for(String s:NRSerialPort.getAvailableSerialPorts()){
System.out.println("Availible port: "+s);
port=s;
}
int baudRate = 115200;
NRSerialPort serial = new NRSerialPort(port, baudRate);
serial.connect();
DataInputStream ins = new DataInputStream(serial.getInputStream());
DataOutputStream outs = new DataOutputStream(serial.getOutputStream());
try{
//while(ins.available()==0 && !Thread.interrupted());// wait for a byte
while(!Thread.interrupted()) {// read all bytes
if(ins.available()>0) {
char b = ins.read();
//outs.write((byte)b);
print(b);
}
Thread.sleep(5)
}
}catch(Exception ex){
ex.printStackTrace()
}
serial.disconnect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment