Trouble with function block CfgGetDefaultGateway()

Hi Everyone,

I’ve got some trouble with this FB.

In substance i want to change the default gateway form user interface.

I don’t know why but i can’t reach the correct pdevice to point the correct value. After writing a new string i need to read it, but i can’t do it.

i attach some screenshots to explain better.

Any Suggestions?

Screenshot 2024-09-17 142344


Screenshot 2024-09-17 142522

What is the content of your Network.Data.Device variable?
It should be a STRING containing the full device path of your ETHx device.

For ETH1 of an APC3100 it would simply be “IF3” if I’m not mistaken.

→ Look up the path in your physical view! If you move the mouse over the desired interface, you should see the “PLC Address:” in the tooltip!

Best regards,

Since the ‘DefaultGateway’ is a global parameter you can set pDevice to 0.

2 Likes

I’m sorry i forgot to explain that. Yes Network.Data.Device is IF3 of my eth device.
I just know that i can see the plc address on my physical view but the default gateway is in PLC ($root), i just tried to change the address in root but it won’t work.

According to the help it should work also with device, but it seems optional…

What is the error code you are getting?

Edit: Sorry, didn’t see it in the screenshot…

Hi,

error code 29009 just means, that the default gateway isn’t configured at all.
Do you use static IP settings? If yes, is a default gateway set inside the project? Because if a DHCP client setting is used, the default gateway is transferred automatically by the DHCP server, but if using static IP addressing, the default gateway has to be set explicitely by the user in the project, or by software using CfgSetDefaultGateway().

Best regards!

1 Like

from his last answer I suppose he uses ‘$root’

image

but this is not a valid device name for this fb.

Either the device name of the real Ethernet device must be used or ‘0’. If you use the Ethernet device it is just an additional check if this device exists and if this in the right mode.

2 Likes

Hi to All,

I did some attempts, but it sill don’t work correctly.
Now I’m in this condition.


Screenshot 2024-09-18 121908
Screenshot 2024-09-18 121929
Screenshot 2024-09-18 121950

In screenshots you can see that i configured a default gateway, and now pDevice is null, why i can’t read it?

At the moment again error 29009 it means that the default gateway was not set.

Other suggestions?

Thank you all for support.

Hello Matteo,
I suppose the function block is mentioning 29009 due to the fact that your Gateway IP is wrong.

You use an IP adress of 192.168.128.50 with a subnet of 255.255.255.0
Your gateway IP on the other hand is 192.168.100.254 which does not fit to your network.
Basically the Gateway IP is the adress where all packets are sent which do not belong to the network IP range you define. The Gateway (most likely a router or VLAN switch) then forwards the telegram to a different network where it hopefully fits
In your case your network is from 192.168.128.1 to 192.168.128.254 → your gateway does not fit into this range and the IP stack of the PLC could not send any packet not belonging to its range to the gateway as it is also in a non valid range.

Please try (for testing) to set a Gateway IP of 192.168.128.254 and try again. I would expect that it then works

2 Likes

I now tested this and I can show you my results:

Here is the function block with a valid Gateway IP:

And here with a invalid IP:

I used AB as programming language but the result would be the same in ST
(192.168.10.xxx is my private IP range)

5 Likes

Thank you Oliver!

It works!

Screenshot 2024-09-18 133932

kind regards!

1 Like

Perfect :slight_smile: good to hear and thanks for the feedback !

1 Like