MATLAB: Does MATLAB not recognize the Arduino board if the previous External mode simulation is interrupted in Simulink 8.0(R2012b) and onwards releases

arduinodisconnectexternalmodesimulink

If I run a model on Arduino board in external mode and then disconnect the cable or the cable connection becomes a little loose, I get the following error,
"Error occurred while executing External Mode MEX-file 'ext_serial_win32_comm'; ExtSetTargetPkt() call failed for ExtSendGenericPkt(). Ensure target is still running"
After that, I reconnect the cable and try to run the model again on Arduino board, I get errors asking me to check the target hardware connection and the COM port setting even though I have not changed the COM port number and the connection is fine.

Best Answer

This behavior can be observed in both Simulink R2012b and R2013a. When the serial communication is interrupted abruptly by events like unplugging of the cable or loosely connected hardware, the Arduino hardware deregisters itself from the operating system and this in turn results in Simulink environment being not able to find the Arduino hardware.
To avoid this problem, make sure that you have proper connection with the hardware and refrain from unplugging the cable while data is being exchanged between the host and the target.
If the issue does occur, the only workaround as of now is to close MATLAB, disconnect the Arduino, and restart MATLAB. In case where this does not address the issue, a complete restart of the computer is needed.
Related Question