02-25-2021 07:28 AM
Hi,
i posted a question few days ago, but maybe it was to complicated or something. And i wanted to start to think in a new way.
So my simple question is:
Is it possible to recieve data only on Demand from an analogInputChannel without stopping the task itself?
If i set up a Channel with a finite AquisitionType and restart the task each time, it slows down. If i set up a continuous channel, the data is acquiried automatically and gets stored in the buffer. If i then use task.read() it works through the buffer "step by step", but i only want the latest value when calling task.read(). So i would have to call the task.read() exactly as often as the task writes to the buffer, which is impossible in my case.
I thought about using the stream_in method with a reader and always dumping the data in the buffer when reading it (read all samples that are available), but couldnt make it to work.
def DAQ_Monitoring(c,condition,ExChange,sample_rate):
with nidaqmx.Task() as task:
task.ai_channels.add_ai_current_chan("cDAQ9184-1B901BFMod1/ai0")
task.ai_channels.add_ai_current_chan("cDAQ9184-1B901BFMod1/ai1")
task.ai_channels.add_ai_current_chan("cDAQ9184-1B901BFMod1/ai2")
# MAXIMUM task.timing.cfg_samp_clk_timing(rate=66666,sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,samps_per_chan=2)
task.timing.cfg_samp_clk_timing(rate=1000,sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS, samps_per_chan=nidaqmx.constants.READ_ALL_AVAILABLE)
reader = AnalogMultiChannelReader(task.in_stream)
values_read = np.zeros((3,), dtype=np.float64)
sample_RateSeconds = (sample_rate)*(10**(-3)) #convert sampleRate from [ms] to [s]
startTime = datetime.now().timestamp()
oldTime = 0
task.start()
while condition.value == 3:
while ((datetime.now().timestamp()-startTime)-oldTime) < sample_RateSeconds:
pass
timeData = datetime.now().timestamp()-startTime
oldTime = timeData
reader.read_many_sample(values_read)
print(values_read)
pressureIn = values_read[0,0]
pressureVessel = values_read[1,0]
volumeFlow = values_read[2,0]
print(pressureIn)
position, force = pullData(c)
accousticEmission1 = 999
vibration = 999
pressureIn = (1000000/16)*(pressureIn-0.004)
pressureVessel = (200000/16)*(pressureVessel-0.004)
volumeFlow = 3250*volumeFlow
ExChange[:] = [timeData,pressureIn,pressureVessel,volumeFlow,accousticEmission1,vibration,position,force]
Calling this def throws this error:
Traceback (most recent call last):
File "C:\Users\Jetting\anaconda3\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Users\Jetting\anaconda3\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Jetting\Desktop\Robert\SCT_TryOut_DifferentAcqTypes\SCT_24.02.2021_v1.1_stream.py", line 102, in DAQ_Monitoring
task.start()
File "C:\Users\Jetting\anaconda3\lib\site-packages\nidaqmx\task.py", line 1026, in start
check_for_error(error_code)
File "C:\Users\Jetting\anaconda3\lib\site-packages\nidaqmx\errors.py", line 127, in check_for_error
raise DaqError(error_buffer.value.decode("utf-8"), error_code)
nidaqmx.errors.DaqError: The specified mathematical operation results in an overflow.
Device: cDAQ9184-1B901BF
Task Name: _unnamedTask<0>
Status Code: -50175
Is there any advice or hint you have for me?