Listening for value changes

A common use case for NetworkTables is where a program on the Driver Station generates values that need to be sent to the robot. For example, imagine that some image processing code running on the Driver Station computes the heading and distance to a goal and sends those values to the robot. In this case it might be desirable for the robot program to be notified when new values arrive from the Driver Station. NetworkTables provides facilities to do that.

Using a NetworkTable EntryListener

One of the more common cases for NetworkTables is waiting for a value to change on the robot. This is called an EntryListener because it notifies the robot program when a network table entry (single value) changes. The following code shows how to do this.

  1. Get the default instance of NetworkTables.
  2. Get an reference to the subtable containing the keys that are to be watched for changes.
  3. Get a reference to the Entry object the the particular key ("Y") that should be watched.
  4. Add an EntryListener for changed values of "X". The lambda ("->" operator) defines the code that should run when "X" changes.
  5. Add an EntryListener for changed values of "Y". The lambda defines the code that should run when the value of "Y" changes.

0 Report Errors

Use this form to report any errors with the documentation. For help with WPILib, please use the FIRST Forums at http://forums.usfirst.org For reporting WPILib bugs, please submit an issue on GitHub at https://github.com/wpilibsuite/allwpilib/issues/new

Ignore