Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Access on Network Interface XF10 for PLC programs

Access on Network Interface XF10 for PLC programs

drschiffler
Established Member

Hi,

the question is about principal functionality.

Task / Approach: Use the sensors from an android mobile in a plc program (see picture at the bottom). 

- Android APP SensorDroid -> https://sites.google.com/view/sensordroid/  

- This app allows simple UDP stream of sensor values. (eg. pseudo code: "socket.bind('0.0.0.0','52122'); while true, socker.read(data)", see the python example on web)

I've created an PLC Program as follows

 

PROGRAM MobileUDPClient
VAR
    fbPeerClient    :    NBS.UDP_Peer;
    fbReceive       :    NBS.UDP_Receive;
    sRcvMsg         :    STRING;
	sLocalIP		:	 NBS.IPv4Address:= (ipAddress := '0.0.0.0');
	uiPort     		:    UINT := 52122; // Listen port
END_VAR
----------------------------------------------------------------------------------------------------------------------------------
fbPeerClient(xEnable := TRUE, itfIPAddress:=sLocalIP , uiPort:= uiPort);
 
fbReceive(xEnable := (fbPeerClient.itfPeer <> NBS.CAA.gc_hINVALID),
            itfPeer := fbPeerClient.itfPeer,
            udiSize := SIZEOF(sRcvMsg),
            pData := ADR(sRcvMsg));

 

 The code makes use of the codesys Net Base Services (3.5.16.0). It seems to work correctly. I can send/receive to the PLC itself (IP for send/receive are the same).

But -- in case of the virtual core -- independent of the virtualization settings (port forward or adapter share) it does not work. Actually, this is not tested on a real core device.

Question: Will the use of the NBS.UDP_Peer work in principal on the ctrlX core and which Address shall the peer bind to (0.0.0.0, 127.0.0.1, 192.168.1.1)?

Thanks,

Andreas

This example uses the OCI of the drive internal PLC. For ctrlX core PLC there has to be another interface connection.

drschiffler_0-1620396328494.png

 

 

4 REPLIES 4

Dias
Community Moderator
Community Moderator

Hello Andreas,

is your problem still there or have you solved it?

It is very special therfore it is not easy to help.

In case of using a real CORE you should use the CORE-IP e.a. 192.168.1.1 (default)

 Regards

Dirk

drschiffler
Established Member

Hi,

the topic is not solved yet. The problem is that the PLC snap has no permission to bind to the network interface (plug network-bind is missing in the snap.yaml). I guess this is done by intention. So the plc can use the LAN network.

Can anyone confirm this fact?

BR

Andreas

georkueh
Community Moderator
Community Moderator

Hello,

the binding via 0.0.0.0 should be the right value. The socket functions provides by the PLC are executed as operating system functions. So we expect, that this will work on areal ctrlX CORE. If you don't have a real ctrlX CORE, you re welcome to provide an example program here. We may are able to test it with a real ctrlX CORE.

 

kind regards

Hi,

UDP socket stream now works on a real ctrlx core. You have to use the address 0.0.0.0 for binding the socket. (NBS.UDP_Peer)

The application sends a packet to the android mobile app (SensorDroid) and then receives continuously sensor data from the mobile (via WLAN). It seems that a sample rate of 100 Hz (10 ms) is possible. The PLC app puts the orientation angle on the datalayer as an example. (Project file attached, remove the txt ending)

 

 

fbSocket(xEnable := TRUE, itfIPAddress := sLocalIP, uiPort := 53122);

IF xSend THEN
	fbSend(xExecute := xSend,
            itfPeer := fbSocket.itfPeer,
            itfIPAddress := GVL.sIpAddr,
            uiPort := 53121,
            udiSize := SIZEOF(sSendMsg),
            pData := ADR(sSendMsg));

    xSend := FALSE;
END_IF

fbReceive(xEnable := (fbSocket.itfPeer <> NBS.CAA.gc_hINVALID),
			xReady => xReceived,
			itfPeer := fbSocket.itfPeer,
            udiSize := 512,
            pData := ADR(sRcvMsg));

IF xReceived THEN
	IL_StrSplit(ADR(sRcvMsg),'$40',0,TRUE,ADR(sData),SIZEOF(sData));
	IL_StrSplit(sData[2],'$24',0,TRUE,ADR(sElements),SIZEOF(sElements));
	iTimeDiff := ULINT_TO_UINT(iTimestamp_act -  iTimestamp_old);
	iTimestamp_old := iTimestamp_act;
	iTimestamp_act := STRING_TO_ULINT(sElements[1]^);
	IL_StrSplit(sData[5],'$24',0,TRUE,ADR(sElements),SIZEOF(sElements));
	rOrientation[0] := STRING_TO_REAL(sElements[1]^);
	rOrientation[1] := STRING_TO_REAL(sElements[2]^);
	rOrientation[2] := STRING_TO_REAL(sElements[3]^);
END_IF

drschiffler_0-1622542617631.png

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist