Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

SetReadChannelsToRead/Reading channels in a specfic order.

I have been trying to update our Ni-DAQ legacy scripts to Ni-DAQmx scripts and have encountered one large problem. I am trying to perform an Analog Block Read. The channel number and order is determined by some parameters supplied by another program. These values are contained in an array such as 0,7,1,7,2,7... etc where 7 is used to "zero" the voltage in between reads. This process works with 7 channels, but when I switch to a DAQ with 14 or 28 channels,I receive error 200082, which provides useless information in my opinion to solving the problem. I am wondering if there is a maximum amount of channels that can be specified in DAQmxSetReadChannelsToRead. The function in question is below, but some parameters may not be referenced. 

 

 

 

DLLEXPORT union data_val CALLBACK AIBConfig(void)
{
union data_val dev, mode, polarity, samp, gain, chvect, SampRate, ScanRate, ret;
int16* gains;
int16* vect;
int i;
int error = 0;
int32 read = 0;

// Configure all analog input ports for double buffered data collection.
get_param_val(&dev, ING, FIRST); // Retrieving Parameters from Splot
if (dev.i < 1 || dev.i > MAXDEV)
sntx_err(OUT_OF_RANGE);
AIBdev = dev.i;
get_param_val(&mode, ING, MID);
get_param_val(&polarity, ING, MID);
get_param_val(&samp, ING, MID);
if (samp.i < 0)
sntx_err(OUT_OF_RANGE);
nsamp[dev.i] = samp.i;
if (minpeakind == 0)
minpeakind = samp.i / 20; // default to match previous hard coded value
get_param_val(&gain, PTRT, MID);
if (gain.pv.p == NULL)
sntx_err(NULL_PTR);
if (gain.pv.pinfo->btype != SHRT)
sntx_err(TYPE_MISMATCH);
nchan[dev.i] = gain.pv.pinfo->dim[0];
gains = (int16*)gain.pv.p;
get_param_val(&chvect, PTRT, MID);
if (chvect.pv.p == NULL)
sntx_err(NULL_PTR);
if (chvect.pv.pinfo->btype != SHRT)
sntx_err(TYPE_MISMATCH);
if (chvect.pv.pinfo->dim[0] != (int)nchan[dev.i])
sntx_err(INDEX_OUT);
vect = (int16*)chvect.pv.p;
get_param_val(&SampRate, DUB, MID);
get_param_val(&ScanRate, DUB, LAST);

// allocate buffers
nibufsize[dev.i] = nchan[dev.i] * nsamp[dev.i] * 2; // *2 for double buffered
if (piBuffer[dev.i] != NULL)
free(piBuffer[dev.i]);
piBuffer[dev.i] = (int16*)malloc(nibufsize[dev.i] * sizeof(int16));
if (piBuffer[dev.i] == NULL)
sntx_err(OUT_OF_MEM);
if (piHalfBuffer[dev.i] != NULL)
free(piHalfBuffer[dev.i]);
piHalfBuffer[dev.i] = (int16*)malloc(nibufsize[dev.i] / 2 * sizeof(int16));
if (piHalfBuffer[dev.i] == NULL)
sntx_err(OUT_OF_MEM);
if (piXferBuffer[dev.i] != NULL)
free(piXferBuffer[dev.i]);
piXferBuffer[dev.i] = (int16*)malloc(nibufsize[dev.i] / 2 * sizeof(int16));
if (piXferBuffer[dev.i] == NULL)
sntx_err(OUT_OF_MEM);
if (diff[dev.i] != NULL)
free(diff[dev.i]);
diff[dev.i] = (int*)malloc(nchan[dev.i] * sizeof(int));
if (diff[dev.i] == NULL)
sntx_err(OUT_OF_MEM);


for (i = 0; i < (int)nchan[dev.i]; i++) // Assigning respective gains to channels
{
switch (gains[i])
{
case 1:
{
voltsLow[i] = (float)-5;
voltsHigh[i] = (float)5;
}
break;
case 2:
{
voltsLow[i] = (float)-2.5;
voltsHigh[i] = (float)2.5;
}
break;
case 5:
{
voltsLow[i] = (float)-1;
voltsHigh[i] = (float)1;
}
break;
case 10:
{
voltsLow[i] = (float)-0.5;
voltsHigh[i] = (float)0.5;
}
break;
case 20:
{
voltsLow[i] = (float)-0.25;
voltsHigh[i] = (float)0.25;
}
break;
case 50:
{
voltsLow[i] = (float)-0.1;
voltsHigh[i] = (float)0.1;
}
break;
case 100:
{
voltsLow[i] = (float)-0.05;
voltsHigh[i] = (float)0.05;
}
break;
default:
voltsLow[i] = (float)-5;
voltsHigh[i] = (float)5;
break;
}
}
time_step[dev.i] = 1.0 / ScanRate.d; // Calculating timestep
error = DAQmxCreateTask("", &taskHandle); // Creating Task
handleError(error, taskHandle);

for (i = 0; i < (int)nchan[dev.i]; i += 2)
{
char devAIB[256]; // Retrieving dev/chan # from splot
sprintf_s(devAIB, 256, "dev%d/ai%d", dev.i, vect[i]);
char inputMode[256]; // Retrieving dev/chan # from splot
sprintf_s(inputMode, 256, "DAQmx_Val_%d", mode.i);

if (vect[i] == LOOPBACKCH)
continue;
if (mode.i == 0) // Setting the terminal configuration
{
error = DAQmxCreateAIVoltageChan(taskHandle, devAIB, "", DAQmx_Val_Diff, voltsLow[i], voltsHigh[i], DAQmx_Val_Volts, NULL);
handleError(error, taskHandle);
}
else if (mode.i == 1)
{
error = DAQmxCreateAIVoltageChan(taskHandle, devAIB, "", DAQmx_Val_RSE, voltsLow[i], voltsHigh[i], DAQmx_Val_Volts, NULL);
handleError(error, taskHandle);
}
else if (mode.i == 2)
{
error = DAQmxCreateAIVoltageChan(taskHandle, devAIB, "", DAQmx_Val_NRSE, voltsLow[i], voltsHigh[i], DAQmx_Val_Volts, NULL);
handleError(error, taskHandle);
}
}
char controlChannel[256]; // Retrieving dev/chan # from splot
sprintf_s(controlChannel, 256, "dev%d/ai%d", dev.i, LOOPBACKCH);
error = DAQmxCreateAIVoltageChan(taskHandle, controlChannel, "", DAQmx_Val_Diff, -5, 5, DAQmx_Val_Volts, NULL); // Might not be always ai7? Therefore might need to be fixed to receive from splot.
handleError(error, taskHandle);
error = DAQmxCfgSampClkTiming(taskHandle, NULL, ScanRate.d, DAQmx_Val_Rising, DAQmx_Val_ContSamps, nibufsize[AIBdev]/2); // Configuring the Sample timing
handleError(error, taskHandle);
error = DAQmxSetAIConvRate(taskHandle, SampRate.d); // Modifying the AI convert clock rate
handleError(error, taskHandle);
error = DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, 2048, 0, EveryNCallback, NULL); // Creating Callback event
handleError(error, taskHandle);
error = DAQmxRegisterDoneEvent(taskHandle, 0, DoneCallback, NULL); // Creating done event
handleError(error, taskHandle);

