0% found this document useful (0 votes)
236 views

Selecontrol® Mas: Tcp/Ip and Udp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
236 views

Selecontrol® Mas: Tcp/Ip and Udp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

SELECONTROL® MAS

TCP/IP and UDP

This material has been compiled exclusively for training. Subsequently, it will not
be revised or updated in any way. It is intended only for your own personal use.
This material has been compiled with utmost care but, by way of exception, may
contain erroneous or misleading particulars for which Selectron Systems AG
cannot accept any liability. The contents of this material are for internal use only.
No part may be reproduced, utilized and/or communicated to others, unless
expressly authorized by Selectron Systems AG.
Selectron Systems AG reserves all rights to the acquisition and registration of
commercial property rights, particularly those for filing patent, utility model and/or
design applications.

Knorr-Bremse Group
Overview

Introduction
 The OSI Layer Model
 User Datagram Protocol (UDP)
 Transmission Control Protocol (TCP)

MOS Libraries for Ethernet Communication


 General
 NET_MLib
 ETHx_MLib

Textfeld für Quellen und Fußnoten


Knorr-Bremse Group |2
The OSI Layer Model

Introduction

The OSI Layer Model

 Multi-layer reference model which assigns different communication functions to the various layers
 It serves as a theoretical model for modern communication systems

ISO/OSI

7 Application layer
HTTP SNMP FTP TRDP CIP Modbus TCP/IP

6 Presentation layer
TCP / UDP
5 Session layer
IP
4 Transport layer
Ethernet
3 Network layer

2 Data link layer UDP or TCP are not on Application level


Ethernet is not a Protocol
1 Physical layer

Knorr-Bremse Group |3
Introduction
UDP TCP
Connection-less service Connection-oriented service
Example of datagram sockets Example of stream sockets

No retransmission and Provides retransmission


no error & flow control and error & flow control

High transmission speed but not as high


Very high transmission speed (best effort)
than UDP
Non-guaranteed transfer Reliable transfer with acknowledgements

Routing: Routing:

Can be full duplex Is full duplex


Typical applications: Typical applications:
VoIP, streaming services Email, Web browsing, data exchange

Knorr-Bremse Group |4
Introduction

UDP – User Datagram Protocol

 Transaction oriented
 Delivery and duplicate protection are not guaranteed
 Datagram mode of packet-switched computer communication
 Major uses are DNS (Domain Name Server) NTP (Network Time Protocol), SNMP (Simple Network Management
Protocol) and TFTP (Trivial File Transfer Protocol)
 The field size has a theoretical limit of 65,535 bytes

Bits 0 78 1516 2324 31


Source Port Destination Port
Length Checksum
data octets

Knorr-Bremse Group |5
Introduction

TCP - Transmission Control Protocol

 Connection-oriented
 Highly reliable host-to-host protocol
 Able to transfer a continuous stream of octets in each direction
 Must recover from data that is damaged, lost, duplicated, or delivered out of order
 Provides a means for the receiver to govern the amount of data sent by the sender (flow control)

Bits 0 78 1516 2324 31


Source Port Destination Port
Sequence Number
Acknowledgement Number
UAPRSF
Data
Reserved R C S S Y I Window
Offset GKHTNN
Checksum Urgent Pointer
Options Padding
data
Knorr-Bremse Group |6
MOS Libraries for Ethernet Communication

General

 The Ethernet manufacture libraries are designed for IPv4


 MOS version MOS83x_V606.ECEF provides 5 TCP sockets
 MOS version MOS83x_V700.A5BC or higher provides 20 TCP sockets
 MOS version MOS83x_V722.A9DC or higher provides 100 TCP sockets
 MOS version MOS83x_V710.ECA7 or higher uses at least 5 Sockets for Ethernet services
 Ethernet MLibs
− NET_MLib: Functions for Ethernet connectivity and TCP/UDP (MOS83x_V700.A5BC and higher)
− DNS_MLib: Functions for the DNS (MOS83x_V723.C69B and higher)
− EIPAx_MLib: Functions for EtherNet/IP (CIP) (MOS83x_V723.C69B and higher)
− ETHx_MLib: Functions for ICMP, IGMP, UDP and TCP (MOS83x_V723.C69B and higher)
− FTPC_MLib: Functions for FTP (MOS83x_V723.C69B and higher)
− SNMP_MLib: Functions for SNMP (MOS83x_V723.C69B and higher)
− TRDPx_MLib: Functions for TRDP (MOS83x_V723.C69B and higher)
− TRDPMx_MLib: Functions for TRDP master (MOS83x_V723.C69B and higher)

Knorr-Bremse Group |7
MOS Library NET_Mlib

TCP - Transmission Control Protocol

NET_COMMUNIC
 Can be used as a server or client
 Passes the received data as a byte stream
 User has to extract the frames from the TCP stream
UDP – User Data Protocol

