From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Missmatch on value read after writting a value using C++ (NiDAQmx)

Solved!
Go to solution

We have written a value (2v) to an output channel AO1 and was verified the value in hardware (voltmeter).  The channel AO1 is wired to the input channel AI3.  But when we read the value of AI3, we do not get the value that we have writtem. We have tried the behavior with and without a triggering source. In both cases, we did not get the value written to AO1, when reading from AI3.


The C++ code used for Analog value reading and writing is given below. Is there any issue with the below code?

Read analog
------------

TaskHandle oTask;
constexpr char TaskName[] = "";
double fRead{ 0 };
int32 nError = DAQmxCreateTask(TaskName, &oTask);
nError = DAQmxCreateAIVoltageChan(oTask, "Dev1/AI3", "", DAQmx_Val_Cfg_Default, -3.25, 3.25, DAQmx_Val_Volts, nullptr);
nError = DAQmxCfgSampClkTiming(oTask, "", 1.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2);
nError = DAQmxCfgDigEdgeStartTrig(oTask, "PFI0", DAQmx_Val_Rising);
int32 nError = DAQmxReadAnalogF64(oTask, 1, 60, DAQmx_Val_GroupByChannel, &fRead, 1, &nSampsPerChanRead, nullptr);
nError = DAQmxClearTask(oTask);

Write analog
------------

constexpr char TaskName[] = "";
TaskHandle oTask;
double dValues[2]{ 2, 2 };
int32 nError = DAQmxCreateTask(TaskName, &oTask);
nError = DAQmxCreateAOVoltageChan(oTask, "Dev1/AO1", "", -3.25, 3.25, DAQmx_Val_Volts, nullptr);
nError = DAQmxCfgSampClkTiming(oTask, "", 50.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2);
nError = DAQmxCfgDigEdgeStartTrig(oTask, "PFI0", DAQmx_Val_Rising);
nError = DAQmxWriteAnalogF64(oTask, 2, 1, 60, DAQmx_Val_GroupByChannel, dValues, nullptr, nullptr);
nError = DAQmxWaitUntilTaskDone(oTask, 60);
nError = DAQmxClearTask(oTask);

 

0 Kudos
Message 1 of 2
(900 Views)
Solution
Accepted by topic author kiran_t

Sometimes this kind of thing is due to a mismatch between the terminal configuration (RSE, NRSE, differential) and the physical wiring.   You can use test panels in MAX to experiment with the configuration, and here's a summary about the recommended physical wiring.  (The classic, more thorough article can be found here.)

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 2 of 2
(867 Views)