561 views
in Getting started by
Hi,

In the MiddlewareClass I created property string firstName I assign it a default value. I next create Update method.

In my ClassApplication, I  place view text object, Text1, I set Text1.String to the property string firstName via Middleware::MiddlewareClass.firstName. Text1 now reflects the value of propterty firstName. First question is this the correct way to go about setting Text1?

How do go about updating firstName from my C code? Plus amending the Update method to handle a string is that all that is required? if I have gone about all wrong, please stir me in the right direction simply. Ultimately, I would like to update strings  and numerical values being displayed  from my C code.

Thanks in advance.

MikeZ
by
Hi Paul,

Thank you for such a detailed answer.

MikeZ

1 Answer

0 votes
by

Hello MikeZ,

you want to display strings and numerical values received from the C code. For this purpose:

1. Add a new Device Class to one of your units. It will serve as interface between the GUI application and the C code. How you create a new Device Class is explined in the chapter Device Class and Device Driver. Please note, the Device Class implements the interface. In order to access this interface, there is also a global instance (so-called autoobject) available. If you use the template Device Interface from the Gallery folder Device, you will get a class DeviceClass and the corresponding autoobject Device automatically.

2. In your Device Class add properties fro the values you want to exchange. Use the template Property from the Gallery folder Device. Using this template, the property comes accompanied by an Update and OnSet methods.

3. Rename the property to reflect its content.

4. Change the type of the property to reflect its content. For example, set the type to string if you want the property to store text and int32 if you want it to store 32-bit signed integer.

5. Specify the default value the property should have at the startup time.

6. Open the associated Update method. In the declaration area of the method change the type of the method parameter to correspond to the type of the property.

7. In your Application class (or other GUI component where you want the values being shown) add Text views for evey value.

8. In  the same component add Property Observer for each value to show. Use the template Property Observer from the Gallery folder Device.

9. For every Property Observer initialize its property Outlet to refer to a corresponding property in your Device instance (the autoobject mentioned in 1.). For example, if you have added a property Voltage to your device class and the instance has its default name Device and it exists in the unit Application, you would initialize Outlet with the following expression:

Use the Assistant window to select the right property.

9. For every Property Observer add a Slot method.

10. Connect the slot methods with the corresponding Property Observers. For this purpose the Property Observer provides a property OnEvent.

11. Open the slot methods for editing.

12. In the Slot method implement code to retrive the data from the Device Class and to store it in the Text view. This implementation can include all eventl. conversions, etc.. For example, if the property Voltage in your Device Class stores a singned integer, you can convert it in string and display it together with the voltage unit 'V':

VoltageTextView.String = string( Application::Device.Voltage ) + " V";

13. In your C Code, every time the value (e.g. Voltage) changes, invoke the Update method of the Device Class corresponding to this value. Pass the new value in the parameter of the method. To do this, however, you will need to obtain access to the autoobject (to the global instance ) of the Device Class. Following could be the C Code to provide new voltage value:

/* Obtain access to the global autoobject 'Application::DeviceObject' of the
  class 'Application::DeviceClass' */
ApplicationDeviceClass device = EwGetAutoObject( &ApplicationDevice,
                                                  ApplicationDeviceClass );

/* In context of the object invoke the method 'UpdateVoltage()' */
ApplicationDeviceClass__UpdateVoltage( device, 240 );

What happens here:

- Invoking the methods updates the value stored in the property Voltage in the global instance of your Device Class.

- Additionally, the Device Class broadcasts a notification about this alternation.

- The affected Property Observer react to this notification and signal the associated slot methods.

- The slot methods read the new (actual) value of the property from the Device and format new text to be shown on the screen.

Please note:

A. If you are using multi-tghreading, the C code should always be executed in context of the GUI thread.

B. If you want a string to be passed, use the function EwNewStringAnsi() ( or EwNewString()) to create a proper string object before passing it to the Update() method. For example:

/* Obtain access to the global autoobject 'Application::DeviceObject' of the
  class 'Application::DeviceClass' */
ApplicationDeviceClass device = EwGetAutoObject( &ApplicationDevice,
                                                  ApplicationDeviceClass );

char*   some_c_string = "Hello world!";
XString string        = EwNewStringAnsi( some_c_string );

/* In context of the object invoke the method 'UpdateText()' */
ApplicationDeviceClass__UpdateText( device, string );

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

...