-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.py
executable file
·39 lines (29 loc) · 971 Bytes
/
listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
#
# This is a NetworkTables client (eg, the DriverStation/coprocessor side).
# You need to tell it the IP address of the NetworkTables server (the
# robot or simulator).
#
# This shows how to use a listener to listen for changes in NetworkTables
# values. This will print out any changes detected on the SmartDashboard
# table.
#
import sys
import time
from networktables import NetworkTable
# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)
if len(sys.argv) != 2:
print("Error: specify an IP to connect to!")
exit(0)
ip = sys.argv[1]
NetworkTable.setIPAddress(ip)
NetworkTable.setClientMode()
NetworkTable.initialize()
def valueChanged(table, key, value, isNew):
print("valueChanged: key: '%s'; value: %s; isNew: %s" % (key, value, isNew))
sd = NetworkTable.getTable("SmartDashboard")
sd.addTableListener(valueChanged)
while True:
time.sleep(1)