Greetings, I'm currently working with CoDeSys V2.3. During simulation I want to be able to read and write variables with an external application or script (e. g. a Python script). Both CoDeSys and the external application should be running on the same local machine. No external hardware should be involved in the scenario.
To be more specific, I want to simulate a controller. The user should be able to write a program to set some variables (output), the external application would read those variables and set some other variables (input) in return.
The program simply increments a counter variable on each cycle, now the variable named "ACTIVE" should be modified by an external application and the result should be shown in CoDeSys. Therefore the counting should start or stop depending on the external application or script.
I'm not sure whether there is an API or communication protocol available that could allow this scenario.
In simulation mode there is not any communication between your CoDeSys application and outer.
You must use the soft PLC (PLCWinNT, installed on your PC with CoDeSys) ) to communicate with another application. (OPC server, ...)
Hey, thanks a lot for your answer and interest!
If I understand correctly, PLCWinNT is like a virtual PLC running on my machine, right?
When started, a TCP/IP-address and a RS232-address are displayed.
Which configuration do I need to change in CoDeSys to be able to use PLCWinNT?
Finally, how would I be able to communicate with PLCWinNT? You mentioned OPC. In this case, would PLCWinNT provide the OPC server and my own application would be the OPC client?
PLCWinNT is a real soft PLC.
It is fully operationnal, but without licence it runs during two hours.
To test a program it is fully sufficiant.
To use it, you need :
1°) Choose PLCWinNT in Target Setting. (Ressources -> Target Setting)
2°) Uncheck the simulation option (Online Menu)
3°) Define Communication parameters (Online Menu)
Address IP is Localhost (Internal IP addresse of your PC) or the real IP address of your PC.
4°) Start PLCWinNT
5°) Login (Online Menu), if there is no program on the controller, you can download the new program.
6°) Start the PLC (Online Menu --> Run)
7)) You can test your program in the same way you used with simulation mode.
The difference is, when you logout Soft PLC still running, so when you login
You have to start OPC Configurator to set and start the CODESYS OPC server running on your PC (installed wiht CoDeSys).
After you need an OPC Client (for example your own application) to test communication.
Hey again! Thanks a lot for your help so far! Somehow I had problems with the connection to PLCWinNT so I re-installed everything and now it works! I can load a program into PLCWinNT and start it, furthermore I can watch the variables change in CoDeSys.
Finally I need to get the OPC connection to work. For now I wanted to use UaExpert to test the connection. Later I would like to use either a Python application with the "opcua" library or some C# application to read and write variables over OPC.
Do I need to keep the "OPC Configurator" running or is it only needed to set the configuration once?
I can't seem to find the connection URL for OPC.
I researched a bit and found some forms of
"opc.tcp://localhost:4840" or "opcua://localhost:4840"
but I'm not sure whether the OPC server is even running.
The OPC Configurator is used to configure the OPC server.
As soon as you save the configuration this starts the OPC server and you can then close the configurator.
When you want to connect with your OPC client, you should see "CoDeSys OPC02" or "OPC Server for CoDeSys V2.0" which is the server on which to connect.
Please note, I discovered that the name of your CoDesys project must not contain spaces.
And when you define this name in the OPC configurator, you only have to put the name, without extension.
Log in to post a comment.