From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting of nidaqmx constant, Coupling:AC/DC/GND using nidaqmx Python package

Solved!
Go to solution

Hello,

I am using PXI 4462. The name of my channel is 'Dev1/ai0'.

I do know by default the following program reads the data with DC coupling(Just for testing, I use the signal generator to give voltage input to channel Dev1/ai0 using different DC offsets). But for my applications I would like to read this data with AC coupling for this channel:Dev1/ai0.

I have gone through the documentation of nidaqmx python package which says about nidaqmx.constants.Coupling such as Coupling.AC=10045;Coupling.DC=10050,Coupling.GND=10066. But apparently I could not succeed in implementing it in my code.

How and where can I say/input this information in my code. 

The code is as follows:

with nidaqmx.Task() as task:

        task.ai_channels.add_ai_voltage_chan('Dev1/ai0') 
        task.timing.cfg_samp_clk_timing(Samples_Per_Sec=50000, source="",                                             active_edge=Edge.RISING,sample_mode=AcquisitionType.FINITE,              

                samps_per_chan=50000)
        data=task.read(samps_per_chan=50000)

 

Thank You.

0 Kudos
Message 1 of 5
(3,185 Views)

Hi Swapnil,

 

What commands have you tried?

Have you tried something like this?

 

Task.ai_channel.ai_coupling = nidaqmx.constants.Coupling.AC

 

0 Kudos
Message 2 of 5
(3,143 Views)

Hi Jacob,

Thanks for your inputs.

I did try using AIChannel like,

AIChannel.ai_coupling = nidaqmx.constants.Coupling.AC  (But, it did not work)

The alternative that you have proposed did not work for me(I get an attribute error).

By the way, I believe in your answer you mean to say 'task.ai_channel.ai_coupling' and not 'Task.ai_channel.ai_coupling''.

After going through the documentation of nidaqmx and also the source code I do not see 'ai_channel' attribute in Task (and so the attribute error is justifiable).

 

Swapnil

0 Kudos
Message 3 of 5
(3,129 Views)
Solution
Accepted by topic author Swapnil@CEA

Swapnil,

 

Sorry I did mean task not Task. I did some more digging and I think this might work:

 

with nidaqmx.Task() as task:

            chan = task.ai_channels.add_ai_voltage_chan("4462/ai0")

            chan.ai_coupling = constants.Coupling.AC

            data = task.read()

            print(data)

 

Let me know if this works for you.

 

Thanks!

0 Kudos
Message 4 of 5
(3,105 Views)

Hi Jacob,

 

The solution suggested by you "chan" works perfectly fine for me.

 

I think I was making mistake for using the right syntax, to assign properties defined in a specific 'class' in python.

 

Thanks again for your help.

 

Swapnil 

 

0 Kudos
Message 5 of 5
(3,093 Views)