03-23-2017 01:28 PM
I have a nother problem with the MATLAB script node. When using the MATLAB node the "MATLAB command window" opens as soon as a VI containing this node is loaded into memory.
Now the problem is that after a few hours the MATLAB command window crashes randomly when I execute my main program which leads to an error "1047: LabVIEW: LabVIEW failed to send variable to the script server." One can simulate this behaviour by opening the attachted vi and closing the command window by hand before running the vi.
Now my question is if there is any way to restart the Matlab Command window without restarting labview or stopping my programm? This would be the easiest solution for my problem as I dont think that I will be able find the source of the crash itsself.
Thanks for your help!
Solved! Go to Solution.
03-28-2017 03:07 AM - edited 03-28-2017 03:15 AM
this sounds to me like a case for local error handling, actually. I attached a modified version just to show you how it works in principal. For your application you have to see how it works with your logic, so that you can keep yor program running. I would try calling the MathScript from within a SubVI and when the error occurs send a message to the main VI to re-call the corresponding sub VI.
The thing with the crashing matlab command window is, that I don't know if you can simply call it again, or if some matlab process in the backgrond has to be stopped. I don't have matlab installed, so unfortunately, I can't help you on this end, but you are able to run a command prompt and kill any remaing matlab processes. Here are the links for ending a task from within LabVIEW:
How Do I Execute a Windows Command in LabVIEW? - National Instruments
Kill Processes From The Command Prompt In Windows 7
On a side-node: you can take a look at the Structured Error Handler Template, this might solve the problem for you how to react to an error:
Structured Error Handler (SEH) Library - National Instruments
I hope this helps you along!
03-28-2017 04:16 AM
Thanks a lot for your help! Your suggestion is exactly what i tried to do. Unfortunately LabVIEW does not find the MATLAB server if I relaunch it from the windows console.
However I now found out that LabVIEW reinitializes the Matlab window again if all VI's that contain Matlab Script nodes are removed from memory and then of these VI's is called by reference. I think I can rewrite my application in some way to make this work as error handling after Matlab crashed.
After several hours of search I could also find out what part of the code is responsible for the crash. If I use the function
"imagesc(Img);" in Matlab where Img is a 2D array of doubles then matlab crashes after ~5000 calls.
03-28-2017 06:47 AM
And you are right, it sounds easier to implement your solution in LabVIEW rather than trying to solve the problem in Matlab - which sounds like a reference/memory leak to me.