Last active
April 7, 2020 20:33
-
-
Save madhephaestus/489b5cdd5efd380316927904974097ae to your computer and use it in GitHub Desktop.
serialTest.groovy
This file contains hidden or 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
/serialTest.class | |
/.classpath | |
/.project |
This file contains hidden or 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
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