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.
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().
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.
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
That’s strange, from my experience CfgGetDefaultGateway also returns the right address by using DHCP client.
What PLC and Automation Runtime you’re using?
When calling CfgGetDefaultGateway in INIT, theoretically it could happen that the DHCP data isn’t already valid (depending on the servers response time), so I would recommend to wait some seconds after PLC startup and call the FB then (again).
I’ve no idea why the default gateway returned (not only with the function block, but also by SDM) is not the configured one.
But honestly spoken, I don’t understand this setup at all?
For proper function of a default gateway, the gateway has to be part of one of the IP subnets used on the ethernet interfaces.
In the setting you describe, the default gateway uses a net 192.168.1/24 and therefore isn’t inside the IP subnet of IF2 (10.52.0/24), nor inside of IF3 (192.168.2/24). That means that the default gateway cannot be reached by the IF2 or IF3 net… or have you setted up some extra static routing inside the PLC?
Normally, when using DHCP client, the default gateway setting in AS is empty and the default gateway address is delivered by the DHCP server… I did a very quick test with some 4.93 version, and it worked like expected.
So unfortunately, I only can recommend to check the AS settings twice / again, or making a simple test with an empty project to check if the behavior changes.
Thanks for your responses. Definitely was on the right track. The project I was working on was a way to change the IP settings from a mappView UI.
From my testing, if a default gateway is defined statically (in the CPU configuration or using CfgSetDefaultGateway), CfgGetDefaultGateway returns this static default gateway even when DHCP is enabled.
Like Alex described though, if the default gateway is not set, CfgGetDefaultGateway returns the default gateway as assigned by the DHCP server.
To get my application/program to work, I am now setting the default gateway to be empty when DHCP is enabled (by calling CfgSetDefaultGateway with an IP of 0.0.0.0).