Integration with device / reading class state

244 views
asked Feb 14, 2019 in System Integration by elage.lucas

Hello,

I made a GUI interface and now I'm trying to integrate it with my device.

I mean to execute an action when the user selects the button 'TypeButton0', so I configured a method 'UpdateDevice' in device class with the following script:

var bool TypeButton0 = false;

if (TypeButton0 == true)
{
  native ( TypeButton0 )
  {
    DeviceDriver_SetLedStatus( value );
  }
}

else
{
  return;
}

 

TypeButton communicates with TypeW, so I called UpdateDevice in its onset also in device class:

if ( value < 0 )
  value = 0;
if ( value > 7 )
  value = 7;

/* check for new value */
if ( value == pure TypeW )
  return;

pure TypeW = value;  
                           

notifyobservers ^TypeW;

UpdateDevice(TypeW);

 

Please, what am I doing wrong?

Thank you,

Lucas

update device

1 Answer

+1 vote
answered Feb 14, 2019 by Paul Banach

Hello,

the implementation of the UpdateDevice() method is confusing me a little bit. Especially the if-condition evaluates the variable TypeButton0 which due to the preceding initialization is always false . The code within the if-condition will never execute. Can you check this?

var bool TypeButton0 = false;

if (TypeButton0 == true)
  ...

Best regards

Paul Banach

commented Feb 14, 2019 by elage.lucas
Hello,

It was a terrible mistake, thanks for your observation. I'm not sure how to declare this variable.

The logic that I'm trying to build is something like:

On DeviceUpdate - Device Class

var VSG::TypeButton button0 = TypeButton0;     

if (button0 == true)
{
  native ( button0 )
  {
    DeviceDriver_SetLedStatus( value );
  }
}

else
{
  return;
}

 

It is giving me an error of 'unknown identifier' for TypeButton0

 

Regards,

Lucas
commented Feb 15, 2019 by Paul Banach

Hello Lucas,

The error message indicates, that there is no corresponding member with the name TypeButton0. Well, do you want the variable to exist within the DeviceClass? If yes, you can add new variable to your class. Then specify its data type (VSG::TypeButton ?) and initial (default) value.

Depending on your application case you can also use property instead of the variable.

Does it help you further?

Best regards

Paul Banach

commented Feb 18, 2019 by elage.lucas

Hello,

Thank you for your answer, I'm getting to know better this software.

I could build its profile (F8) without getting any errors, but it isn't working propelry yet.

I configured DeviceDriver, ew_bsp_inout and stm32f746g_discovery files to send a signal to a GPIO where I connected a LED and it didn't work, so I tested the same files with a simpler application and worked.

So I'm still doing something wrong.

What I did: 

  •  TypeButton Class with a property Type1, in which I configure the values of my TypeButtons.typebutton

 

  • Device Class where I add a Variable 'button', a Property 'Type1' (same as above) and a 'UpdateDevice' method
deviceclass
  • OnSetType1:

    if ( Type1 < 0 )
      Type1 = 0;
    if ( Type1 > 7 )
      Type1 = 7;

    pure Type1 = value;

    switch ( value )
    {
        case 0:
           button = 0;
        case 1:
           button = 1;
        case 2:
           button = 2;
        case 3:
           button = 3;
        case 4:
           button = 4;
        case 5:
           button = 5;
        case 6:
           button = 6;
        case 7:
           button = 7;
      default:
        ;
    }

  • UpdateDevice:

      if (button == 0 )
    {
      native 
      {
        DeviceDriver_SetLedStatus( value );
      }

    }

    return aArg1;

      

  • What can I do to fix it?

 

Thanks for your patience, I'm still building my knowledge in this field.

 

Thank you for your attention.

 

Regards,

Lucas

commented Feb 19, 2019 by Manfred Schweyer

Hello Lucas.

Can you set a breakpoint (by using the integrated Debugger of Embedded Wizard Studio) and check if your UpdateDevice() method is called? Alternatively, you can place some trace statements within your method and see if you get the correct values that you want to send to the device.

Before going to the target the GUI application should work as expected.

Maybe in the above implementation the call to UpdateDevice() is missing within OnSetType1.

Best regards,

Manfred.

commented Feb 22, 2019 by elage.lucas

Hello Manfred,

Thank you for your answer, but I couldn't figure it out.

I'm going to change my approach, I think it will be a better way to do it.

When I press Start, it calls the property Running, in Device Class, and in its OnSet Method:

if ( value == pure Running )
  return;

pure Running = value;

notifyobservers ^Running;
  
if ( value )
{
$if !$prototyper
  native
  {
  DeviceDriver_StartTest(^TypeW, ^DepthW, ^SagsW, ^TestsW);
  }
$endif
  TestsRemaining = pure TestsW;
  Timer.Enabled = true;
}
else
Timer.Enabled = false;
$if !$prototyper
   native
  {
  DeviceDriver_StopTest(^TypeW, ^DepthW, ^SagsW, ^TestsW);
  }

$endif

 So, it counts the Tests Remaining, and I want to call my Native code with it. On DeviceDrive_StartTest I write my if/else case, based on the value of the properties TypeW, DepthW, SagsW and TestsW (present on Device Class).

 

How is the proper way to declare those properties names here: DeviceDriver_StartTest( ? ) ??

 

 I've tried ^TypeW, Device.TypeW, ^Device.TypeW, VSG::Device.TypeW.... 

All of them gave me errors back when building.

 

Regards,

Lucas

 

commented Feb 24, 2019 by Paul Banach

Hello Lucas,

as far as I understood, you want to call the C functions DeviceDriver_StartTest() and DeviceDriver_StopTest() with the values taken from the properties TypeW, DepthW, SagsW and TestsW. In such case it is important to understand, that accessing the class members (here the properties) from the native code is not possible. The above code will not compile.

Instead use local variables to exchange values between the EmWi (Chora) world and the native code. Also inform the native statement about your intention to access the variables from the native code. Concrete in your case how to call the C function DeviceDriver_StartTest().

if ( value )
{
$if !$prototyper
  var int32 typeW  = TypeW;
  var int32 depthW = DepthW;
  var int32 sagsW  = SagsW;
  var int32 testsW = TestsW;

  native ( typeW, depthW, sagsW, testsW )
  {
    DeviceDriver_StartTest( typeW, depthW, sagsW, testsW );
  }
$endif
  TestsRemaining = pure TestsW;
  Timer.Enabled = true;
}

[...]

Please see also native statement.

Best regards

Paul Banach

commented Apr 18, 2019 by elage.lucas
Hey Paul,

Appreciate all your help but I couldn't make it work.
I'll change my design to a simpler one that doesn't need to read any variable, just simple buttons and stuff.

Thank you for your help.

Lucas

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

...