LAN_UDP_INSTALL
 Installs a UDP socket
 A socket has a full duplex capability
 Each socket has queues for sending and receiving data
LAN_UDP_SENDTO
 Sends an UDP datagram packaged in a DUT structure
 An unicast datagram can send up to 4080 bytes
LAN_UDP_RECVFROM
 Receives an UDP datagram packaged in a DUT
structure
 A maximum of 4080 bytes can be received
Knorr-Bremse Group |8
MOS Library ETHx_MLib

Get IP configuration

ETH_X_GET_IP_CONFIG reads the configuration of an Ethernet interface

 The process is started with a positive pulse at input pGet


 xDHCP is set if the interface is configured via DHCP
 DHCP server has not yet assigned the IP address:
− iStatus takes the value –32’758
− sIpAddress, sSubNetmask, and sGateway return address "0.0.0.0“
− tDhcpLeaseTime returns 0 ms
 DHCP server has assigned an address to the interface:
− iStatus is set to 0
− sIpAddress, sSubNetmask, sGateway, and tDhcpLeaseTime return values assigned from the server

Knorr-Bremse Group |9
MOS Library ETHx_MLib

ICMP echo request (ping)

ETH_X_PING sends an ICMP echo request (ping) to the specified IP address dwIpAddress and waits for a response
from the partner station.

 An ICMP echo request is sent to the partner with a positive edge at input xEnable
 The result is signaled via outputs pDone and pError
 tTimeout indicates the wait time for a response:
− No response within this wait time → error –32’757
− Partner responds within the timeout → positive pulse at pDone and calculation of delay time tDelayTime

Knorr-Bremse Group | 10
MOS Library ETHx_MLib

UDP – User Data Protocol

ETH_X_UDP_SOCKET
 Opens a UDP datagram socket and binds it to the
specified port
 A full duplex socket is created
 Any existing receive data should be read to not block
resources unnecessarily in case data is only sent
ETH_X_SENDTO
 Enables connectionless sending of data to a socket
 The to send data is packed in a DUT
ETH_X_RECVFROM
 Enables connectionless receiving of data from a socket
 The to receive data is packed in a DUT

Knorr-Bremse Group | 11
MOS Library ETHx_MLib

TCP - Transmission Control Protocol

ETH_X_TCP_SERVER
 Opens a TCP server socket on the specified port
 Accepted connections continue to exist, even if the
server is closed
ETH_X_TCP_CONNECTION
 Accepts an incoming client connection to the
given server
 Indicates address and port of the client
 Exchanged keep-alives in the case of an inactive
connection (75s interval)
 Nagle's algorithm is disabled
ETH_X_TCP_CLIENT
 Creates a connection to a TCP server
 Exchanged keep-alives in the case of an inactive
connection (75s interval)
 Nagle's algorithm is disabled

Knorr-Bremse Group | 12
MOS Library ETHx_MLib

TCP - Transmission Control Protocol

ETH_X_SEND
 Sends the data to the connected partner using the
provided socket
 The data to be sent is taken from a DUT
 Sending process may require multiple cycles depending
on the size of transmission data
 It is not guaranteed that the data arrives at the recipient
ETH_X_RECV
 Receives the data transmitted by the connected partner
from the provided socket
 The data is copied it to the DUT
 Receiving process may require multiple cycles
depending on the size of the data
 A TCP socket can store up to 16 kB data

Knorr-Bremse Group | 13
Error handling

Knorr-Bremse Group | 14
Setup for exercise on UDP

Exercise

 Change the IP address of one CPU and connect the two training boxes together
 Unplug the DDE 301 power supply on both training boxes
 Create an application and insert the resource, task, DUT and POU
 Add DDT 732 digital I/O module to PLC_Config and specify the I/O’s
 Use the ETHx_MLib function blocks (ETH_X_UDP_SOCKET, ETH_X_SENDTO, ETH_X_RECVFROM,
eth_x_ip_addr_to_dword) to set up an UDP communication
 Insert the functionality to pass the inputs of the CPU 1 to the outputs of the CPU 2 and vice versa
 Optional: Check the communication using Wireshark and the mirror port on the training box
 Optional: Implement an error handling in case of an open loop or a power loss of a CPU
CPU 1 DDT 732 CPU 2 DDT 732
IP: 192.168.0.2 digital I/O IP: 192.168.0.3 digital I/O

LAN 1

Knorr-Bremse Group | 15
Setup for exercise on UDP (see Online Help mETHx.chm)

The function block ETH_X_UDP_SOCKET opens a UDP socket and binds it


to the specified port @ uiUdpPort

The process is started with a positive edge at input xInstall.


The result is signaled by the Boolean outputs: xInstalled and xError.

With a negative edge, an open socket (xInstalled = TRUE) is closed.

diSocket is the resulting socket handle used for transmitting and receiving

Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 16
Setup for exercise on UDP

The function block ETH_X_SENDTO enables connectionless sending of data to


