mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Initial commit of Java wrappers.
The JNI bindings are built directly into the shared library. In the gradle build, all built shared libraries are embedded into the generated jar. Java bindings may be disabled via -DWITHOUT_JAVA (cmake) or -PskipJava=true (gradle). TODO: - getEntryInfo() and RPC are not yet implemented. - The cmake build doesn't integrate the built objects into the jar. - The Java client and server tests are not built (but have been manually tested). This has not yet been tested on Windows.
This commit is contained in:
39
java/test/Client.java
Normal file
39
java/test/Client.java
Normal file
@@ -0,0 +1,39 @@
|
||||
import edu.wpi.first.wpilibj.networktables.*;
|
||||
import edu.wpi.first.wpilibj.tables.*;
|
||||
|
||||
public class Client {
|
||||
private static class MyLogger implements NetworkTablesJNI.LoggerFunction {
|
||||
public void apply(int level, String file, int line, String msg) {
|
||||
System.err.println(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
NetworkTablesJNI.setLogger(new MyLogger(), 0);
|
||||
NetworkTable.setIPAddress("127.0.0.1");
|
||||
NetworkTable.setPort(10000);
|
||||
NetworkTable.setClientMode();
|
||||
NetworkTable nt = NetworkTable.getTable("");
|
||||
try { Thread.sleep(2000); } catch (InterruptedException e) {}
|
||||
try {
|
||||
System.out.println("Got foo: " + nt.getNumber("foo"));
|
||||
} catch(TableKeyNotDefinedException ex) {
|
||||
}
|
||||
nt.putBoolean("bar", false);
|
||||
nt.setFlags("bar", NetworkTable.PERSISTENT);
|
||||
nt.putBoolean("bar2", true);
|
||||
nt.putBoolean("bar2", false);
|
||||
nt.putBoolean("bar2", true);
|
||||
nt.putString("str", "hello world");
|
||||
double[] nums = new double[3];
|
||||
nums[0] = 0.5;
|
||||
nums[1] = 1.2;
|
||||
nums[2] = 3.0;
|
||||
nt.putNumberArray("numarray", nums);
|
||||
String[] strs = new String[2];
|
||||
strs[0] = "Hello";
|
||||
strs[1] = "World";
|
||||
nt.putStringArray("strarray", strs);
|
||||
try { Thread.sleep(10000); } catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user