MATLAB Examples

Filtering on EtherType

Filtering Ethernet data using EtherType.

This example shows how to use blocks in the library xpcethernetlib to filter Ethernet data based on the sender's EtherType. EtherType is a field in the Ethernet networking standard and indicates which protocol is being transported in an Ethernet packet. Signal data is sent by the transmitter model, xpcEnetDemo3Tx, running on one target computer, TargetPC1, to the receiver model, xpcEnetDemo3Rx, running on the second target computer, TargetPC2. The "Filter Type" block is used to specify the EtherTypes that will be accepted. In this simple example, data packets containing one of three different EtherTypes are allowed to pass through respective Filter Type blocks in the receiver model. The accepted Ether Types are:

  1. EtherType : 88CD (SERCOS-III)
  2. EtherType : 88A4 (EtherCAT®)
  3. EtherType : 0800 (IPv4)

Notes:

  1. In this example, only packets with EtherTypes 88CD (SERCOS-III) and 88A4 (EtherCAT) are transmitted, received, and plotted.
  2. Real SERCOS-III and EtherCAT packets are not being transmitted. Only the EtherType field in the Ethernet packet is set to emulate these types.

Contents

Requirements

To run this example, you will need two target computers, each with an installed and configured dedicated Ethernet card (in addition to the Ethernet card used for the Ethernet link between the development and target computers). Refer to the Simulink® Real-Time™ documentation on model-based Ethernet communications for details. Once configured, set the PCI Bus and Slot in the "Real-Time Ethernet Configuration" block of xpcEnetDemo3Tx and xpcEnetDemo3Rx to that of the Ethernet card installed in TargetPC1 and TargetPC2 respectively.

Open, Build, and Download the Tx Model to TargetPC1

Click here to open the Tx model: xpcEnetDemo3Tx. This model drives an oscillator with a square wave signal and sends the oscillator input and output signals to the Rx target computer. The oscillator input (square wave) is transmitted as a SERCOS-III packet and the oscillator output is transmitted as an EtherCAT packet. Open the model.

mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp(systems, 'xpcEnetDemo3Tx'))
  mdlOpen = 1;
  open_system(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpcEnetDemo3Tx'));
end

Build the model and download to the Tx target computer, TargetPC1.

  • Configure for a non-Verbose build.
  • Build and download application.
  • Close the model if we opened it.
set_param('xpcEnetDemo3Tx','RTWVerbose','off');
evalc('rtwbuild(''xpcEnetDemo3Tx'')');
if (mdlOpen)
  bdclose('xpcEnetDemo3Tx');
end

Open, Build, and Download the Rx Model to TargetPC2

Click here to open the Rx model: xpcEnetDemo3Rx. This model filters packets based on specified EtherType and unpacks the received data for display in target scopes. Open the model.

mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp(systems, 'xpcEnetDemo3Rx'))
  mdlOpen = 1;
  open_system(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpcEnetDemo3Rx'));
end

Build the model and download to the Rx target computer, TargetPC2.

  • Configure for a non-Verbose build.
  • Build and download application.
  • Close the model if we opened it.
set_param('xpcEnetDemo3Rx','RTWVerbose','off');
evalc('rtwbuild(''xpcEnetDemo3Rx'')');
if (mdlOpen)
  bdclose('xpcEnetDemo3Rx');
end

Run both Models

Using the Simulink Real-Time object variables tgTx and tgRx, start the models.

  • Start the Tx model.
  • Start the Rx model.
  • Let the models run for at least 5 sec.
start(tgTx);
start(tgRx);
pause(5);

Display the Tx Target Computer Scope

View the Tx target computer video display. It displays a plot of the signal data that is sent to the Rx target computer via raw Ethernet. Use command:

tgTx.viewTargetScreen;

Display the Rx Target Computer Scopes

Voew the Rx target computer video display. It displays a plot of the signal data received from the Tx target computer via raw Ethernet. Note that data with EtherTypes SERCOS-III and EtherCAT pass through the filters. Use command:

tgRx.viewTargetScreen;

Stop both Models

When done, stop the models from running.

  • Stop the Tx model.
  • Stop the Rx model.
stop(tgTx);
stop(tgRx);