Dear Unified Automation Team,
i´m working on an OPC UA implementation for a small robtic system. It consists of a Raspberry Pi with a control unit for 20 motors. Each motor has arround 40 registers.
So defined a Motortype in your UAModeler-Software and made 20 instances of it with different names and one ID-Paramater to differentiate them in the interface for the controller.
I have used your C++ PiFace-implementation as Codebase and the modified server is running flawless with its new Data-Model. So the current task is to implement the interface for the real time data.
The method i will use looks like this: ArbotixPro::ReadWord(int id, int address, int *pValue, int *error);
The adresses for the registers are implemented like you did in your C++ example Lesson 3. But i need a possibility to read the ID-Value of the current object for the interface-method in the readValue method of this object.
So my question is:
Is there an elegent way to reference to the current object and read its ID-Value, which is in the adressspace and could be changed anytime? The idea is that the interface of the motors is flexible enough so a client could add new instances of the motortype and by writing its ID-Value the method gets the right Motor-ID.
Thanks in advance.
Read Object Parameter for readValue/writeValue
Moderator: uasdkcpp
-
- Jr. Member
- Posts: 4
- Joined: 18 Jul 2016, 12:43
- Support Team
- Hero Member
- Posts: 3069
- Joined: 18 Mar 2011, 15:09
Re: Read Object Parameter for readValue/writeValue
Hello angrynuknuk,
just to make sure I understand correctly what you're trying to do. You have designed an ObjectType called 'MotorType' and this ObjectType has a number of child Variables. To access these Variables you need to access your interface. That's the scenario.
So in readValues() you get a list of UaVariables to read. At this point you need to have all the information to access your interface.
Either you put all that information in your UserData or you collect that information on the fly. Typically the performance is much better when you collect this information once and put it into a UserData that you can directly access in your readValues implementation.
I don't understand jet how you get that ID information. Is that just a Variable of your MotorType Object or where does that ID come from?
just to make sure I understand correctly what you're trying to do. You have designed an ObjectType called 'MotorType' and this ObjectType has a number of child Variables. To access these Variables you need to access your interface. That's the scenario.
So in readValues() you get a list of UaVariables to read. At this point you need to have all the information to access your interface.
Either you put all that information in your UserData or you collect that information on the fly. Typically the performance is much better when you collect this information once and put it into a UserData that you can directly access in your readValues implementation.
I don't understand jet how you get that ID information. Is that just a Variable of your MotorType Object or where does that ID come from?
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Jr. Member
- Posts: 4
- Joined: 18 Jul 2016, 12:43
Re: Read Object Parameter for readValue/writeValue
The ID of the Motor-Childrens is just a Variable which should be writeable by clients. So it is possible to change the associated Motor while the server is running by changing the ID. Currently the ID-Numbers are set as start value in the UAModeler.
I have made a snipped picture from the UAModeler to the attachment. Maybe it will clarify it.
Thanks in advance
I have made a snipped picture from the UAModeler to the attachment. Maybe it will clarify it.
Thanks in advance
- Support Team
- Hero Member
- Posts: 3069
- Joined: 18 Mar 2011, 15:09
Re: Read Object Parameter for readValue/writeValue
There are basically 2 approaches you could choose here:
1) Since reading the ServoID value is just an access to the in-memory value you can read it from that node. So you need to put some kind of reference to that variable into your UserData (e.g. NodeId or pointer to that UaVariable) to access it.
2) Put the value of that Variable into a shared Object and add that to your UserData. Any access to the ServoID values is redirected to that SharedObject. Any write operation on ServoID will change the value of the SharedObject and on the next access in readValue you'll have the updated ID.
You find a sample implementation for option 2) in the C++ DemoServer.
See:
NodeManagerDemo::initializeWorkOrder
NodeManagerDemo::readValues
NodeManagerDemo::writeValues
1) Since reading the ServoID value is just an access to the in-memory value you can read it from that node. So you need to put some kind of reference to that variable into your UserData (e.g. NodeId or pointer to that UaVariable) to access it.
2) Put the value of that Variable into a shared Object and add that to your UserData. Any access to the ServoID values is redirected to that SharedObject. Any write operation on ServoID will change the value of the SharedObject and on the next access in readValue you'll have the updated ID.
You find a sample implementation for option 2) in the C++ DemoServer.
See:
NodeManagerDemo::initializeWorkOrder
NodeManagerDemo::readValues
NodeManagerDemo::writeValues
Best regards
Unified Automation Support Team
Unified Automation Support Team