Instrument Control Toolbox | ![]() ![]() |
Example: Server Drops the Connection
This example shows what happens when a TCP/IP object loses its connection with a remote server. The server is a Sony/Tektronix AWG520 Arbitrary Waveform Generator (AWG). Its address is sonytekawg.mathworks.com
and its port is 4000. The AWG's host IP address is 192.168.1.10 and is user configurable in the instrument. The associated host name is given by your network administrator. The port number is fixed and is found in the instrument's documentation.
The AWG can drop the connection because it is taken off line, it is powered down, and so on.
fprintf(t,'*IDN?') fscanf(t) Warning: A timeout occurred before the Terminator was reached. (Type "warning off instrument:fscanf:unsuccessfulRead" to suppress this warning.) ans = ''
At this point, the object and the instrument are still connected.
If you attempt to write to the instrument again, an error message is returned and the connection is automatically closed.
fprintf(t,'*IDN?') ??? Error using ==> fprintf Connection closed by RemoteHost. Use FOPEN to connect to RemoteHost.
Note that if the TCP/IP object is connected to the local host, the warning message is not displayed. Instead, the error message is displayed following the next read operation after the connection is dropped.
t
, you should disconnect it from the host, and remove it from memory and from the MATLAB workspace.
![]() | The TCP/IP Object Display | Creating a UDP Object | ![]() |