Instrument Control Toolbox | ![]() ![]() |
Example: Writing and Reading Data with a UDP Object
This example illustrates how to use text read and write operations with a UDP object connected to a remote instrument.
The instrument used is an echo server on a Linux-based PC. An echo server is a service available from the operating system that returns (echoes) received data to the sender. The host name is daqlab11
and the port number is 7
. The host name is assigned by your network administrator.
daqlab11
.
u
to the echo server.
fprintf
function to write text data to the instrument. For example, write the following string to the echo server.
You use the fscanf
function to read text data from the echo server.
The DatagramTerminateMode
property indicates whether a read operation terminates when a datagram is received. By default, DatagramTerminateMode
is on
and a read operation terminates when a datagram is received. To return multiple datagrams in one read operation, set DatagramTerminateMode
to off
. The following commands write two datagrams. Note that only the second datagram sends the terminator character.
Since DatagramTerminateMode
is off
, fscanf
reads across datagram boundaries until the terminator character is received.
u
, you should disconnect it from the host, and remove it from memory and from the MATLAB workspace.
![]() | Example: Writing and Reading Data with a TCP/IP Object | Events and Callbacks | ![]() |