11-18-2011 04:52 PM
Hi,
Using Matlab 2010a to call nicaiu.dll and run DAQmx commands. Most things work fine. However, very often (>50% of the times) when I enter wrong or illegal DAQmx parameters (as I'm in the process of developing and debugging my code...) Matlab will simply fail miserable, crash and often not even write out a core dump before exiting. I assume this is a Matlab issue and should contact them (which I will). However, I was wondering of anyone here as experience something similar, and if something as simple as upgrading/downgrading the Matlab version helped?
Thanks,
Per
Solved! Go to Solution.
11-19-2011 12:29 AM
For the benefit of the comunity, I'll post the 'answer' I found myself;
Investigating this issue a bit further I found that the crashed were caused exclusively by calls to the DAQmx function DAQmxGetErrorString(). This function was used in my error function that catches all DAQmx errors returned by DAQmx.
Specifically, this is the code that causes Matlab to crash;
nLen = calllib('mynidaqmx', 'DAQmxGetErrorString', statusCode, '', 0);
[errCode, sStr] = calllib('mynidaqmx', 'DAQmxGetErrorString', statusCode, char(nLen-1), nLen-1);
Can anyone confirm this behavior?
- Per
11-20-2011 04:57 PM
Hi Per,
To allocate a string of length N, try calling blanks(N) instead of char(N). char(N) converts the ASCII code N into a character.
Also, you probably don't want to subtract one from the length. That causes DAQmx to truncate the string and return warning 200026, "Requested string could not fit into the given buffer". It does not cause DAQmx to omit the trailing null character: the string is still null-terminated, just one character shorter.
Brad
11-21-2011 01:46 PM
Thanks Brad.
You suggestion to use blanks() seems to have made a difference. At the very least, I have not had Matlab crash in a while, so I marked your answer as a Solution.
- Per