From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-16-2015 06:22 AM
Hello,
I am doing data streaming in C by PXI-5421 follow this instruction : http://zone.ni.com/reference/en-XX/help/370524R-01/siggenhelp/streaming/
Below is my psudo code:
1. Specify the amount of onboard memory to be used for streaming
waveformSize = 1048576;
short* CurData[ 16 ];
checkErr(niFgen_init(Resource, VI_TRUE, VI_TRUE, &vi))
checkErr(niFgen_ConfigureChannels(vi, ChannelName)); //ChannelName = '0'
checkErr(niFgen_ConfigureOutputMode(vi, NIFGEN_VAL_OUTPUT_ARB)); //arbitrary mode is used
checkErr(niFgen_ConfigureSampleRate(vi, SampleRate)); //Sample Rate = 40e6;
checkErr(niFgen_AllocateWaveform(vi, ChannelName, waveformSize, &wfmHandle)); //Allocate on borad memory for streaming
2. Identify the streaming waveform
checkErr(niFgen_SetAttributeViInt32(vi, ChannelName, NIFGEN_ATTR_STREAMING_WAVEFORM_HANDLE, wfmHandle));
checkErr(niFgen_SetAttributeViReal64(vi, VI_NULL , NIFGEN_ATTR_STREAMING_WRITE_TIMEOUT, 10.0)); //Set TimeOut = 10s
3. Fill the streaming waveform with initial data
for(j=0;j<16;j++){
fread(CurData[j], sizeof(short), waveformSize/16 , PlayedFile); //Read Data from my saved file
checkErr(niFgen_WriteBinary16Waveform (vi, ChannelName, wfmHandle, waveformSize/16, CurData[ j ]));
}
4. Begin generating the waveform
checkErr(niFgen_ConfigureOutputEnabled(vi, ChannelName, VI_TRUE));
checkErr(niFgen_InitiateGeneration(vi));
5. Write a block of waveform data. (Optional) Monitor available memory as the waveform generates
do{
niFgen_GetAttributeViInt32 (vi, "0", NIFGEN_ATTR_STREAMING_SPACE_AVAILABLE_IN_WAVEFORM , &FreeSpace);
//if(FreeSpace>=waveformSize/16){
fread(renewData, sizeof(short), waveformSize/16 , PlayedFile);
checkErr(niFgen_WriteBinary16Waveform (vi, "0", wfmHandle, waveformSize/4, PlayData));
//}
}while(1);
I generate first 1048576 points of data correctly. However, I am stuck in write new data into my allocated onboard memory space.
The error message, space in the streaming waveform has not become availabe within the specific time, pops out after 10sec which is my timeout period.
If I check my availbale space via the property NIFGEN_ATTR_STREAMING_SPACE_AVAILABLE_IN_WAVEFORM, it never increases. Do I miss something? Can I work in arbitrary mode for data streaming?
Any suggestion is appreciated. Thanks!
Solved! Go to Solution.
09-16-2015 09:46 AM
Can I work in arbitrary mode for data streaming?
Arbitrary Mode is a valid mode to do streaming.
On first glance, nothing looks out of the ordinary.
checkErr(niFgen_WriteBinary16Waveform (vi, "0", wfmHandle, waveformSize/4, PlayData)
What are you defining as "PlayData"? Also, is there a reason why you decided to write in the size of waveformSize/4 whereas everywhere else you are writing it as waveformSize/16.
Jason L
09-17-2015 03:52 AM
Hello Jason,
Sorry I paste my old code. It should have been:
fread(renewData, sizeof(short), waveformSize/16 , PlayedFile);
checkErr(niFgen_WriteBinary16Waveform (vi, "0", wfmHandle, waveformSize/16, renewData));
I found that If i take off the do while loop, and write new data into my allocated space only one time, the time out error message won't pop out.
But I still can't update my streaming data. PXI-5421 generate my initial filled in data only.
09-17-2015 11:13 AM
From looking at the LabVIEW/CVI example it looks like you are on the right track.
If you take out the Do/While loop, do you even get 1114112 samples generated? That is, 1048576+(1048576/16) samples?
What is the value returned by "niFgen_GetAttributeViInt32 (vi, "0", NIFGEN_ATTR_STREAMING_SPACE_AVAILABLE_IN_WAVEFORM , &FreeSpace);" ?
I have attached the CVI example to this post. It has a lot of extra functions that change the CVI GUI, but the FGEN function calls should be the same. The only thing that is noticebly different is that they set a repeat count and use the single trigger mode. I would go ahead and edit your code to be similar just to make sure that there aren't any hardware issues. Then I would try to generate and stream a sinewave first before trying to use your file. Hopefully we can narrow down any issues.
Jason L.
09-18-2015 05:48 AM
Hello Jason,
I know why my free space never increase. When I test my code, i use debug step mode to check the free memory space which leads write in data can't keep up with data streaming therefore driver did not return the current free
space to me. If I execute my program, the freespace do increase, and I can do data streaming continuously as I want.
Thanks for your help! The example helps me a lot. I really appericated it. : )
03-06-2016 01:59 AM - edited 03-06-2016 02:00 AM
Hello Jason,
Could you tell me something about checkErr( )?
Thank you!