[Compound Widget] Set Property Variable via Button

Hello Community,
i have a compound widget as you can see below. If the button is clicked a variable ‘BtnTest.intCommand’ is set to a fixed value. The plc application then reacts somhow to this. With this implementation it works as intended.

<?xml version="1.0" encoding="utf-8"?>
<CompoundWidget id="CW_TestHistory" width="800" height="600" xmlns="http://www.br-automation.com/iat2015/contentDefinition/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Widgets>

    <Widget xsi:type="widgets.brease.GroupBox" id="GbComplete" top="0" left="0" width="800" height="600" zIndex="0" text="History" style="Ersa">
      <Widgets>

        <Widget xsi:type="widgets.brease.Button" id="Button" top="10" left="10" width="160" zIndex="0" text="Test" padding="0px 0px" style="Ersa" />
        <Widget xsi:type="widgets.brease.NumericOutput" id="NoCommand" top="50" left="10" width="160" zIndex="1" format="{'metric':{'decimalPlaces':0,'minimumIntegerDigits':1},'imperial':{'decimalPlaces':0,'minimumIntegerDigits':1},'imperial-us':{'decimalPlaces':0,'minimumIntegerDigits':1}}"   textAlign="right" style="Ersa"  borderWidth="1px" cornerRadius="4px" borderStyle="solid"  />
 
      </Widgets>
    </Widget>

  </Widgets>
  <Properties>

        <!--value/data-->
        <Property xsi:type="StructureBindableProperty" name="value" type="STRUCT_MvCW_TestHistory" category="data" readOnly="false" >
            <Description>Structure bindings.</Description>
            <Mappings>

                <Mapping widget="NoCommand" property="node" type="Number" mode="twoWay" memberPath="BtnTest.intCommand" mapToNode="true" />

            </Mappings>
        </Property>

  </Properties>

  <EventBindings>

    <EventBinding id="Button_Clicked">
      <Source xsi:type="widget.Event" widgetRefId="Button" event="Click" />
      <EventHandler condition="">
        <Action>
          <Target xsi:type="widget.Action" widgetRefId="NoCommand">
            <Method name="SetValue" value="1" />
          </Target>
        </Action>
      </EventHandler>
    </EventBinding>

  </EventBindings>

</CompoundWidget>

But i actually do not want to display the variable ‘BtnTest.intCommand’ to the operator.

So my question: Is there a way to set the variable ‘BtnTest.intCommand’ directly without the NumericOutput?

Thank you

Hi @Lucky

I don’t know if I get it right, you want the NumericOutput hidden on the HMI? If it’s that just use property visible to false.
If it depend on some role you can use permissionView property.

Regards,
Florent

That´s possible, but this way i still have to create the NumericOutput and bind it to the variable. In case i have multiple buttons, this can be effortful.

I´d rather find a way to adjust my eventbinding so the variable is set directly.

But i don´t know if thats possible

I still don’t really know what you’re trying to do :sweat_smile:
You want to bind a variable to the compoundWidget then set this variable based on which button is selected?

Yes !

If Button is clicked then set the binded variable to 1

So you can use a button bar and bind the selectedIndex to your variable!

I want to keep the normal button. But probably the functionality im searching for is not possible this way…

Hello,

I may also not be understanding correctly, but it seems like you are using an event binding so that when a button is pressed the numeric input value is changed.
You would like to not display the numeric input.

If that is correct, then you can simply replace the widget.Action with an opcUa.NodeAction to change the variable BtnTest.intCommand directly.

You do not need the NumericInput at all.

That´s exactly i would like to do. But if i try this…

<EventBinding id="Button_Clicked">
  <Source xsi:type="widget.Event" widgetRefId="Button" event="Click" />
  <EventHandler condition="">
    <Action>
      <Target xsi:type="opcUa.NodeAction" widgetRefId="BtnTest.intCommand">
        <Method name="opcUa.NodeAction.SetValueNumber" value="1" />
      </Target>
    </Action>
  </EventHandler>
</EventBinding>

I receive the error ‘This is an invalid xsi:type’.

Most likely because this assignment is not allowed inside a compoundwidget ?!

There is syntax error in your code, but anyways you cannot use opcUa action in a Compound widget, but at this point why you want to use a Compound widget, if you use buttons in a content you can use eventbinding on them and use opcUa action to set the value.
Maybe you can give us a little bit more of context?

<EventBinding id="Button_Clicked">
	<Source xsi:type="widget.Event" widgetRefId="Button" event="Click" />
	<EventHandler condition="">
		<Action>
			<Target xsi:type="opcUa.NodeAction" refId="::Program:Value1">
				<Method name="opcUa.NodeAction.SetValueNumber" value="1" />
			</Target>>
		</Action>
	</EventHandler>
</EventBinding>

Note: here is the help that describes that you cannot use OPC UA actions B&R Online Help

Thank you @florent.boissadier . This information was very helpfull, i didn´t know this explicit restriction.

With this information i´m going to close this thread.

Summarize:

  1. Within compoundwidget it is not possible to set a the binded variable directly via button click.
    The best way to handle this is to make the numeric output invisible.
  2. Outside a compoundwidget simply a opcUa.NodeAction can be used to set the variable.

There is some confusion here.
The restriction will not let you use an opcua action within the compound widget itself, however you can define an event for the button within the compound widget being clicked.
Then once you place your compound widget on a content, you can assign an opcua action to the configured event binding.

I have used this method and can confirm it works.