Write variables in OPCUA Server | AXC F 2152
Hello,
I would like to know if it's possible write variables that are already created in the OPCUA Server which has integrated the AXC F 2152. I have all these variables set as a GLOBAL.
My goal is to write these variables through a Python script but I don't know how can I do it. If you can provide me some information it could be great.
Regards!
Comments
Hello,
Just so I understand - you have a PLCnext Engineer program running in the PLC, which defines variables that are marked with the "OPC" attribute. These variables now appear as tags in the OPC UA server, and you want to write to these tags from a Python script on the PLC. Is that correct?
If so - is your intention for the OPC UA server to act as the OPC UA server for your Python application, thereby allowing OPC UA clients to exchange information with your Python script - is that correct?
Or - do you just want your Python script to be an OPC UA client, and exchange information with the PLCnext Engineer project through the OPC UA server?
(there are different solutions for each of these scenarios).
Martin.
I created OPCUA variables in the PLC field of the project and I marked them as OPC. I checked that this works by using an OPC UA Client, the UA Expert. All these variables are set as GLOBAL
I want to overwrite these variables each time a value change in the python script and also see these changes in the UA Expert. I don't want to send data from the PLC to the python script, I only want that the OPC Server receives data from the python script
So I think, that the solution is closer to the first option that you commented. If not, I really appreciate that you correct me.,
Thank you!
OK, so it sounds like you would like the OPC UA server to act as the OPC UA server for your Python script.
In this case the "simplest" approach is probably to use the REST interface to write to the PLCnext Engineer variables. I'm not sure if this will work for Global variables - the variables may need to be declared as PORT variables in a PLCnext Engineer program, because (I think) the variable must have the "HMI" attribute checked in PLCnext Engineer along with the OPC attribute.
There is a sample project on Github that uses the REST API, and also some discussion of this in the forum. You can try this out using
curl
on the PLC command-line, similar to whats described in this post:https://www.plcnext-community.net/index.php?option=com_easydiscuss&view=post&id=2346&Itemid=221&lang=en#reply-2348
(but using writes instead of reads).
If you get this working, you can use similar REST calls from your Python script to write to the PLCnext Engineer variables.
I would be interested to know how you get on with this.
Martin.