Closed Chops91 closed 3 years ago
Hello.
You need to specify the type.
import System
for hardware in myproject.Devices:
for item in hardware.DeviceItems:
if item.Name == "PLC1":
attribute = (item.GetAttribute("CycleCommunicationLoad"))
print (attribute)
print (type(attribute))
item.SetAttribute("CycleCommunicationLoad", System.UInt64(60))
attribute = (item.GetAttribute("CycleCommunicationLoad"))
print (attribute)
I'm not sure how to properly find the correct types for all. I am not able to find it using openness explorer. Maybe in C# the GetAttributes will return the correct type? Either way I think its mosly Strings and UInt64 being used.
Thanks for the quick response. Now I am onto the next stumbling block.
One of the configuration values I want to change is part of the failsafe settings of a safety device and I now get this nice error:
A password was assigned for the safety program. Changes with Openness are therefore not permitted.
Anyway your suggestion does work for non failsafe configuration values.
Which version of TIA and FW are you working on? I am not sure (just guessing), could it by any luck be something that has been added at a later SW/FW?
See below for my TIA version. Yes I am aware that V17 is already but you know how it goes in the corporate world. We have just got our V16 license so will be making the move to that shortly.
You have answered the initial question so will close the issue.
Thank you for your assistance!
Just FYI from page 610 of the Openness API docs.
Hi,
I don't really have an issue just wasn't sure how to contact you direct. Firstly thanks for the pointers and examples you have provided they have been of great help to get me as far as I have got so far, Python for me is much easier to get my head around than C# and all the visual studio overhead and so this is more me reaching out asking for some pointers.
I have a project where I can add a device however I want to change some of the default device configuration values for our application and doing this for 1000's of devices manually is very tedious so here goes scripting.
I can add the device and I have managed to get to the attributes that I want to update the issue I am facing now is how exactly the syntax should be for the values that I am trying to achieve.
From the openness API docs there is not much info regarding the SetAttribute function so I am using the library SetAttribute example as some guidance for what I want to achieve. Extract from page 142 of the Openness API docs below:
Below is an example for my application, where the device names and what it is looking for specifically have been substituted out for something a little more generic.
Running the above I get the error:
The problem I appear to be having is that the '2' (attribute value) that I am trying to set is not of the type object. Looking at the docs this seems consistent as the set attribute is expecting a KeyValuePair<string, object>.
Do you by any chance have any insights into how I can do this so that '2' (attribute value) is an object? Or how I can create a KeyValuePair<string,object> in python?