- Create a "Standard project" and select CODESYS Control Win V3 as the device.
- Define the target system by means of the Network scan.
As of SP17:
- Open the Library Manager and add the following libraries:
Net Base Services
StringUtils Create a global variable list named gvlSettings gvlSettings and define the following variables:
Section Column Code Block theme Confluence {attribute 'qualified_only'} VAR_GLOBAL // !!! Make sure that the firewall does not block these ports !!! uiPort : UINT := 50000; // Port for the sender => receiver will set to uiPort + 1 sIPAddres : STRING(19) := '192.168.99.109'; END_VAR
- Add a POU to the project and name is UdpClient.
- Adapt the POU UdpClient as follows:
Section Column width 7 Declaration
Column width 93 Code Block theme Confluence VAR fbPeerClient : NBS.UDP_Peer; ipAddress : NBS.IPv4Address; xPeerActiv : BOOL := TRUE; fbSend : NBS.UDP_Send; xSend : BOOL; sSendMsg : STRING(255) := 'Hello World'; END_VAR
Section Column width 7 Implementation
Column width 93 Code Block theme Confluence IF xPeerActiv AND NOT fbPeerClient.xBusy THEN ipAddress.SetInitialValue(ipAddress := gvlSettings.sIPAddres); fbPeerClient(xEnable := TRUE, itfIPAddress := ipAddress, uiPort := gvlSettings.uiPort + 1); END_IF fbPeerClient(); fbSend(xExecute := xSend AND fbPeerClient.xBusy, itfPeer := fbPeerClient, itfIPAddress := ipAddress, uiPort := gvlSettings.uiPort, pData := ADR(sSendMsg), udiSize := DINT_TO_UDINT(Stu.StrLenA(ADR(sSendMsg)))); IF xSend THEN xSend := FALSE; END_IF
- Adapt the POU PLC_PRG as follows:
Section Column width 7 Declaration
Column width 93 Code Block theme Confluence VAR fbPeerServer : NBS.UDP_Peer; ipAddress : NBS.IPv4Address; fbReceive : NBS.UDP_Receive; xPeerActiv : BOOL := TRUE; xRead : BOOL; abyReceive : ARRAY [0..255] OF BYTE; sLastValidReceive : STRING(255); udiIndex : UDINT; END_VAR
- sdgasdfg
Up to SP16:
- Open the Library Manager and add the Network add the Netzwork library.
Add a global variable list to the project and define the following variables:
Section Column width 93 Code Block theme Confluence {attribute 'qualified_only'} VAR_GLOBAL sIpAddr : NBS.IP_ADDR := (sAddr := '192.168.99.74'); // Change to own IP-Address // !!! Make sure that the firewall does not block these ports !!! uiPort : UINT := 8181; // Port for the sender => receiver will set to uiPort + 1 END_VAR
...
Adapt the POU PLC_PRG as follows:
Section Column width 7 DeklarationDeclaration
Column width 93 Code Block theme Confluence VAR fbPeerServer : NBS.UDP_Peer; fbSend : NBS.UDP_Send; xSend : BOOL; sSendMsg : STRING := 'Hello World'; END_VAR
Section Column width 7 ImplementierungImplementation
Column width 93 Code Block theme Confluence UdpClient(); fbPeerServer(xEnable := TRUE, ipAddr := GVL.stIpAddr, uiPort := GVL.uiPort); IF fbPeerServer.hPeer <> CAA.gc_hINVALID THEN fbSend(xExecute := xSend, hPeer := fbPeerServer.hPeer, ipAddr := GVL.stIpAddr, uiPort := GVL.uiPort + 1, szSize := SIZEOF(sSendMsg), pData := ADR(sSendMsg)); END_IF IF xSend THEN xSend := FALSE; END_IF
...