FreeOpcUa / python-opcua

LGPL Pure Python OPC-UA Client and Server
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
1.37k stars 660 forks source link

creating subtypes and defining the definitions for properties #626

Open akgaurihar opened 6 years ago

akgaurihar commented 6 years ago

As part of my integrated project i need to take the data from ecl@ass website and define the subtyptes as shown in the pictures below. 1) how to code different subtypes or properties under 1 folder? 2) how to input definitions to certain properties /attributes?

ecl ss ecla ss2

I tried writing this way but iam not able to give multiple subtypes under one cetegorie.please check the screen shots in relation with code.

myobj=objects.add_object(idx, "AUTOMATION") myobj=myobj.add_object_type(idx, "robotics assembly") myobj=myobj.add_folder(idx, "robotics kinematics parts") myobj=myobj.add_object_type(idx,"0173-1#02-AAO742#002 - Brand") myobj=myobj.add_property(idx,"02-AAO742 Brand", 0) myobj=myobj.add_variable_type(idx, "Part of the naming for the support and the recognition of the brand position of products and services consisting of words, numbers, letters or other characters. Registered brands and trademarks are indicated with the appropriate protective signs",STRING)

zerox1212 commented 6 years ago

I don't understand what you are trying to do, but normally you define custom types in the server first. dev = server.nodes.base_object_type.add_object_type(0, "robotics assembly type")

Then when you instantiate a new object you set it to the type you defined. I haven't used OPC UA in a while so I'm not sure if it's the best approach to add types directly to the node. I never really used the subtypes function of UA so I would need to read the spec for that.

Are you getting errors or what exactly? Are you using the server or the client? Being more specific with the problem would be helpful.

akgaurihar commented 6 years ago

our task is to define any example( in this case we chose kinematics parts )with all its properties from the ecl@ss website as mentioned on 1 server and few other properties of the same example on another server and connect the 2 servers over a client.

we wanted to code in such a way that it just replicates the website for client to view it on ua expert.

link for refrence : http://www.eclasscontent.com/index.php?id=27389101&version=10_1&language=en&action=det

when u click " 0173-1#02-AAO742#002 - Brand " under kinematics parts it shows few properties like Classification,name,properties,definition etc so we wanted to know how we can code this in such a way that we have these 4 properties under " 0173-1#02-AAO742#002 - Brand ". check the ua expert screen shot attached below uaexpert

zerox1212 commented 6 years ago

You are saying that having multiple children under "0173-1#02-AAO742#002 - Brand" isn't working (UA Expert doesn't show your STRING variable node)?

How familiar are you with OPC UA? Are you sure you want to be declaring custom types in the tree like that?

Normally I would do something like this:

# create our custom object type
    assem = server.nodes.base_object_type.add_object_type(0, "Assembly")
    assem_folder = assem.add_folder(idx, "robotics kinematics parts")
    assem_folder.add_variable(0, "sensor1", 1.0)
    assem_folder.add_property(0, "device_id", "0340")

    # instantiate our new object type
    myrobot= instantiate(server.nodes.objects, assem, bname="2:assem0001")

However you data doesn't really look reusable, so I don't think you would use types at all.

akgaurihar commented 6 years ago

yes! we are not able to create subtypes like property, short name, format, defination under the title "0173-1#02-AAO742#002 - Brand" 41413206-a5d730de-6fe2-11e8-9fce-2ddcf173cd83

oroulet commented 6 years ago

What happens? Do you get any error message?

akgaurihar commented 6 years ago

no! we are not getting any errors, but we are not able to create subtypes

zerox1212 commented 6 years ago

That isn't how types work in OPC UA (as far as I know, @oroulet can correct me). To do what you want with types you would have to make many smaller types.

# create our custom object type for brand
    brand = server.nodes.base_object_type.add_object_type(0, "Brand")
    brand.add_variable(0, "sensor1", 1.0)
    brand.add_property(0, "device_id", "0340")

# create our custom object type for robot
    assem = server.nodes.base_object_type.add_object_type(0, "Assembly")
    assem_folder = assem.add_folder(idx, "robotics kinematics parts")
    assem_folder.add_object(idx, "brand", brand_type)  #fix this, i don't remember how to add an object with data type at the moment, but this would put your BRAND TYPE under your ASSEMBLY TYPE

# instantiate our new object type, now you have the prebuilt structure you defined above
    myrobot= instantiate(server.nodes.objects, assem, bname="2:assem0001")
oroulet commented 6 years ago

@akgaurihar what does that mean? Either you get an error or you have some code not behaving like expected. To create a subtype you create a node type under an existing type. And that works fine

akgaurihar commented 6 years ago

@zerox1212 now according to you , so in order to make sub types we need to code separately, as u have shown but when in u r code it doesnt show the subtypes in address space of ua expert ,it shows in references.

@oroulet yes the code is not behaving in the way we are expecting as told previously about the task our addresss space should display all the sub types according to the website of ecl@ss. please take a look at my last screenshot , so i click "0173-1#02-AAO742#002 - Brand" i need to have 5 sub types(property,format,shortname etc) shown on my address space barof ua expert moveover which clicked need to display the data shown in the screen shot on attributes or references section. I just wanted to know if this is possible or not.

zerox1212 commented 6 years ago

Thetype nodes are listed under the server object. Look under server>data types>base object type or whatever.

That is what I was saying earlier, your application isn't a good fit for types because your structure doesn't have much that is reusable. You might as well just build your entire tree with normal objects.

An example use of data type would be like this:

DataType for Generic Machine:
  Machine
    >ID
    >Temperature
    >Status

Then if you had several machines you could instantiate this structure and get this:

myMachine1
  >ID = 101
  >Temperature = 36
  >Status = Running

myMachine2
  >ID = 105
  >Temperature = 24
  >Status = Stopped

The instantiated object would have string node IDs like this: myMachine1.ID and myMachine2.ID.

In your example only that lowest layer (brand) looks reusable to me, but if you understand the concept you can figure it out yourself what can be a reusable type and what can't.

Also I use different terminology. You don't need 5 sub types, you need a brand type with 5 children (UA properties and variable nodes).

yangpeiren commented 6 years ago

@zerox1212 , could you please give an example of the customized DataType in code? I've searched in the project, only found examples in an xml file named enum_struct_test_nodes.xml under test folder, the customized DataType has such part: `

` could you please give an example of how to create this in code? Thank you very much!

zerox1212 commented 6 years ago

An enum and a type are not the same in OPC UA.

There are already examples... Create an object type: https://github.com/FreeOpcUa/python-opcua/blob/master/examples/server-custom-object.py Create an enum (similar to datatype): https://github.com/FreeOpcUa/python-opcua/blob/master/examples/server-enum.py

Please always look through the example folder before posting issues. Also post the code which you already tried yourself, you will get more help if you put in some effort.

oroulet commented 6 years ago

@zerox1212 good example ;-) . On client side (or if enums are defined in XML)) one can use load_enums() now that we have that function instead of creating Python enum en by hand.

zerox1212 commented 6 years ago

Do we need to update the enum example?

oroulet commented 6 years ago

No