Created
February 17, 2016 09:24
-
-
Save PeterJohnson/c74375e46003602cb097 to your computer and use it in GitHub Desktop.
This file contains 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 edu.wpi.first.wpilibj.networktables.*; | |
import edu.wpi.first.wpilibj.tables.*; | |
public class Listener { | |
private static class MyListener implements ITableListener { | |
public void valueChanged(ITable source, String key, Object value, boolean isNew) { | |
System.out.println("value changed: " + key + " isNew=" + isNew); | |
} | |
} | |
public static void main(String[] args) { | |
NetworkTable.setIPAddress("127.0.0.1"); | |
NetworkTable.setPort(10000); | |
NetworkTable.setServerMode(); | |
NetworkTable nt = NetworkTable.getTable(""); | |
MyListener listener = new MyListener(); | |
nt.addTableListener(listener); | |
//nt.addTableListenerEx(listener, nt.NOTIFY_NEW|nt.NOTIFY_UPDATE|nt.NOTIFY_LOCAL); | |
try { Thread.sleep(1000); } catch (InterruptedException e) {} | |
nt.putNumber("foo", 0.5); | |
nt.setFlags("foo", NetworkTable.PERSISTENT); | |
nt.putNumber("foo2", 0.5); | |
nt.putNumber("foo2", 0.7); | |
nt.putNumber("foo2", 0.6); | |
nt.putNumber("foo2", 0.5); | |
try { Thread.sleep(10000); } catch (InterruptedException e) {} | |
} | |
} |
This file contains 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 edu.wpi.first.wpilibj.networktables.*; | |
import edu.wpi.first.wpilibj.tables.*; | |
public class ListenerClient { | |
private static class MyListener implements ITableListener { | |
public void valueChanged(ITable source, String key, Object value, boolean isNew) { | |
System.out.println("value changed: " + key + " isNew=" + isNew); | |
} | |
} | |
public static void main(String[] args) { | |
NetworkTable.setIPAddress("127.0.0.1"); | |
NetworkTable.setPort(10000); | |
NetworkTable.setClientMode(); | |
NetworkTable nt = NetworkTable.getTable(""); | |
MyListener listener = new MyListener(); | |
nt.addTableListener(listener); | |
//nt.addTableListenerEx(listener, nt.NOTIFY_NEW|nt.NOTIFY_UPDATE|nt.NOTIFY_LOCAL); | |
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) {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment