Read Object Parameter for readValue/writeValue

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
angrynuknuk
Jr. Member
Jr. Member
Posts: 4
Joined: 18 Jul 2016, 12:43

Read Object Parameter for readValue/writeValue

Post by angrynuknuk »

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.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3069
Joined: 18 Mar 2011, 15:09

Re: Read Object Parameter for readValue/writeValue

Post by Support Team »

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?
Best regards
Unified Automation Support Team

angrynuknuk
Jr. Member
Jr. Member
Posts: 4
Joined: 18 Jul 2016, 12:43

Re: Read Object Parameter for readValue/writeValue

Post by angrynuknuk »

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.

Image

Thanks in advance

User avatar
Support Team
Hero Member
Hero Member
Posts: 3069
Joined: 18 Mar 2011, 15:09

Re: Read Object Parameter for readValue/writeValue

Post by Support Team »

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
Best regards
Unified Automation Support Team

Post Reply