-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_data_from_simdevice.py
More file actions
44 lines (35 loc) · 1.35 KB
/
read_data_from_simdevice.py
File metadata and controls
44 lines (35 loc) · 1.35 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
44
import opendaq
import time
# Create a fresh openDAQ™ instance
instance = opendaq.Instance()
device = None
# Find and connect to a simulator device
print("Searching for the device simulator...")
for device_info in instance.available_devices:
if device_info.name == 'Reference device simulator':
device = instance.add_device(device_info.connection_string)
print("Connected to:", device.info.name)
break
else:
print("Device simulator not found. Please ensure it is running.")
exit(0)
# 1. Get the first signal of the first channel
channel = device.channels[0]
signal = channel.signals[0]
print("Reading from signal:", signal.name)
# 2. Create a StreamReader for the signal
# By default, it reads values as Float64 (double)
reader = opendaq.StreamReader(signal)
# 3. Use a TimeStreamReader for easy timestamp conversion
time_reader = opendaq.TimeStreamReader(reader)
print("\n--- Reading 20 samples with timestamps ---")
# Read data in a loop
for i in range(20):
# Wait for some data to be generated
time.sleep(0.1)
# Read up to 100 available samples with timestamps
samples, timestamps = time_reader.read_with_timestamps(100)
# Print the last received sample and its timestamp, if any
if len(samples) > 0:
print(f"Value: {samples[-1]:.4f}, Timestamp: {timestamps[-1]}")
print("\n--- Finished reading ---")