Inital test (from beerduino, https://github.com/ilyevsky/beerduino) to establish protocol buffer communication between java and arduino powered by purejavacomm (https://github.com/nyholku/purejavacomm).
This commit is contained in:
35
src/main/java/test/Test.java
Normal file
35
src/main/java/test/Test.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package test;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
import beerduino.Beerduino.Echo;
|
||||
import beerduino.Beerduino.Ping;
|
||||
|
||||
public class Test implements EchoListener {
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
new Test().start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void start() throws Exception {
|
||||
Arduino arduino = new Arduino();
|
||||
arduino.connect();
|
||||
arduino.addListener(this);
|
||||
OutputStream outputStream = arduino.getOutputStream();
|
||||
int i = 123;
|
||||
while ( i < 10000) {
|
||||
Ping ping = Ping.newBuilder().setId(i++).build();
|
||||
System.out.println("writing!");
|
||||
ping.writeDelimitedTo(outputStream);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
arduino.close();
|
||||
}
|
||||
|
||||
public void receive(Echo echo) {
|
||||
System.out.println("> " + echo.getMessage() + " " + echo.getId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user