You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

  • 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:


    {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:


    Declaration

    VAR
        fbPeerClient    :    NBS.UDP_Peer;
        fbReceive       :    NBS.UDP_Receive;
        sRcvMsg         :    STRING;
    END_VAR

    Implementation

    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:


    Deklaration

    VAR
    	fbPeerServer    :    NBS.UDP_Peer;
        fbSend          :    NBS.UDP_Send;
        xSend           :    BOOL;
        sSendMsg        :    STRING := 'Hello World';
    END_VAR

    Implementierung

    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.


  • No labels