08-04-2017 03:23 PM
Can someone help me figure why this statement is evaluating as true?
Both the TotalDataPoints and CurrentDataCount variables are static int declared before main( ).
What's happening in the screen shots is, the programming environment is currently halted as it threw an error because the TdmsFileHandle was not initialized properly. I moused over the variables in the halted state to show the current variable values.
The issue is that TotalDataPoints = 153600 and CurrentDataCount = 0, yet the condition is evaluating as true and executing the IF statement when it should be false.
Anyone have a guess why this is happening? It only occurs when I compile the program and the function is executed for the first time. Subsequent calls, when the variables hold the same values, evaluates the IF expression properly as false.
CURRENTLY HALTED AT TDMS_SaveFile:
Solved! Go to Solution.
08-05-2017 11:10 AM
Hi there,
Is there any other threads accessing the data? What happens if you don't make them static? They won't retain values between invocations of the function so you should see a difference from subsequent runs of the functions that access this data.
Does this data get written to from the GUI by any field?
Can you replicate this with a simple example?
Thanks,
Ed
08-06-2017 05:15 PM
From what you describe it sounds like it is possible that your variables are initially uninitialized and then wrongfully evaluates as true when it should be false. Try explicitly initializing the variables at startup.
The second possibly is timing. You might execute your failing routine before the variables were accessed.
08-07-2017 09:32 AM
Thanks Jattie, that was it. I officially hate programming with callbacks.
You can never be confident of timing or program flow when DAQmxRegisterEveryNSamplesEvent is running. The function in question was being called before CurrentDataCount was initialized and was showing as 0 in the mouse-over event.
If the program flowed as-designed without the daq DAQmxRegisterEveryNSamplesEvent breaking in, all would have been well. There needs to be a better way of tracking events when a function can take over your program flow at any arbitrary instant.
Thanks -