Show / Hide Table of Contents

Getting notified when a property changes

This example provides information on comparing two objects defined as properties in SmartComponent, explaining the use of the OnPropertyValueChanged(SmartComponent, DynamicProperty, object) method.

The topic considers that a SmartComponent project created from Visual Studio exists. Refer to topic Creating a SmartComponent on how to create it.

The steps that will be performed in this topic are:

  1. Add a signal and the properties to the SmartComponents XML file.

  2. Add the description of the signal and the properties to the XML resource file.

  3. Modify the code in the CodeBehind.cs file.

Note

The code in this topic can be tested using the default RobotStudio Smart Component template.

Solution

  1. Open SmartComponent1.xml file. Declare two properties and one signal, as shown below:

    <Properties>
       <DynamicProperty name="ObjectA" valueType="ABB.Robotics.RobotStudio.ProjectObject"/>
       <DynamicProperty name="ObjectB" valueType="ABB.Robotics.RobotStudio.ProjectObject"/>
    </Properties>
    <Signals>
       <IOSignal name="Output" signalType="DigitalOutput" readOnly="true"/>
    </Signals>
    
  2. Open SmartComponent1.en.xml file. Provide descriptions for the component, its properties, and the signal.

    <SmartComponent name="SmartComponent1" description="Sets a digital signal
            as a result of an object comparison">
        <DynamicProperty name="ObjectA" description="First object"/>
        <DynamicProperty name="ObjectB" description="Second object"/>
        <IOSignal name="Output" description="Set to high (1) if the objects are equal"/>
    </SmartComponent>
    
  3. Open the "CodeBehind.cs" file and modify OnPropertyValueChanged. When the value of a property changes, OnPropertyValueChanged(SmartComponent, DynamicProperty, object) gets triggered. The objects are compared. If the objects are equal, the Output signal is set to high; otherwise, it is set to low.

    Here are the steps to be followed to achieve the above mentioned task:

    • Get the value of property ObjectA.

      public override void OnPropertyValueChanged(SmartComponent component, DynamicProperty changedProperty, object oldValue)
      {
          ProjectObject a = (ProjectObject)component.Properties["ObjectA"].Value;
      }
      
    • Get the value of property ObjectB.

      public override void OnPropertyValueChanged(SmartComponent component, DynamicProperty changedProperty, object oldValue)
      {
          ProjectObject a = (ProjectObject)component.Properties["ObjectA"].Value;
      
          ProjectObject b = (ProjectObject)component.Properties["ObjectB"].Value;
      }
      
    • Set the signal to 1 if ObjectA value equals ObjectB value, otherwise 0.

      public override void OnPropertyValueChanged(SmartComponent component, DynamicProperty changedProperty, object oldValue)
      {
          ProjectObject a = (ProjectObject)component.Properties["ObjectA"].Value;
      
          ProjectObject b = (ProjectObject)component.Properties["ObjectB"].Value;
      
          component.IOSignals["Output"].Value = a == b ? 1 : 0;
      }
      

Compiling the Code

Note

In order for the Library Compiler to find the code behind assembly asset it needs to be located in the same directory as the Library XML file. The template project contains the following Post-Build Event, that copies the assembly to the right place.

copy /y "$(TargetPath)" "$(ProjectDir)"

The LibraryCompiler.exe is executed as a Post-Build Event, which means it is executed after the C# project has been built, and the code behind asset has been created.

"%ProgramFiles(X86)%\ABB\RobotStudio {version}\bin\LibraryCompiler.exe" "$(ProjectDir)\SmartComponent1.xml" "$(ProjectDir)\"

Required Namespaces

ABB.Robotics.RobotStudio

ABB.Robotics.RobotStudio.Stations

See Also

  • SmartComponent Introduction
  • Creating a SmartComponent
  • Overriding OnIOSignalValueChanged
  • Overriding CustomValidation
In this article
Back to top Copyright © 2025 ABB