Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  • Create a "Standard project" and select CODESYS Control Win V3 as the device.
  • Define the target system by means of the Network scan.


  • Open the Library Manager and add the Netzwork library.


  • Add a global variable list to the project and define the following variables:



    Section
    Column
    width93
    Code Block
    themeConfluence
    {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





  • Add a POU to the project and name is UdpClient.



  • Adapt the POU UdpClient as follows:



    Section
    Column
    width7

    Declaration

    Column
    width93
    Code Block
    themeConfluence
    VAR
        fbPeerClient    :    NBS.UDP_Peer;
        fbReceive       :    NBS.UDP_Receive;
        sRcvMsg         :    STRING;
    END_VAR




    Section
    Column
    width7

    Implementation

    Column
    width93
    Code Block
    themeConfluence
    fbPeerClient(xEnable := TRUE, ipAddr:= GVL.stIpAddr, uiPort:= GVL.uiPort + 1);
    
    fbReceive(xEnable := (fbPeerClient.hPeer <> CAA.gc_hINVALID), 
                hPeer := fbPeerClient.hPeer, 
                szSize := SIZEOF(sRcvMsg), 
                pData := ADR(sRcvMsg));





  • Adapt the POU PLC_PRG as follows:


    Section
    Column
    width7

    Deklaration

    Column
    width93
    Code Block
    themeConfluence
    VAR
    	fbPeerServer    :    NBS.UDP_Peer;
        fbSend          :    NBS.UDP_Send;
        xSend           :    BOOL;
        sSendMsg        :    STRING := 'Hello World';
    END_VAR




    Section
    Column
    width7

    Implementierung

    Column
    width93
    Code Block
    themeConfluence
    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





  • Start the project and set the xSend variable to TRUE.