-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmydaq_long.py
More file actions
31 lines (23 loc) · 982 Bytes
/
mydaq_long.py
File metadata and controls
31 lines (23 loc) · 982 Bytes
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
import nidaqmx as dx
import numpy as np
import time
import matplotlib.pyplot as plt
chunksize = 100
class MyDAQ_Long():
def __init__(self):
self.data = []
def capture(self, duration=10, samplerate=1000):
"""Captures input of Ai0 for duration seconds at samplerate samplerate."""
self.data = [] # Clear data
self.task = dx.Task()
self.task.ai_channels.add_ai_voltage_chan("myDAQ3/ai0")
self.task.timing.cfg_samp_clk_timing(samplerate,sample_mode=dx.constants.AcquisitionType.CONTINUOUS)
self.task.register_every_n_samples_acquired_into_buffer_event(chunksize, self.updateData)
self.task.start()
time.sleep(duration+0.01)
self.task.stop()
return np.linspace(0, duration, len(np.array(self.data).flatten())), np.array(self.data).flatten()
def updateData(self, task_handle, every_n_samples_event_type, number_of_samples, callback_data):
newdata = self.task.read(number_of_samples_per_channel=chunksize)
self.data.append(newdata)
return 0