First, I want to point out that the old API still works. But if you want to switch over to the new API, here’s a simple Java client example:
package networktablesdesktopclient;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
public class NetworkTablesDesktopClient {
public static void main(String] args) {
new NetworkTablesDesktopClient().run();
}
public void run() {
NetworkTableInstance inst = NetworkTableInstance.getDefault();
NetworkTable table = inst.getTable("datatable");
NetworkTableEntry xEntry = table.getEntry("x");
NetworkTableEntry yEntry = table.getEntry("y");
inst.startClientTeam(TEAM); // where TEAM=190, 294, etc, or use inst.startClient("hostname") or similar
inst.startDSClient(); // recommended if running on DS computer; this gets the robot IP from the DS
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
System.out.println("interrupted");
return;
}
double x = xEntry.getDouble(0.0);
doubly y = yEntry.getDouble(0.0);
System.out.println("X: " + x + " Y: " + y);
}
}
}
If you’re looking to get values just inside of a subsystem etc. read through this. I made this for grabbing values from the limelight/changing values, so I hope it can be of use and help explain some stuff.
I created an application using Peter’s code above but when it runs I get the error below. I made two changes to the code to add my team number and fix the “doubly” typo near the end. I referenced the following library which resolves the NetworkTable references but I assume this is my mistake.
C:\Users\kingb\wpilib\java\current\lib
tcore.jar
Don’t I need the client (PC) side version of this library? I believe the one above is for the RoboRIO.
Assuming this is my problem, does anyone know where the correct library/jar is located?
Thanks
Exception in thread “main” java.lang.NoClassDefFoundError: edu/wpi/first/wpiutil/RuntimeDetector
at edu.wpi.first.networktables.NetworkTablesJNI.<clinit>(NetworkTablesJNI.java:27)
at edu.wpi.first.networktables.NetworkTableInstance.getDefault(NetworkTableInstance.java:88)
at networktablesdesktopclient.NetworkTablesDesktopClient.run(NetworkTablesDesktopClient.java:13)
at networktablesdesktopclient.NetworkTablesDesktopClient.main(NetworkTablesDesktopClient.java:9)
Caused by: java.lang.ClassNotFoundException: edu.wpi.first.wpiutil.RuntimeDetector
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 4 more
That’s correct, the jar in the plugins is for the RoboRIO, and you were also missing the wpiutil jar. You’ll need the following 3 jar files for desktop use: