I'm working with a Raspberry CM4 for a project. This Raspberry is going to act as a Modbus TCP slave and I want to edit the Ethernet adapter comm settings while the code is running, and also make these changes effective in the Raspberry network settings.
I would like to know if it is possible to dynamically change the IP, subnetmask and gateway of the Ethernet adapter in a similar way as it is done in this faq thread for a Modbus TCP Slave:
And I'm trying to edit the Ethernet node settings with the code in the second picture, using the method UpdateConfiguredIpSettings but it does nothing.
the first steps are done correctly:
- Set the SysSocket properties in the .cfg file
- Enable the option in the Ethernet adapter to adjust the IP address
but the code should be handled differently to change the IP adres of the PLC.
1)
add the following instance to your variable declaration:
Reconfigure : DED.Reconfigure;
2)
In your application you should now write some code to:
- first disable the ethernet adapter
- then change the IP adres
- then enable the ethernet adapter again
So for example
Set the enable status of the ethernet adapter to false:
Ethernet.Enable := FALSE;
Then call the Reconfigure FB, when done, change IP:
- off course you have to create some additional variable which contain the new settings for your ethernet adapter:
Reconfigure(xExecute := TRUE, itfNode := Ethernet); IF Reconfigure.xDone THEN ErrorCode := Ethernet.UpdateConfiguredIPSettings(IPAddress := abyNewIP, SubnetMask := abyNewSubnet, Gateway := abyNewGateway); END_IF IF Reconfigure.xDone OR Reconfigure.xError THEN Reconfigure(xExecute := FALSE); END_IF
Then enable the ethernet adapter again:
Ethernet.Enable := TRUE; Reconfigure(xExecute := TRUE, itfNode := Ethernet); IF Reconfigure.xDone OR Reconfigure.xError THEN Reconfigure(xExecute := FALSE); END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you very much, it works perfectly fine. I was able to change the IP and I could verify it via Linux Terminal in my Raspberry.
One last comment, I had to disable all the underlying devices of the Ethernet node for the code to work (in my case there were a Modbus TCP Master, Modbus TCP Slave and the Pi declared as TCP Slave Device. I'm leaving the final version attached in several pics.
Hello together. I also want to try it but when enter Ethernet.UpdateConfiguredIPSettings I don't see this Option. what do I wrong. I hope somebody can help me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello together. I also want to try it but when enter Ethernet.UpdateConfiguredIPSettings I don't see this Option. what do I wrong. I hope somebody can help me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone, I was able to change the IP address of my Controller (wago 750-8212), but when i restart my Controller then the IP address resets to the original, are there any other settings i need to implement?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi! I have a problem, when I write Ethernet.Enable, I get an error ("Enable" undefined). Could you send me the program? I can't solve it, and I don't know if it's because I'm missing a library or some FB...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm working with a Raspberry CM4 for a project. This Raspberry is going to act as a Modbus TCP slave and I want to edit the Ethernet adapter comm settings while the code is running, and also make these changes effective in the Raspberry network settings.
I would like to know if it is possible to dynamically change the IP, subnetmask and gateway of the Ethernet adapter in a similar way as it is done in this faq thread for a Modbus TCP Slave:
https://faq.codesys.com/display/CDSFAQ/Modbus+TCP+Slave%3A+Dynamic+Setting+of+the+IP+Address
I have read some other threads in this forum about this topic and I have already tried to add to the config file CODESYSControl_User.cfg this:
[SysSocket]
Adapter.0.Name="eth0"
Adapter.0.EnableSetIpAndMask=1
And I'm trying to edit the Ethernet node settings with the code in the second picture, using the method UpdateConfiguredIpSettings but it does nothing.
What else can I try?
Thank you in advance,
Pablo.
the first steps are done correctly:
- Set the SysSocket properties in the .cfg file
- Enable the option in the Ethernet adapter to adjust the IP address
but the code should be handled differently to change the IP adres of the PLC.
1)
add the following instance to your variable declaration:
Reconfigure : DED.Reconfigure;
2)
In your application you should now write some code to:
- first disable the ethernet adapter
- then change the IP adres
- then enable the ethernet adapter again
So for example
Set the enable status of the ethernet adapter to false:
Ethernet.Enable := FALSE;
Then call the Reconfigure FB, when done, change IP:
- off course you have to create some additional variable which contain the new settings for your ethernet adapter:
Then enable the ethernet adapter again:
Thank you very much, it works perfectly fine. I was able to change the IP and I could verify it via Linux Terminal in my Raspberry.
One last comment, I had to disable all the underlying devices of the Ethernet node for the code to work (in my case there were a Modbus TCP Master, Modbus TCP Slave and the Pi declared as TCP Slave Device. I'm leaving the final version attached in several pics.
You are awesome!!!! Thx so much for sharing, this is exactly I am looking for.
Hello together. I also want to try it but when enter Ethernet.UpdateConfiguredIPSettings I don't see this Option. what do I wrong. I hope somebody can help me.
Hello together. I also want to try it but when enter Ethernet.UpdateConfiguredIPSettings I don't see this Option. what do I wrong. I hope somebody can help me.
Hi everyone, I was able to change the IP address of my Controller (wago 750-8212), but when i restart my Controller then the IP address resets to the original, are there any other settings i need to implement?
Hi! I have a problem, when I write Ethernet.Enable, I get an error ("Enable" undefined). Could you send me the program? I can't solve it, and I don't know if it's because I'm missing a library or some FB...
Last edit: pablotorres 2024-09-30
Last edit: pablotorres 2024-09-30