I am using a nidaqmx python3 pacakge to program the NI PCI-6133 acquisition board, and I can't use the board in continuous acquisition mode. It doesn't give an error, but I can't see the buffer values. I can read some values using this package. I am based on this question. My Code:
import nidaqmx
from nidaqmx import stream_readers
import numpy as np
import time
data2=np.zeros((1, 10000), dtype=np.float32)
system=nidaqmx.system.System.local()
print("Driver version nidaqmx:",system.driver_version)
#19.6
for device in system.devices:
print("Device:", device)
syst=nidaqmx.system.system.System()
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan("Dev1/ai0",min_val=-10.0,max_val=10.0)
task.timing.cfg_samp_clk_timing(rate=10000,
active_edge=nidaqmx.constants.Edge.RISING,
sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
samps_per_chan=10000)
reader =stream_readers.AnalogMultiChannelReader(task.in_stream)
def reading_task_callback(task_idx, event_type, num_samples, callback_data=None):
"""After data has been read into the NI buffer this callback is called to read in the data from the buffer.
This callback is for working with the task callback register_every_n_samples_acquired_into_buffer_event.
Args:
task_idx (int): Task handle index value
event_type (nidaqmx.constants.EveryNSamplesEventType): ACQUIRED_INTO_BUFFER
num_samples (int): Number of samples that was read into the buffer.
callback_data (object)[None]: No idea. Documentation says: The callback_data parameter contains the value
you passed in the callback_data parameter of this function.
"""
buffer = np.zeros((1, num_samples), dtype=np.float32)
reader.read_many_sample(buffer, num_samples, timeout=nidaqmx.constants.WAIT_INFINITELY)
# Convert the data from channel as a row order to channel as a column
data = buffer.T.astype(np.float32)
# Do something with the data
print("Hello")
print(data)
return 0 # callback must return an integer, otherwise callback throws a wall of errors
task.register_every_n_samples_acquired_into_buffer_event(10000, reading_task_callback)
Output:
Driver version nidaqmx: DriverVersion(major_version=19, minor_version=6, update_version=0)
Device: Device(name=Dev1)
Additionaly I use NI I/O trace for monitor the communication with the board:
1. DAQmxGetSysNIDAQMajorVersion (19 (0x13))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:39,6679 Call Duration 00:00:00.0000
Status: 0 (0x0)
2. DAQmxGetSysNIDAQMinorVersion (6 (0x6))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:39,7099 Call Duration 00:00:00.0000
Status: 0 (0x0)
3. DAQmxGetSysNIDAQUpdateVersion (0 (0x0))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:39,7509 Call Duration 00:00:00.0000
Status: 0 (0x0)
4. DAQmxGetSysDevNames (0x053C4A58, 0 (0x0))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:39,8709 Call Duration 00:00:00.0439
Status: 5 (0x5)
5. DAQmxGetSysDevNames ("Dev1", 5 (0x5))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:39,9579 Call Duration 00:00:00.0000
Status: 0 (0x0)
6. DAQmxGetSysNIDAQMajorVersion (19 (0x13))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,0279 Call Duration 00:00:00.0000
Status: 0 (0x0)
7. DAQmxGetSysNIDAQMinorVersion (6 (0x6))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,0689 Call Duration 00:00:00.0000
Status: 0 (0x0)
8. DAQmxGetSysNIDAQUpdateVersion (0 (0x0))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,1099 Call Duration 00:00:00.0000
Status: 0 (0x0)
9. DAQmxCreateTask ("", 0x6A1621A0)
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,1509 Call Duration 00:00:00.0059
Status: 0 (0x0)
10. DAQmxGetTaskName (0x6A1621A0, "", 0 (0x0))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,1979 Call Duration 00:00:00.0000
Status: 16 (0x10)
11. DAQmxGetTaskName (0x6A1621A0, "_unnamedTask<0>", 16 (0x10))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,2389 Call Duration 00:00:00.0000
Status: 0 (0x0)
12. DAQmxCreateAIVoltageChan (0x6A1621A0, "Dev1/ai0", "", "DAQmx_Val_Cfg_Default", -10.000000 (-1.000000E+01), 10.000000 (1.000000E+01), DAQmx_Val_Volts, "")
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,2799 Call Duration 00:00:00.0130
Status: 0 (0x0)
13. DAQmxCfgSampClkTiming (0x6A1621A0, "", 10000.000000 (1.000000E+04), DAQmx_Val_Rising, DAQmx_Val_ContSamps, 10000 (0x0000000000002710))
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,3359 Call Duration 00:00:00.0000
Status: 0 (0x0)
14. DAQmxRegisterEveryNSamplesEvent (0x6A1621A0, "DAQmx_Val_Acquired_Into_Buffer", 10000 (0x2710), 0 (0x0), 0x00FD0FDC, NULL )
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,3769 Call Duration 00:00:00.0039
Status: 0 (0x0)
15. DAQmxClearTask (0x6A1621A0)
Process ID: 0x00001DBC Thread ID: 0x00000C18
Start Time: 07:49:40,4219 Call Duration 00:00:00.0000
Status: 0 (0x0)
Some help, ideally a code or modification from my code that can use the board in continues mode and extract the values from the buffer.