MATLAB: Simulink is already connected to another real-time model

ethquadrotorrealtimesimulinkSimulink Desktop Real-Timetargetxpc target

Hi, I'm using the real-time target and sometimes I get this error:
*Error occurred while executing External Mode MEX-file 'rtwinext':
Simulink is already connected to another real-time model. It is not allowed to connect to multiple real-time models simultaneously*
The only solution that I can apply is to restart the Computer and this is so bad.
I don't know why. Can you help me?
Thanks a lot!

Best Answer

This situation may happen if the real-time code terminates in some unusual way and does not properly disconnect from Simulink. To clean up manually without restarting the computer, please type these two commands:
rtclear
rtunload
If this does not help, a more aggresive way is to reinstall the real-time kernel (which cleans up all previous activities):
rtwintgt -setup