| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Instrument Control Toolbox |
| Contents | Index |
| Learn more about Instrument Control Toolbox |
| On this page… |
|---|
Event Types and Callback Properties |
The event types and associated callback properties supported by TCP/IP and UDP objects are listed below.
TCP/IP and UDP Event Types and Callback Properties
Event Type | Associated Properties |
|---|---|
Bytes available | |
Datagram received | DatagramReceivedFcn (UDP objects only) |
Error | |
Output empty | |
Timer | |
The datagram-received event is described below. For a description of the other event types, refer to Event Types and Callback Properties.
A datagram-received event is generated immediately after a complete datagram is received in the input buffer.
This event executes the callback function specified for the DatagramReceivedFcn property. It can be generated for both synchronous and asynchronous read operations.
You can respond to event information in a callback function or in a record file. Event information stored in a callback function uses two fields: Type and Data. The Type field contains the event type, while the Data field contains event-specific information. As described in Creating and Executing Callback Functions, these two fields are associated with a structure that you define in the callback function header. Refer to Debugging: Recording Information to Disk to learn about storing event information in a record file.
The event types and the values for the Type and Data fields are given below.
TCP/IP and UDP Event Information
Event Type | Field | Field Value |
|---|---|---|
Bytes available | Type | BytesAvailable |
Data.AbsTime | day-month-year hour:minute:second | |
Datagram received | Type | DatagramReceived |
Data.AbsTime | day-month-year hour:minute:second | |
Data.DatagramAddress | IP address string | |
Data.DatagramLength | Number of bytes received as double | |
Data.DatagramPort | Port number of sender as double | |
Error | Type | Error |
Data.AbsTime | day-month-year hour:minute:second | |
Data.Message | An error string | |
Output empty | Type | OutputEmpty |
Data.AbsTime | day-month-year hour:minute:second | |
Timer | Type | Timer |
Data.AbsTime | day-month-year hour:minute:second |
The Data field values are described below.
AbsTime is defined for all events, and indicates the absolute time the event occurred. The absolute time is returned using the MATLAB Command window clock format.
day-month-year hour:minute:second
DatagramAddress is the IP address of the datagram sender.
DatagramLength is the length of the datagram in bytes.
DatagramPort is the sender's port number from which the datagram originated.
Message is used by the error event to store the descriptive message that is generated when an error occurs.
This example extends Example: Communicating Between Two Hosts to include a datagram received callback. The callback function is instrcallback, which displays information to the command line indicating that a datagram has been received.
The following command configures the callback for the UDP object u2.
u2.DatagramReceivedFcn = @instrcallback;
When a datagram is received, the following message is displayed.
DatagramReceived event occurred at 10:26:20 for the object: UDP-doetom.dhpc. 25 bytes were received from address 192.168.1.12, port 8844.
![]() | Writing and Reading Data | Using Device Objects | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |