01-25-2021 03:10 PM
I understand that Global variables in general are a bad idea, but I thought some handles to my XNet CAN interface would be an acceptable use of a global.
nxSessionRef_t g_OutputSessionRef[2] = { 0 , 0 };
nxSessionRef_t g_InputSessionRef [2] = { 0 , 0 };
My system has two DUTs and I can direct CAN traffic based off of socket number.
I would initialize these variables with create session and would get a valid handle. I could observe them in View Variable value they looked good.
In subsequent calls to the DLL that accessed these values they would be set back to 0.
Its not worth adding a bunch of code snippets - my problem is that these global variables do not keep their values during the life of the DLL. I have a work around in that for all of my CAN traffic I am passing in an input/output session reference, I basically have moved the global value to TestStand. To be honest I am now seeing other global variables re-setting to 0.
My real question is - has anybody else seen this? Is there some setting that I am missing in the developer environment that would prevent this? How do I make a global variable be persistent?
If I call these same DLL's from a CVI program designed to test and exercise these DLL's I do not see this behavior.
Solved! Go to Solution.
01-25-2021 09:09 PM - edited 01-25-2021 09:12 PM
Hi,
It seems like you are unloading the DLL somewhere.
Please check the load/unload options of your steps and the global TestStand setting.
If you have a big sequence file that may be painful. If you put a breakpoint in your DLLMain function, inside DLL_DETACH block, you can detect the point where your DLL gets unloaded.
Hope this helps
01-26-2021 09:52 AM