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.
- Real SERCOS-III and EtherCAT packets are not being transmitted. Only the EtherType field in the Ethernet packet is set to emulate these types.
- 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.
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 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: xpcEnetDemo4Tx. 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(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpcEnetDemo4Tx')); 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('xpcEnetDemo4Tx','RTWVerbose','off'); evalc('rtwbuild(''xpcEnetDemo4Tx'')'); if (mdlOpen) bdclose('xpcEnetDemo4Tx'); end
Open, Build, and Download the Rx Model to TargetPC2
Click here to open the Rx model: xpcEnetDemo4Rx. 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(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpcEnetDemo4Rx')); end
SERCOS-III Receiver Subsystem
EtherCAT Receiver Subsystem
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.
Configure for a non-Verbose build. Build and download application. Close the model if we opened it.
set_param('xpcEnetDemo4Rx','RTWVerbose','off'); evalc('rtwbuild(''xpcEnetDemo4Rx'')'); if (mdlOpen) bdclose('xpcEnetDemo4Rx'); 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:
Display the Rx Target Computer Scopes
View 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 only data with SERCOS-III and EtherCAT EtherTypes are pass through the respective Ethernet Rx blocks. Use command:
Stop both Models
When done, stop the models from running.
- Stop the Tx model.
- Stop the Rx model.