04-07-2013 07:07 PM
How local variables initialized in CVI?
Are there any default values for local variables?
04-07-2013 11:49 PM
Local variables are not initialized as default. You have to do that with your code.
04-08-2013 12:25 AM
Following function is generated by IVI Scope driver generator.
If the vertical coupling is GND, variable simOffset is used in an equation without being initialised.
Is this a bug and it must be initialized?
/*****************************************************************************
* Function: TTTTT_FetchWaveformSafe
* Purpose: This function returns the data from the instrument. You must
* range-check all parameters and lock the session before calling
* this function.
*****************************************************************************/
static ViStatus TTTTT_FetchWaveformSafe (ViSession vi, ViConstString channelName,
ViInt32 waveformSize, ViReal64 waveform[],
ViInt32 *actualPoints, ViReal64 *initialX,
ViReal64 *xIncrement)
{
ViStatus error = VI_SUCCESS;
if (!Ivi_Simulating (vi)) /* call only when locked */
{
ViSession io = Ivi_IOSession (vi); /* call only when locked */
ViChar rdBuf[5000];
checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));
/*=CHANGE: ==============================================================*
Do actual instrument I/O only if not simulating. Example:
viCheckErr( viPrintf (io, ":WAV %s:DATA?", channelName));
viCheckErr( viRead (io, rdBuf, 5000, VI_NULL));
Change the number of elements in the rdBuf array as appropriate for your
instrument's maximum record size.
Convert the rdBuf raw data here to a double precision floating point
numbers and store the data in the waveform array.
Read the waveform preamble from the instrument to get the initial X
and X increment values.
If the oscilloscope did not resolve all points in the waveform record,
replace such points with the IVI_VAL_NAN value. The function should
return the TTTTT__WARN_INVALID_WFM_ELEMENT
warning in this case.
*============================================================END=CHANGE=*/
}
else
{
ViInt32 x;
ViReal64 yRange, simOffset;
ViInt32 triggerSlope, vCoup;
ViReal64 k, level, theta, offset;
checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL,
TTTTT_ATTR_HORZ_RECORD_LENGTH,
0, actualPoints));
checkErr( Ivi_GetAttributeViReal64 (vi, channelName,
TTTTT_ATTR_VERTICAL_RANGE,
0, &yRange));
checkErr( Ivi_GetAttributeViInt32 (vi, channelName,
TTTTT_ATTR_VERTICAL_COUPLING,
0, &vCoup));
checkErr( Ivi_GetAttributeViReal64 (vi, channelName,
TTTTT_ATTR_VERTICAL_OFFSET,
0, &offset));
checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL,
TTTTT_ATTR_TRIGGER_SLOPE,
0, &triggerSlope));
checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
TTTTT_ATTR_TRIGGER_LEVEL,
0, &level));
checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
TTTTT_ATTR_HORZ_TIME_PER_RECORD,
0, xIncrement));
checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
TTTTT_ATTR_ACQUISITION_START_TIME,
0, initialX));
theta = asin (2*level/yRange);
if (triggerSlope == TTTTT_VAL_POSITIVE)
k = 1.0;
else
k = -1.0;
if( *actualPoints>waveformSize )
*actualPoints = waveformSize; /* Checking number of points to write */
*xIncrement /= *actualPoints;
if (vCoup == TTTTT_VAL_DC)
simOffset = 0.5;
if (vCoup == TTTTT_VAL_GND)
k = 0.0;
for (x = 0; x < *actualPoints; x++)
{
ViReal64 y = simOffset + k * 2.5 * sin (*xIncrement * 12560 * x + k * theta) + // ~2 periods of 1kHz sinewave
(!(x%20)) * (16384 - rand())/150000.0;
waveform[x] = (offset + yRange/2) > y ? ((offset - yRange/2) < y ? y : (offset - yRange/2)) : (offset + yRange/2);
}
}
Error:
return error;
}
04-08-2013 09:44 AM
Eddie,
It does look as though the simOffset variable is not initialized unless the coupling is set to GND. To clarify, were you seeing an error saying the variable isn't initialized?
04-08-2013 06:27 PM
I haven't seen an error yet, just was wandering how the function will react in this case and is this an error that should be fixed?
04-09-2013 08:33 AM
Eddie,
If you do see an error, you could change the variable declaration to the following:
ViReal64 simOffset = 0;
This would resolve any errors that may occur. Let us know if you have any more questions about it!