Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Ethernet Rx Block Filtering

Filtering Ethernet data using the Ethernet Rx block.

This example shows how to use blocks in the library xpcethernetlib to filter Ethernet data based on the packet's EtherType. EtherType is a field in the Ethernet networking standard that designates which protocol is being transported in the Ethernet packet. Packets of signal data are sent by the transmitter model, xpcEnetDemo4Tx, running on one target computer, TargetPC1, to the receiver model, xpcEnetDemo4Rx, running on the second target computer, TargetPC2. The "Ethernet Rx" block is used to specify the EtherType filter criteria. In this simple example, two separate Ethernet Rx blocks are used to receive and filter data packets. One Ethernet Rx block accepts SERCOS-III packets (EtherType - 88CD), the second Ethernet Rx block accepts EtherCAT® packets (EtherType - 88A4). Go to the Filter tab in the respective Ethernet Rx blocks to see EtherType specification options.

Notes:

  1. Real SERCOS-III and EtherCAT packets are not being transmitted. Only the EtherType field in the Ethernet packet is set to emulate these types.

  2. This model shows how to receive and process packets using multiple Ethernet Rx blocks. Compare this example with xpcEnetDemo3 which uses one Ethernet Rx block and then parses data packets with the Network Buffer Filter block. Use the method shown in this example, xpcEnetDemo4, if you want more than one Ethernet Rx block - perhaps each contained in separate subsystems.

Requirements

To run this example, you will need two target computers each with a properly installed and configured dedicated Ethernet card (in addition to the Ethernet card used for host-target communications). Refer to the Simulink Real-Time documentation on model-based Ethernet communications for details. Once configured, set the PCI Bus and Slot in the "Ethernet Init" block of xpcEnetDemo4Tx and xpcEnetDemo4Rx 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: xpcEnetDemo4TxxpcEnetDemo4Tx. 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, 'xpcEnetDemo4Tx'))
  mdlOpen = 1;
  open_system('xpcEnetDemo4Tx');
end

% Build the model and download to the Tx target computer, TargetPC1.
set_param('xpcEnetDemo4Tx','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('xpcEnetDemo4Tx');                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcEnetDemo4Tx
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Successful completion of build procedure for model: xpcEnetDemo4Tx
### Looking for target: TargetPC1
### Download model onto target: TargetPC1
% Close the model if we opened it.
if (mdlOpen)
  bdclose('xpcEnetDemo4Tx');
end

Open, Build, and Download the Rx Model to TargetPC2

Click here to open the Rx model: xpcEnetDemo4RxxpcEnetDemo4Rx. This model filters packets based on 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, 'xpcEnetDemo4Rx'))
  mdlOpen = 1;
  open_system('xpcEnetDemo4Rx');
end

SERCOS-III Receiver Subsystem

open_system('xpcEnetDemo4Rx/SERCOS-III Receiver');

EtherCAT Receiver Subsystem

open_system('xpcEnetDemo4Rx/EtherCAT Receiver');

Select the Ethertype(s) of interest on the Filter tab of the Ethernet Rx block. As example, SERCOS-III packet are selected here:

% Build the model and download to the Rx target computer, TargetPC2.
set_param('xpcEnetDemo4Rx','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('xpcEnetDemo4Rx');                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcEnetDemo4Rx
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Successful completion of build procedure for model: xpcEnetDemo4Rx
### Looking for target: TargetPC2
### Download model onto target: TargetPC2
% Close the model if we opened it.
if (mdlOpen)
  bdclose('xpcEnetDemo4Rx');
end

Run both Models

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

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

Display the Tx Target Computer Scope

Take a snapshot of the Tx target computer video display. Plotted is the signal data that's sent to the Rx target computer via raw Ethernet.

xpctargetspy('TargetPC1')

Display the Rx Target Computer Scopes

Take a snapshot of the Rx target computer video display. Plotted is the signal data received by the Tx target computer via raw Ethernet. Note that only data with SERCOS-III and EtherCAT EtherTypes are pass through the respective Ethernet Rx blocks.

xpctargetspy('TargetPC2')

Stop both Models

When done, stop the models from running.

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

% EOF xpcEnetDemo3.m
Was this topic helpful?