-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables_testing.py
More file actions
43 lines (35 loc) · 1.21 KB
/
tables_testing.py
File metadata and controls
43 lines (35 loc) · 1.21 KB
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
40
41
42
43
import time
import threading
import logging
from networktables import NetworkTables
# Initialize NetworkTables
NetworkTables.initialize(server='localhost')
# Create a table for testing
table = NetworkTables.getTable('TestTable')
# Function to send data to NetworkTables
def send_data():
while True:
# Send some data (e.g., a timestamp)
timestamp = time.time()
table.putNumber('Timestamp', 20)
print(f'Sent: Timestamp={20}')
time.sleep(1)
# Function to receive data from NetworkTables
def receive_data():
while True:
# Get data from NetworkTables
data = table.getNumber('Timestamp', 0.0) # 0.0 is the default value
print(f'Received: Timestamp={data}')
time.sleep(1)
if __name__ == '__main__':
# Set up logging to see NetworkTables messages
logging.basicConfig(level=logging.DEBUG)
# Create threads for sending and receiving data
send_thread = threading.Thread(target=send_data)
# receive_thread = threading.Thread(target=receive_data)
# Start the threads
send_thread.start()
# receive_thread.start()
# Wait for the threads to finish (you can stop them manually)
send_thread.join()
# receive_thread.join()