84 views
in System Integration by

Hi,

Setup:

  • I have a class A with a1,a2,a3 (all uint32 type) and class B with b1(uint32), b2 and b3 being bool types in one of the Unit. 
  • I have created two properties in DeviceClass with types A and B, so they have UpdateA() and UpdateB() methods linked with them and has associated observers with them in EW.
  • In my devicedriver file I have created objects ewA and ewB of type A and B respectively.
  • Now when I need to update a1, a2 or a3 I will be calling UpdateA(deviceObject,(A)(ewA)) and as UpdateB(deviceObject,(B)(ewB)) for updating b1, b2 or b3.
  • Before this the values are assigned as ewA->a1 = deviceValueofa1, ewA->a2 = deviceValueofa2 and viz. 

Problem:

When the statement ewA->a1 = deviceValueofa1 is executed ewB->b1 also gets updated. Same goes the other way i.e.,  ewB->b1 = deviceValueofb1 updates ewA->a1.

 

Question:

  • What is the root cause of this behaviour? - Did I miss or do anything wrong?
  • What must be done to avoid this behaviour?

 

 

Thanks,
Aswath

1 Answer

0 votes
by

Hello Aswath,

What do mean with "...In my devicedriver file I have created objects ewA and ewB of type A and B respectively."? Do you create instances of Chora objects directly within native code? If yes, please note that the instances are discarded automatically by the Garbage Collection. See also the section Don't retain nor modify objects or strings.

Nevertheless, based on the description, it is difficult to narrow down the cause of the behaviour. Can you provide an example demonstrating this problem?

Best regards

Paul Banach

by

Hi Paul,

 Yes I am creating the instance of Chora objects directly within my cpp file (The devicedriver is the name of the cpp file). I have a group of variables which are functionally related, for example Engine temperature, rpm and torque as one set of variables and environment temperature, pressure as another set of variables. So I grouped them in Chora as classes (Class A and Class B respectively) and update their values using observer pattern using UpdateA(deviceObject,(A)(ewA))  and UpdateB(deviceObject,(B)(ewB)).

Is there any other way to group variables in Chora other than classes which doesn't cause this problem?

 

Regards,

Aswath

by

Hello Aswath,

creating Chora objects in C is not wrong in itself. It is not documented and recommended because of the possible programming traps. You can create an object, initialise it with some data and then pass the object to Embedded Wizard. What you should avoid is to store the object in some C variable for later use. Next time when you evaluate the variable, the referred object possibly does not exist anymore. Trying to use it will result in memory corruption.

Is there any other way to group variables in Chora other than classes which doesn't cause this problem?

So far I understood, you use the object of class A to pass multiple values in the invocation of the method UpdateA(). In such case you can modify the method UpdateA() so it contains parameters for each individual value. Concrete, the DeviceClass contains then 4 properties representing the values RPM, Torque, Temperature and Pressure and 1 (one) UpdateA() method. From C code you invoke only the UpdateA() method and pass to it the four values for RPM, Torque, etc.:

Nevertheless, I still don't understand the cause of the behaviour you observed. If the problem still exists, can you provide me an example demonstrating it?

Best regards

Paul Banach

 

asd

by
Hi Paul,

 Thanks for the suggestion, I'll try this and let you know. I'll try to reproduce the behaviour with a sample code and send you the project file ASAP for further analysis.

 

Regards,

Aswath.
by
Hi Paul,

  I am unable to isolate the code EW code from our proprietary code. So I am unable to send you any code for further analysis. The problem still exists.
 Thanks for your help.
by
Hello Aswath,

thank you for the information. I can imagine that this is not really satisfactory. How can we proceed in this case?

Based on the available information we are not able to identify the source of the problem. I see two options:

Option 1: You continue trying to narrow down the issue. Especially the approach of creating/accessing Chora objects from C code is a difficult aspect. Officially it is not the recommended way how data is exchange. Although it should work. Maybe commenting out the code sections one by one helps to localize the source?

Option 2: If the problem still persists, we could take a look at your actual project. Since you are Professional customer, the simplest would be, you contact us directly via support@embedded-wizard.de and send your project for further analysis.

What do you think?

Best regards

Paul Banach
by
Hi Paul,

 I was using the objects of Chora inside my C code, looks like its not recommended. So I have started using individual variables to pass on the data to "update" functions as per your first answer. So will proceed with the same and update here if there's any problem in the future.

 

Thanks,

Aswath
by
Hello Aswath,

thank you for the update. Does it mean, you was able to solve the issue? Or does it still exist?

Best regards

Paul Banach
by
Hi Paul,

But usage of chora objects inside C code still results in same problem, in that view the problem is not solved.

I did change my approach of safely sending data to GUI from C code, in that view the problem is solved.

 

Regards,

Aswath
by
Thank you very much for this information! It sounds good.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...