Read IP adress of PLC from your code

For my work I want to read the IP of the local PLC itself to make configurations in the code depending on the IP address so I can have 1 program to manage multiple different PLC’s doing roughly the same actions.

I use the following setup:

  • PLCnext Engineer 2024.0 LTS
  • PLCnextBase_1_4_1

I thought that this PBCL function would work but it gave me an empty string

I did found the function PBCL_ConvIPv4ToString() function so you would think there would be a way to access the IPv4 address.

Is there possibly another way of reading the IP of the local PLC? If so help would be appreciated.

Hi,

have a look at FB “PBCL_SysNetwork_1” from “PLCnextBase” library

Remember that “The FB requires the PLCnextBase ServiceProvider component”

Bye,

Marcello

Hello,

Please verify that the correct adapter number (uiAdapterNumber) is selected. In your example, you are trying to access ETH1.

You can check the available interfaces in Linux with: ip addr:

For example see:

Best Regards,
Jorne

Hello Jorne,

Thanks for the response. In the screenshot I have the adapternumber indeed on 1 but at first I did set this value to 0. But I will try the ip addr next week when I have access again to the PLC.

I tried the ip addr function an said the IP adrress was set to adapter 0 (eth0). But when changing the adapternumber nothing changed. Also in documentation of PLCnextBase I checked if the service provider was running and that seems to be running when looking at my code.

Not sure what I do differently then in your example.

Hello JoepVA,

At the moment I am not able to reproduce the behavior you are seeing.

Could you create a small demo project in which the issue can be reproduced, containing only the necessary functionality for reading the IP address?

Please archive the complete PLCnext Engineer project and send the archive to Phoenix Contact Support Netherlands. Then we can take a closer look at the application.

Best Regards,
Jorne

The problem was found from the Support Netherlands but just wanted to mention the solution would someone else have the same issue.

The solution was to upgrade to PLCnextBase library. I first had the version 1.4.1 but I now added the 1.6.4 version. After that the rest worked as desired.
Thanks for the support.

Best Regards,
Joep