char chanreadstr[2048];
char tempchread[80];
char rvect[2048];
chanreadstr[0] = '\0';

for (i = 0; i < (int)nchan[dev.i] - 1; i++)
{
//if (vect[i] == LOOPBACKCH)
//continue;
sprintf_s(tempchread, 80, "dev%d/ai%d, ", AIBdev, vect[i]);
strcat_s(chanreadstr, tempchread);
}
sprintf_s(tempchread, 80, "dev%d/ai%d", AIBdev, LOOPBACKCH);
strcat_s(chanreadstr, tempchread);
error = DAQmxSetReadChannelsToRead(taskHandle, chanreadstr); // Setting specific array of channels to read
handleError(error, taskHandle);
//error = DAQmxGetReadChannelsToRead(taskHandle, rvect, 2048);
//handleError(error, taskHandle);
error = DAQmxStartTask(taskHandle); // Starting the task
handleError(error, taskHandle);

ret.i = error;
return ret;

0 Kudos
Message 1 of 3
(2,595 Views)

Hello,

 

Can you provide the exact text of that error message or a screenshot of it? I just want to make sure we're talking about the same error.

Claire C.
AppSW Staff Product Support Engineer
National Instruments
CLD|CTD
0 Kudos
Message 2 of 3
(2,560 Views)

Error Code.PNGError Message.PNG

0 Kudos
Message 3 of 3
(2,558 Views)