597 views
in System Integration by

Hello EW Team,

I've been working on a project lately and my system is supposed to get informations from external hardware through UART. I've developped a parser to parse the UART buffer and save informations into a struct. So my GUI is supposed to change depending on the informations that the system got. I've added several properties into  my DeviceClass and I'm wondering how am I supposed to assign each property to the corresponding variable from the struct.

I've read the documentation about the Device Class and Device Drivers  and Integrating with the device but it didn't help much. Excuse me if I managed to miss on important details or documentations that are supposed to answer my question.

Best ragards.

Semeh jomaa

1 Answer

+1 vote
by

Hello Semeh Jomaa,

great that you already read the provided documentation. Based on that, let us try to figure out the solution for your particular use-case.

The parsing of the UART buffer means processing data from your device drivers. This happens within the main loop. Within your ProcessData() function you can check if there is a new data frame received from the UART and read the single data fields. 

In order to update the GUI (especially if your widgets should react automatically on any changes) you can implement an UpdateProperty method for each property of your device class.

That's all... ;-)

Let's make an example - assuming you implement a Vehicle Data Logger that receives the current vehicle data via UART.

The Device Class contains a set of properties that represents the different vehicle data values (like oil temperature, oil pressure, ...):

You implement your GUI application, that shows a couple of widgets reflecting the current vehicle values:

The widgets are using these properties via their Outlet properties. This means, every time a property within the Device Class has changed, the widgets are updating automatically. This is the GUI part - implemented within Embedded Wizard Studio.

Within you main loop you make the call to your ProcessData() function - which could be implemented like this (just for explanation not tested):

/*******************************************************************************
* FUNCTION:
*   DeviceDriver_ProcessData
*
* DESCRIPTION:
*   The function DeviceDriver_ProcessData() is called from the main UI loop, in
*   order to process data and events from your particular device.
*   This function is responisble to update properties within the device class
*   if the corresponding state or value of the real device has changed.
*   This function is also responsible to trigger system events if necessary.
*
* ARGUMENTS:
*   None
*
* RETURN VALUE:
*   The function returns a non-zero value if a property has changed or if a
*   system event was triggered. If nothing happens, the function returns 0.
*
*******************************************************************************/
int DeviceDriver_ProcessData( void )
{
  int needUpdate = 0;

  /*
     Get the data you want to provide to the GUI application.
     In case your are working with an operating system and your device is
     controlled from a separate task/thread/process, take all information
     from your device driver out of the message queue.
     Please note, that this function is called within the context of the main
     GUI thread.
     If you control your system by direct register access or some BSP functions,
     get all necessary data you want to provide to the GUI application.
  */

  /* check for a valid access to the autoobject of the device class */
  if ( DeviceObject == 0 )
    return 0;

  /* process your UART data and fill your C structure with the new data */
  if ( Process_Your_UART() == 0 )
    return 0; /* nothing to do */

  /*
     For each device paramter, that is represented by a property within the
     Embedded Wizard device class and that you want to update, you have to call
     the appropriate UpdateProperty() method.

     The following examples assumes, that you have a device class with the
     name 'DeviceClass' within the unit 'Application'.
  */

  /* update one property after the other */
  ApplicationDeviceClass__UpdateOilTemp( DeviceObject, (XInt32)YourCStructure.OilTemp );
  ApplicationDeviceClass__UpdateWaterTemp( DeviceObject, (XInt32)YourCStructure.WaterTemp );
  ApplicationDeviceClass__UpdateMotorTemp( DeviceObject, (XInt32)YourCStructure.MotorTemp );
  /* ... */

  /*
     Trigger system events if necessary, e.g. if a certain situation happens,
     if an error occurs or just if a certain value has changed...
  */


  needUpdate = 1;
  /*
     Return a value != 0 if there is at least on property changed or if a
     system event was triggered. The return value is used by the main loop, to
     decide whether the GUI application has changed or not.
  */

  return needUpdate;
}

I hope this answers your question.

Best regards,

Manfred.

 

by
Hello Mr. Manfred

thank you so much for the long and detailed answer! It helped me better understand how to communicate with the hardware and get the  hang of it. For me, the missing part of the puzzle was the ProcessData() function that I modified for my project and it worked!

Again thank you for the time that you put into making this detailed answer. I hope it will help others that have the same problem as I had.

Have a nice day!

Semeh  Jomaa

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

...