Skip to content

Commit c317107

Browse files
committed
Changed the WaveGen to save the current analog output values
at the beginning of the scan, and to restore them at the end. This prevents the issue of the ao record values not matching the actual output voltage at the end of the scan.
1 parent 644b64a commit c317107

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

measCompApp/src/drvMultiFunction.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ class MultiFunction : public asynPortDriver {
774774
int numWaveGenChans_;
775775
int numWaveDigChans_;
776776
int pulseGenRunning_[MAX_PULSE_GEN];
777+
int waveGenSavedOutput[MAX_ANALOG_OUT];
777778
int waveGenRunning_;
778779
int waveDigRunning_;
779780
int startPulseGenerator(int timerNum);
@@ -1585,6 +1586,8 @@ int MultiFunction::startWaveGen()
15851586
firstChan = i;
15861587
firstType = waveType;
15871588
}
1589+
// Save the current value of the analog output so it can be restored at the end of the scan
1590+
getIntegerParam(i, analogOutValue_, &waveGenSavedOutput[i]);
15881591
// Cannot mix user-defined and internal waveform types, because internal modifies dwell time
15891592
// based on frequency
15901593
if (((firstType == waveTypeUser) && (waveType != waveTypeUser)) ||
@@ -1674,14 +1677,34 @@ int MultiFunction::startWaveGen()
16741677
int MultiFunction::stopWaveGen()
16751678
{
16761679
int err;
1680+
int range;
1681+
int enable;
1682+
int status=0;
16771683
waveGenRunning_ = 0;
1684+
static const char *functionName = "stopWaveGen";
1685+
16781686
setIntegerParam(waveGenRun_, 0);
16791687
ULMutex.lock();
16801688
#ifdef _WIN32
16811689
err = cbStopBackground(boardNum_, AOFUNCTION);
16821690
#else
16831691
err = ulAOutScanStop(daqDeviceHandle_);
16841692
#endif
1693+
1694+
// Set the analog outputs back to their value before the scan
1695+
for (int i=0; i<numAnalogOut_; i++) {
1696+
getIntegerParam(i, waveGenEnable_, &enable);
1697+
if (!enable) continue;
1698+
getIntegerParam(i, analogOutRange_, &range);
1699+
#ifdef _WIN32
1700+
status = cbAOut(boardNum_, i, range, waveGenSavedOutput[i]);
1701+
#else
1702+
Range ulRange;
1703+
mapRange(range, &ulRange);
1704+
status = ulAOut(daqDeviceHandle_, i, ulRange, AOUT_FF_NOSCALEDATA, (double) waveGenSavedOutput[i]);
1705+
#endif
1706+
reportError(status, functionName, "calling AOut");
1707+
}
16851708
ULMutex.unlock();
16861709
return err;
16871710
}

0 commit comments

Comments
 (0)