...
- 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
Section Column width 7 Implementation
Column width 93 Code Block theme Confluence IF xPeerActiv AND NOT fbPeerServer.xBusy THEN ipAddress.SetInitialValue(ipAddress := gvlSettings.sIPAddres); fbPeerServer(xEnable := TRUE, itfIPAddress := ipAddress, uiPort := gvlSettings.uiPort); END_IF fbPeerServer(); fbReceive(xEnable := fbPeerServer.xBusy, itfPeer := fbPeerServer, pData := ADR(abyReceive), udiSize := SIZEOF(abyReceive)); IF fbReceive.udiCount > 0 THEN IF fbReceive.udiCount < SIZEOF(sLastValidReceive) THEN SysMem.SysMemCpy(pDest := ADR(sLastValidReceive), pSrc := ADR(abyReceive), udiCount := fbReceive.udiCount); // Set End of String sLastValidReceive[fbReceive.udiCount] := 0; END_IF END_IF UdpClient();
- Start the project and set the xSend variable to TRUE.
sdgasdfg
Up to SP16:
- Open the Library Manager and add the Network library.
...