10-14-2005 02:50 PM
10-17-2005 04:26 PM
10-17-2005 05:09 PM
10-18-2005 11:18 AM
10-19-2005 12:26 PM
If you have another minute, JLS, I'd like to see what you think of something. I have analyzed my data a little more, and I'm seeing two very distinct and unexplainable failures in my Labview/Matlab interaction.
I have a VI that receives some data and returns some data. Inside is a loop (designed to iterate only once, so that I can have shift registers) that contains a Matlab script. My shift registers are uninitialized, but I don't think this is a problem because my Matlab code is designed to recognize the first call and initialize the values itself. Matlab performs some operations on the shift register data and outputs it back to the shift registers for the next call. Some of this data is then passed out to the calling VI. For debugging purposes, I've written a logger in my Matlab script to dump the inputs and outputs to disk for future analysis.
Normally this system works quite well, but on occasion I'm seeing some very strange behaviour. There are two distinct cases that I find particularly disturbing:
1. Matlab receives the data correctly, manipulates it, but then it seems to be removed from Matlab memory before being outputted back to Labview. I know this because in my debug log the variable is received properly at the inputs but then is absent at the outputs (ie empty array). The code does nothing to clear the workspace memory, and I'm confident that it is not a bug in my Matlab code.
2. Matlab returns the data correctly (again, my debug log of the outputs shows the data is present and correct), and this is put into a shift register. The next time the VI is called, however, the shift register no longer contains the data. Matlab receives an empty array as input. It seems Labview sometimes loses shift register data from one call to the next. Nothing else is writing to these registers, so it's not a side effect of other code.
Both of these problems are intermittent, which is what led me to believe it may be a threading issue; however, with your help I am now confident that threads aren't a problem.
Have you ever seen or heard of such a problem before?
Thanks again for your help!!
cjb
10-20-2005 12:27 PM
10-20-2005 01:23 PM
Hi JLS,
My code is doing pretty much exactly what you've described, and normally behaves exactly as you've described. I have a subVI with a while loop that iterates only once, so that I can store data in shift registers. I have confirmed that most of the time the data remain in the registers across multiple calls, as they should. I am not initializing my shift registers directly (unlike your recommendation); instead, my Matlab code (inside the dummy while loop) is performing the initialization itself during the first call. I believe my setup should be equivalent to your description; indeed, most of the time this setup works properly. The shift registers are initialized to the proper value (by Matlab) and retain the proper data across all calls to the subVI.
On occasion, however, shift register data is lost from one call to the next during execution. The subVI is not being opened or closed, and no manual recompilation is being performed. I don't believe Labview should be recompiling my subVIs during execution, so I doubt this is the cause of my data loss. Are you aware of any case in which Labview would perform automatic recompilation during execution?
This is quite a mystery. Your descriptions indicate that I have the correct implementation, and indeed it usually works. Perhaps you are right that there is some subtle threading problem. I think I am going to have to move from a Labview/Matlab hybrid architecture towards a pure Labview implementation. This will create a lot of work, but I don't see any other way of solving this bug. 🙂
Thanks again for your help JLS,
cjb
10-21-2005 12:29 PM
10-25-2005 12:44 AM
Hi JLS,
Unfortunately I'm running an older version of Labview (6.1), so I can't open your files. 😞 Thanks for taking the time to make them for me though!
Also unfortunately, I can't really initialize my shift registers as I believe you are suggesting, because their size grows with time. Every time a new data point arrives, it is appended to the vector or array, and there is no way to know a priori how many data points there will be.
Anyway, I suppose we will just have to move away from the Labview/Matlab hybrid implementation.
Regards,
cjb
10-25-2005 02:14 PM