MATLAB: Can’t TCPIP connect to the instrument and how can I troubleshoot TCP/IP connection issues

instrumentInstrument Control Toolboxtcpipvisa

I am trying to connect to my instrument using TCPIP.
However I am receiving the following error:
>> t = tcpip('192.168.1.111', 4000);
>> fopen(t)
Error using icinterface/fopen (line 83)
Unsuccessful open: Connection refused
How can I troubleshoot TCP/IP connection issues?

Best Answer

If your instrument supports TCP socket communication (as an alternative to VISA TCP/IP) by allowing control and communication on a static TCP/IP port:
t = tcpip('192.168.1.111', port)
The port number is usually set by convention by the manufacturer (for example the default is 4000 for Tektronix, or 5025 for Agilent/Keysight), but a TCP socket server might need to be explicitly enabled on the instrument.
From the command prompt (Windows) or terminal (Mac OS X or Linux):
1. Try ping with the instrument IP address to verify that the IP address can be reached
ping 192.168.1.111
2. Try telnet with the instrument IP address and port to verify that the port is accessible
telnet 192.168.1.111 4000
If not able to connect to specified port using MATLAB, telnet, or another network tool:
     - Have you specified the correct port number (check instrument manual, or contact manufacturer)
     - Is there a TCP socket server service listening at the specified port --- on certain Tektronix oscilloscope models you might have to enable the socket server, which is a feature provided by TekVISA running on the instrument itself (from TekVisa LAN Server Control), and which can provide a raw TCP connection for instrument control.
     - If the instrument has a built-in PC running the TCP socket server -- is there a firewall on the instrument's PC blocking communication?
     - Is there a firewall on the client PC blocking communication?
Note: As an alternative (only on Microsoft Windows and MAC OS X, as VISA is not supported on 64-bit Linux as of MATLAB R2016a), many LAN-based instruments provide a VISA VXI-11 TCP/IP communication option.
If so, you should be able to detect in MATLAB and vendor software utility (NI VISA, Agilent/Keysight IO Libraries, TekVISA) a VISA resource name (for example 'TCPIP0::192.168.1.111::INSTR'), which can be used in MATLAB with a VISA connection:
>> v= visa('ni', 'TCPIP0::192.168.1.111::INSTR');