LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

General protection error *sampsPerChanWritten= numSampsPerChan;

hey guys,

 

   I'm having a lot of trouble understanding this general protection error,

I have the function:

   int32 __stdcall DAQmxWriteAnalogF64 (TaskHandle taskHandle, int32 numSampsPerChan, bool32 autoStart, float64 timeout, bool32 dataLayout, const float64 writeArray[], int32 *sampsPerChanWritten, bool32 *reserved)
   {
		 GblWriteData[taskHandle]=*writeArray;
		 //actual number of samps written is exactly how many samples came in
		 *sampsPerChanWritten= numSampsPerChan;
		 return 0;
   }

 when I call this function

DAQmxErrChk(DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&data,NULL,NULL));

 I get the general protection error. after some debugging the one line that is cause this is

*sampsPerChanWritten= numSampsPerChan;   

numSampsPerChan is 1 from the function call, and an int32. I dont understand how this would cause an error.

 

Someone mind helping?

 

thanks!

0 Kudos
Message 1 of 3
(3,070 Views)

Hi tianshiz,

 

You're passing NULL for the 'sampsPerChanWritten' parameter, but your implementation of DAQmxWriteAnalogF64() doesn't check whether this parameter is NULL before dereferencing it, so it crashes.

 

By the way, based on this and your previous threads, it sounds like you're trying to use a DAQmx simulated device, but with your own custom data instead of the stock sine wave. Writing your own replacements for the DAQmx read and write functions is a good way to do that. However, I recommend naming your functions something different than the real DAQmx functions, so that you can use conditionals, function pointers, or polymorphism to choose which version to call at runtime. Otherwise, your program won't work with real DAQmx devices.

 

On the other hand, if this is a stub function for a unit test, then carry on. 🙂

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 3
(3,058 Views)

thanks for the help, that ended up being what I found out as well.

 

and yea its just like a stub function, i'm not trying to imitate hardware, that would be prohibitively difficult

0 Kudos
Message 3 of 3
(3,041 Views)