a socket.
With a positive pulse at input pSend, the process is started
The socket diSocket must first be created.
The communication partner is addressed via inputs dwPeerIpAddress and
uiPeerPort.
The send data is taken from a DUT, in which, data between dwStart and bEnd
is sent.
Because this is connectionless communication, it may occur that the data was
not delivered; for example, if the communication partner does not exist.
Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 17
Setup for exercise on UDP

The function block ETH_X_RECVFROM receives data from a socket.

The FB receives data when the input xReceive is set to True.


The socket diSocket must first be created
The reception of data is indicated by setting the output xReceived to True..
The communication partner is indicated via outputs dwPeerIpAddress and
uiPeerPort.
The received data is copied in a DUT; data between dwStart and bEnd
A UDP socket can store up to 4080 Bytes.

Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 18
Setup for exercise on TCP

Exercise

 Change the IP address of one CPU and connect the two training boxes together
 Unplug the DDE 301 power supply on both training boxes
 Create a server application (CPU 1) and a client application (CPU 2), and insert the resource, task, DUT and POU
 Add DDT 732 digital I/O module to PLC_Config and specify the I/O’s
 Use the ETHx_MLib function blocks (ETH_X_TCP_SERVER, ETH_X_TCP_CONNECTION, ETH_X_TCP_CLIENT,
ETH_X_SEND, ETH_X_RECV, eth_x_ip_addr_to_dword) to set up a TCP communication
 Insert the functionality to pass the inputs of the CPU 1 to the outputs of the CPU 2 and vice versa
 Optional: Check the communication using Wireshark and the mirror port on the training box
 Optional: Implement an error handling in case of an open loop or a power loss of a CPU
CPU 1 DDT 732 CPU 2 DDT 732
IP: 192.168.0.2 digital I/O IP: 192.168.0.3 digital I/O

LAN 1

Knorr-Bremse Group | 19
Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm

Setup for exercise on TCP

The function block ETH_X_TCP_SERVER opens a TCP server socket on


the specified port uiServerPort.

The server is installed at a positive edge at input xInstall.


The result is signaled by the Boolean outputs: xInstalled and xError.
If xInstalled is TRUE, incoming connections can be accepted with the
function block ETH_X_TCP_CONNECTION.
The accepted connections continue to exist, even if the server is closed with
a falling edge at input xInstall.

Knorr-Bremse Group | 20
Setup for exercise on TCP

The function block ETH_X_TCP_CONNECTION accepts an incoming client


connection to the given server, ETH_X_TCP_SERVER.
The connection process starts at positive edge at input xAccept.
The result is signaled by the Boolean outputs: xAccepted and xError.
When output xAccepted takes the value TRUE, the incoming connection was
accepted and, in the case of an inactive connection, keepalives are exchanged.
Outputs dwClientIpAddress and uiClientPort indicate the address of the client.
Using socket handle diSocket, data can be exchanged with the client with
function blocks ETH_X_SEND and ETH_X_RECV.
Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 21
Setup for exercise on TCP

The function block ETH_X_TCP_CLIENT creates a connection to a TCP server.

With a positive edge at input xConnect, the process starts.


The result is signaled by the Boolean outputs: xConnected and xError.
When output xConnected takes the value TRUE, the connection was created
and, in the case of an inactive connection, keepalives are exchanged.
Using socket handle diSocket, data is exchanged with the server with function
blocks ETH_X_SEND and ETH_X_RECV.

Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 22
Setup for exercise on TCP

The function block ETH_X_SEND sends the data to the connected partner
using the provided socket.

The data transmission starts at a positive edge at input xSend.


The Socket diSocket must previously have been created with the blocks
ETH_X_TCP_CLIENT or ETH_X_TCP_CONNECTION.
The data to be sent is taken from a DUT, the length of the data is indicated by
udiBytesToSend. Output udiBytesSent indicates the number of bytes sent.
The sending process may require multiple cycles depending on the size of
transmission data.
Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 23
Setup for exercise on TCP

The function block ETH_X_RECV receives the data transmitted by the


connected partner, from the provided socket and copies it to the DUT.
The data reception starts at a positive edge at input xReceive.
Socket diSocket must previously have been created with the blocks
ETH_X_TCP_CLIENT or ETH_X_TCP_CONNECTION. The received data is
copied into a DUT; The number of bytes to be received can be specified by the
input udiBytesToReceive. Output udiBytesReceived indicates the number of
bytes received by the FB.
When the receive process is completed and the flag xAppendable is set, then
the function block can react to input pAppend.
Quelle: C:\Selectron\MOS\MOS83x_V730.E26B\help\en\mETHx.chm
Knorr-Bremse Group | 24
Setup for error handling

Knorr-Bremse Group | 25
Thank you very much for your attention!

Selectron Systems AG Phone: +41 32 387 62 93


Customer Support and Training Email: [email protected]
Bernstrasse 70 www.selectron.ch
CH-3250 Lyss, Switzerland

Knorr-Bremse Group

You might also like