Troubleshoot Communication Failure Through Firewall (Windows)
When I attempt to connect to the target computer by using Simulink Real-Time Explorer, I see this error message.
Error: Cannot connect to target 'TargetPC1': Cannot connect to target.
Even though the connection fails, clicking on the Update button or Reboot button in Simulink Real-Time Explorer works. These operations indicate that the target computer can be reached through the Ethernet port.
What This Issue Means
In R2020b and later releases, Simulink Real-Time uses a protocol for the development-to-target computer connection that is blocked by default in Window Defender Firewall for networks classified as Public. Windows also classifies all Ethernet connections as Public by default.
If you do not select the correct options when first running MATLAB, it is can be possible to ping, update, and reboot the target computer from MATLAB. But, these incorrect option selections prevent communication connection to the target computer. This communication connection is necessary to load and run real-time applications on the target computer.
Try These Workarounds
Resolve this issue by allowing MATLAB to communicate on all types of networks. Apply this setting when prompted on first connection or apply this setting later through the Windows Defender Firewall Allow an app through Windows Firewall selection. If that is not possible due to privilege restrictions, the issue can also be resolved by changing the classification of the Ethernet interface used for development-to-target computer connection from Public to Private.
If you develop a compiled application as described in Create Standalone Instrument Panel App by Using Application Compiler, apply these workarounds to let the compiled application communicate with the target computer through the firewall.
Allow MATLAB for Public and Private Networks by Using Prompt
When you first try to connect to a target computer, Windows Defender Firewall prompts you to allow MATLAB to communicate on Private and Public networks. Make sure that both Private and Public options are selected. Only one is selected by default.
Click Allow access.
Manually Allow MATLAB for Public and Private Networks
From the Windows Start menu, search
Allow an app through Windows
Click the Allow an app through Windows Firewall option.
Scroll down in the Allowed apps and features list and find the MATLAB release that you are using.
If both Private and Public check boxes are selected, see Configure Development-to-Target Computer Ethernet Interface as Private.
Click the Change settings button and confirm the security dialog. Make sure that the Private and Public boxes are selected. A Domain option or others may be available, but these options are not relevant for the MATLAB network access configuration.
Configure Development-to-Target Computer Ethernet Interface as Private
You can use the Windows UI or PowerShell command window to configure development-to-target computer Ethernet interface as private.
Windows UI Method
The Windows UI method is straightforward, but may not be available depending on your system configuration. If not, use the PowerShell Command Window Method.
Right-click on the Wi-Fi or Ethernet network icon in the lower right corner of the Windows taskbar (next to the clock).
Select Open Network & Internet settings.
Under the Ethernet section, click Properties.
Select the radio button for Private.
PowerShell Command Window Method
Right-click on the Windows Start menu and click the Windows PowerShell (Admin) selection.
Run the command
Find the name of the Ethernet interface that you are using for development-to-target computer communication.
Enter the command
Use the interface name that you find as the
Confirm the changes by running
For example, if the interface is named
enter the command:
Set-NetConnectionProfile -Name "Unidentified network" -NetworkCategory "Private"
Confirm Successful Configuration
To confirm successful configuration, in Simulink Real-Time Explorer or in the Simulink Editor on the Real-Time tab, click the Disconnected button. Confirm that the button label changes to Connected.
If the label does not change to Connected, the connection problem persists. Contact a systems administrator for further assistance. Administrator credentials may be required to configure the Windows Defender Firewall, or there may be another firewall on the development computer that requires configuration. A systems administrator may need to allow communications on specific ports or add more specific firewall rules.