Real-Time Measurement and Control

Showing results for 
Search instead for 
Did you mean: 

NI-6210 USB - Python - Inconsistent value sampling

I am currently using a NI-6210 to read data from 2 encoders on the following motors  Ametek Pittman GM8212D142.

I am using the python library nidaqmx.

I am creating 2 tasks, 1 for each encoder:

def initiate_acquisition_task(task_number):
task_name = 'input_task_1' if task_number == 1 else 'input_task_2'
channel = 'Dev1/ctr0' if task_number == 1 else 'Dev1/ctr1'
source = 'PFI0' if task_number == 1 else 'PFI2'
deg = 0 if task_number == 1 else 180

acquisition_task = Task(task_name)

acquisition_task.ci_channels.add_ci_ang_encoder_chan(channel, "", constants.EncoderType.X_4,
acquisition_task.timing.cfg_samp_clk_timing(100000, source=source, sample_mode=constants.AcquisitionType.CONTINUOUS)
print("created new task: ", task_name)

return acquisition_task

Then inside a while loop until user termination input I start reading values while moving the assembly and calculating positions of a point in space based on the readings I get.

So the readings are acquired this way :

read_value_1 =, timeout=0)[0]
position2 = signedNum(read_value_1, 32)
degrees2 = (position2 / PPR) * 180
curr_ang2 = -degrees2[0]

except Exception as e:
# print(e)
curr_ang2 = previous_ang2

read_value_2 =, timeout=0)[0]
position1 = signedNum(read_value_2, 32)
degrees1 = (position1 / PPR) * 180
curr_ang1 = -degrees1[0] + 180
# print("rv2: ", read_value_2)
except Exception as e:
# print(e)
curr_ang1 = previous_ang1

I have been playing around with rate of the acquisition (cfg_samp_clk_timing(100000...) and the number of samples per channel, because changing those values had a massive impact on the real time chart created in python.

My issue is that I start getting values , sometimes I stop moving the assembly but the values are still printing (large buffer I suppose, containing a lot of values and takes time to read and print them all) and sometimes I move the pointer and nothing happens I get no readings at all, happens at random times.

So what I wanted to ask is how I would get a steady semi-real time data acquisition if such thing is possible and if it is a known issue , what could cause the sudden stops in data acquisition .

0 Kudos
Message 1 of 1