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:
EtherType : 88CD (SERCOS-III)
EtherType : 88A4 (EtherCAT®)
EtherType : 0800 (IPv4)
In this example, only packets with EtherTypes 88CD (SERCOS-III) and 88A4 (EtherCAT) are transmitted, received, and plotted.
Real SERCOS-III and EtherCAT packets are not being transmitted. Only the EtherType field in the Ethernet packet is set to emulate these types.
|On this page…|
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 xpcEnetDemo3Tx and xpcEnetDemo3Rx to that of the Ethernet card installed in TargetPC1 and TargetPC2 respectively.
Click here to open the Tx model: xpcEnetDemo3TxxpcEnetDemo3Tx. 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('xpcEnetDemo3Tx'); end
% Build the model and download to the Tx target computer, TargetPC1. set_param('xpcEnetDemo3Tx','RTWVerbose','off'); % Configure for a non-Verbose build. rtwbuild('xpcEnetDemo3Tx'); % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcEnetDemo3Tx ### Generated code for 'xpcEnetDemo3Tx' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for model: xpcEnetDemo3Tx ### Looking for target: TargetPC1 ### Download model onto target: TargetPC1
% Close the model if we opened it. if (mdlOpen) bdclose('xpcEnetDemo3Tx'); end
% Open the model. mdlOpen = 0; systems = find_system('type', 'block_diagram'); if ~any(strcmp(systems, 'xpcEnetDemo3Rx')) mdlOpen = 1; open_system('xpcEnetDemo3Rx'); end
% Build the model and download to the Rx target computer, TargetPC2. set_param('xpcEnetDemo3Rx','RTWVerbose','off'); % Configure for a non-Verbose build. rtwbuild('xpcEnetDemo3Rx'); % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcEnetDemo3Rx 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: xpcEnetDemo3Rx ### Looking for target: TargetPC2 ### Download model onto target: TargetPC2
% Close the model if we opened it. if (mdlOpen) bdclose('xpcEnetDemo3Rx'); end
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.
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.
Take a snapshot of the Rx target computer video display. Plotted is 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.
When done, stop the models from running.
stop(tgTx); % Stop the Tx model. stop(tgRx); % Stop the Rx model. % EOF xpcEnetDemo3.m