High-Speed Digitizers

cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch multi-channel signal simultaneously using ni-scope in PCI-5105?(LabWindows)

I want to subtract  channel 0 from channel 1. So I wrote like this.

According to help, 

 

// Set numWfms to 6, because the acquisition is for 2 channels times 3 records.
niScope_ActualNumWfms (vi, "0,1", &numWfms);

// Fetch the coerced record length
niScope_ActualRecordLength (vi, &actualRecordLength);

// Declare memory for the waveforms and waveform info structs
wfm = malloc (sizeof (ViReal64) * actualRecordLength * numWfms);
wfmInfo = malloc (sizeof (struct niScope_wfmInfo) * numWfms);

 

If I insert "0,1" to channelname(It usually uses "0" in examples) then I can fetch a waveform which is  an array having the information of 2 channel.

But when I inserted this, It doesn't work at all.

This is fetch codes. It was made using example. This situation, channelName is "0,1" from GetCtrlVal.

 

ViStatus _VI_FUNC niScope_Generic(void)


{
ViSession vi = VI_NULL;
ViStatus error = VI_SUCCESS;
ViChar errorSource[MAX_FUNCTION_NAME_SIZE] = " ";
ViChar errorMessage[MAX_ERROR_DESCRIPTION] = " ";

// Variables used to get values from the GUI
ViChar resourceName[MAX_STRING_SIZE];
ViChar channelName[MAX_STRING_SIZE];
ViReal64 verticalRange;
ViInt32 verticalCoupling;
ViReal64 minSampleRate;
ViInt32 minRecordLength;
ViBoolean clearStatistics;
ViInt32 triggerType;
ViInt32 numWaveform;
ViReal64 actualSampleRate;

//Waveforms
struct niScope_wfmInfo *wfmInfoPtr=NULL;
ViReal64 *waveformPtr = NULL;

// Default values used in this example
ViInt32 stop;
ViReal64 verticalOffset = 0.0;
ViReal64 probeAttenuation = 1.0;
ViReal64 refPosition = 50;
ViConstString triggerSource = "0";
ViReal64 triggerLevel = 0.0;
ViReal64 triggerHoldoff = 0.0;
ViReal64 triggerDelay = 0.0;
ViInt32 triggerCoupling = NISCOPE_VAL_DC;
ViInt32 triggerSlope = NISCOPE_VAL_POSITIVE;
ViBoolean enforceRealtime = NISCOPE_VAL_TRUE;
ViReal64 timeout = 5.0;
ViInt32 numRecords=2.0;

 


// Obtain the resource name of the device from the user interface
GetResourceNameFromGUI (resourceName);

// Open the NI-SCOPE instrument handle
handleErr(niScope_init (resourceName, NISCOPE_VAL_FALSE, NISCOPE_VAL_FALSE, &vi));

stop = NISCOPE_VAL_FALSE;

while (!stop)
{
// Obtain the necessary parameters from the user interface
GetParametersFromGUI (channelName, &verticalRange, &verticalCoupling, &minSampleRate,
&minRecordLength, &clearStatistics, &triggerType);

// Configure the vertical parameters
handleErr(niScope_ConfigureVertical(vi, channelName, verticalRange, verticalOffset,
verticalCoupling, probeAttenuation, NISCOPE_VAL_TRUE));

// Configure the horizontal parameters, with the specified number of records
handleErr(niScope_ConfigureHorizontalTiming(vi, minSampleRate, minRecordLength, refPosition, numRecords, enforceRealtime));



// Configure the trigger
if (triggerType == 1) // edge
{
handleErr (niScope_ConfigureTriggerEdge (vi,
triggerSource,
triggerLevel,
triggerSlope,
triggerCoupling,
triggerHoldoff,
triggerDelay));
}
else
handleErr (niScope_ConfigureTriggerImmediate (vi));

// Initiate the acquisition
handleErr(niScope_InitiateAcquisition(vi));

// Make sure we're not exceeding the arbitrary limit on number of waveforms
handleErr (niScope_ActualNumWfms (vi, channelName, &numWaveform));
if (numWaveform > ARBITRARY_MAX_NUM_WFMS)
handleErr (-1);

handleErr(niScope_ActualRecordLength (vi, &actualRecordLength));

// Find out the actual sample rate
handleErr(niScope_SampleRate(vi, &actualSampleRate));

handleErr(niScope_ActualRecordLength (vi, &actualRecordLength));

// Allocate space for the waveform according to the record length and number of waveforms
if (waveformPtr)
free (waveformPtr);
waveformPtr = malloc (sizeof (ViReal64) * actualRecordLength * 2.0);
wfmInfoPtr = malloc (sizeof (struct niScope_wfmInfo) * 2.0);

ViReal64 *waveformPtr = NULL;

// If it doesn't have enough memory, give an error message
if (waveformPtr == NULL || wfmInfoPtr == NULL)
handleErr (NISCOPE_ERROR_INSUFFICIENT_MEMORY);

// Fetch the data
handleErr(niScope_Fetch (vi, channelName, timeout, actualRecordLength, waveformPtr, wfmInfoPtr));
ProcessEvent (&stop);
}
Error :

if (waveformPtr)
free (waveformPtr);

// Display messages
if (error == -1)
strcpy (errorMessage, "This example only works with one channel.");
else if (error != VI_SUCCESS)
niScope_errorHandler (vi, error, errorSource, errorMessage); // Intrepret the error
else
strcpy(errorMessage, "Acquisition successful!");

DisplayErrorMessageInGUI (error, errorMessage);

// Close the session
if(vi)
niScope_close(vi);

return error;
}

 

Thanks for your help!

 

0 Kudos
Message 1 of 1
(2,105 Views)