0
# Instance Management
1
2
Core NetworkTables instance functionality for connection management, server operations, and global configuration. Provides both singleton access and support for multiple independent instances for complex applications.
3
4
## Capabilities
5
6
### Instance Creation and Access
7
8
Create and access NetworkTables instances for connection management.
9
10
```python { .api }
11
class NetworkTablesInstance:
12
@classmethod
13
def getDefault() -> NetworkTablesInstance:
14
"""
15
Get the global singleton NetworkTables instance.
16
17
Returns:
18
NetworkTablesInstance: The default global instance
19
"""
20
21
@classmethod
22
def create() -> NetworkTablesInstance:
23
"""
24
Create a new independent NetworkTables instance.
25
26
Returns:
27
NetworkTablesInstance: New instance completely independent from others
28
"""
29
```
30
31
### Connection Management
32
33
Initialize and manage NetworkTables connections as client or server.
34
35
```python { .api }
36
def initialize(server=None):
37
"""
38
Initialize NetworkTables. Call this before any other NT operations.
39
40
Parameters:
41
- server: str or list, optional. Server address(es) to connect to as client.
42
If None, operates in standalone mode.
43
"""
44
45
def startClient(server_or_servers):
46
"""
47
Start NetworkTables client and connect to server(s).
48
49
Parameters:
50
- server_or_servers: str or list. Server address or list of addresses to connect to
51
"""
52
53
def startClientTeam(team: int, port: int = 1735):
54
"""
55
Start NetworkTables client using FRC team number for server discovery.
56
57
Parameters:
58
- team: int. FRC team number (e.g., 1234 for team 1234)
59
- port: int. Port number (default: 1735)
60
"""
61
62
def startDSClient(port: int = 1735):
63
"""
64
Start NetworkTables client and connect to Driver Station.
65
66
Parameters:
67
- port: int. Port number (default: 1735)
68
"""
69
70
def setServer(server_or_servers):
71
"""
72
Set server address(es) without connecting immediately.
73
74
Parameters:
75
- server_or_servers: str or list. Server address or list of addresses
76
"""
77
78
def setServerTeam(team: int, port: int = 1735):
79
"""
80
Set server using FRC team number without connecting immediately.
81
82
Parameters:
83
- team: int. FRC team number
84
- port: int. Port number (default: 1735)
85
"""
86
87
def stopClient():
88
"""Stop NetworkTables client and disconnect from server."""
89
90
def isConnected() -> bool:
91
"""
92
Check if NetworkTables is connected to a server.
93
94
Returns:
95
bool: True if connected, False otherwise
96
"""
97
98
def getConnections() -> List[dict]:
99
"""
100
Get information about current connections.
101
102
Returns:
103
List[dict]: Connection information including remote addresses and protocol versions
104
"""
105
106
def getRemoteAddress() -> Optional[str]:
107
"""
108
Get the remote address if connected as client.
109
110
Returns:
111
Optional[str]: Remote server address, or None if server or not connected
112
"""
113
114
def getNetworkMode() -> int:
115
"""
116
Get the current network mode.
117
118
Returns:
119
int: Bitmask of current network modes (SERVER, CLIENT, STARTING, etc.)
120
"""
121
122
def isServer() -> bool:
123
"""
124
Check if running in server mode.
125
126
Returns:
127
bool: True if configured as server, False otherwise
128
"""
129
```
130
131
### Server Operations
132
133
Start and manage NetworkTables server for hosting data.
134
135
```python { .api }
136
def startServer(persistFilename: str = "networktables.ini",
137
listenAddress: str = "",
138
port: int = 1735):
139
"""
140
Start NetworkTables server to host data for clients.
141
142
Parameters:
143
- persistFilename: str. File to load/save persistent entries (default: "networktables.ini")
144
- listenAddress: str. Network interface to listen on (default: "" for all interfaces)
145
- port: int. Port number to listen on (default: 1735)
146
"""
147
148
def stopServer():
149
"""Stop NetworkTables server."""
150
```
151
152
### Global Operations
153
154
Control global NetworkTables behavior and lifecycle.
155
156
```python { .api }
157
def shutdown():
158
"""
159
Stop all NetworkTables activity (client, server, listeners).
160
After calling this, NetworkTables must be reinitialized.
161
"""
162
163
def flush():
164
"""
165
Force immediate network update of all pending changes.
166
Normally updates are sent automatically at regular intervals.
167
"""
168
169
def setUpdateRate(interval: float):
170
"""
171
Set the network update rate in seconds.
172
173
Parameters:
174
- interval: float. Time interval in seconds between network updates (default: 0.1)
175
"""
176
177
def setNetworkIdentity(name: str):
178
"""
179
Set the network identity for this instance.
180
181
Parameters:
182
- name: str. Identity name used in connection handshake
183
"""
184
185
def startTestMode(server: bool = True):
186
"""
187
Start NetworkTables in test mode for unit testing.
188
189
Parameters:
190
- server: bool. Whether to start as server (default: True)
191
"""
192
193
def enableVerboseLogging():
194
"""Enable verbose logging for debugging NetworkTables issues."""
195
196
def waitForEntryListenerQueue(timeout: float) -> bool:
197
"""
198
Wait for entry listener queue to be empty (for testing).
199
200
Parameters:
201
- timeout: float. Maximum time to wait in seconds
202
203
Returns:
204
bool: True if queue emptied, False if timeout
205
"""
206
207
def waitForConnectionListenerQueue(timeout: float) -> bool:
208
"""
209
Wait for connection listener queue to be empty (for testing).
210
211
Parameters:
212
- timeout: float. Maximum time to wait in seconds
213
214
Returns:
215
bool: True if queue emptied, False if timeout
216
"""
217
```
218
219
### Entry and Table Access
220
221
Access entries and tables from the instance level.
222
223
```python { .api }
224
def getEntry(name: str) -> NetworkTableEntry:
225
"""
226
Get a NetworkTable entry by full path.
227
228
Parameters:
229
- name: str. Full path to entry (e.g., "/SmartDashboard/speed")
230
231
Returns:
232
NetworkTableEntry: Entry object for type-safe value access
233
"""
234
235
def getEntries(prefix: str, types: int = 0) -> List[NetworkTableEntry]:
236
"""
237
Get all entries with names starting with the given prefix.
238
239
Parameters:
240
- prefix: str. Path prefix to match (e.g., "/SmartDashboard/")
241
- types: int. Bitmask of entry types to include (default: 0 for all types)
242
243
Returns:
244
List[NetworkTableEntry]: List of matching entries
245
"""
246
247
def getTable(key: str) -> NetworkTable:
248
"""
249
Get a NetworkTable by path.
250
251
Parameters:
252
- key: str. Table path (e.g., "SmartDashboard", "/Vision")
253
254
Returns:
255
NetworkTable: Table object for key-value operations
256
"""
257
258
def getGlobalTable() -> NetworkTable:
259
"""
260
Get the root table (equivalent to getTable("/")).
261
262
Returns:
263
NetworkTable: The root table containing all entries
264
"""
265
266
def getGlobalAutoUpdateValue(key: str, defaultValue, writeDefault: bool) -> NetworkTableEntry:
267
"""
268
Get an auto-updating entry from global scope.
269
270
Parameters:
271
- key: str. Full path to entry
272
- defaultValue: Any. Default value if entry doesn't exist
273
- writeDefault: bool. Whether to write default value to table
274
275
Returns:
276
NetworkTableEntry: Auto-updating entry object
277
"""
278
```
279
280
### Entry Management
281
282
Manage entries across the entire NetworkTables instance.
283
284
```python { .api }
285
def deleteAllEntries():
286
"""Delete all entries in this NetworkTables instance."""
287
288
def getEntryInfo(prefix: str, types: int = 0) -> List[tuple]:
289
"""
290
Get information about entries matching the prefix.
291
292
Parameters:
293
- prefix: str. Path prefix to match
294
- types: int. Bitmask of entry types to include (default: 0 for all types)
295
296
Returns:
297
List[tuple]: List of (name, type, flags) tuples for matching entries
298
"""
299
```
300
301
## Usage Examples
302
303
### Basic Client Setup
304
305
```python
306
from networktables import NetworkTables
307
308
# Connect to robot using team number
309
NetworkTables.initialize()
310
NetworkTables.startClientTeam(1234)
311
312
# Wait for connection
313
import time
314
while not NetworkTables.isConnected():
315
time.sleep(0.1)
316
317
print("Connected to robot!")
318
```
319
320
### Server Setup
321
322
```python
323
from networktables import NetworkTables
324
325
# Start as server for testing or coprocessor use
326
NetworkTables.initialize()
327
NetworkTables.startServer()
328
329
print("NetworkTables server started on port 1735")
330
```
331
332
### Multiple Instances
333
334
```python
335
from networktables import NetworkTablesInstance
336
337
# Create separate instances for different purposes
338
robot_nt = NetworkTablesInstance.create()
339
vision_nt = NetworkTablesInstance.create()
340
341
# Configure robot connection
342
robot_nt.startClientTeam(1234)
343
344
# Configure vision processing server
345
vision_nt.startServer(port=1736)
346
```
347
348
## Constants
349
350
```python { .api }
351
# Network modes
352
class NetworkModes:
353
NONE = 0
354
SERVER = 1
355
CLIENT = 2
356
STARTING = 3
357
FAILURE = 4
358
TEST = 5
359
360
# Default values
361
PATH_SEPARATOR = "/"
362
DEFAULT_PORT = 1735
363
```