ThingWorx Edge .NET SDK > ThingWorx Edge .NET SDK Reference > .NET SDK: VirtualThing Class > Sending Property Value Changes from ThingWorx to Edge Devices
Sending Property Value Changes from ThingWorx to Edge Devices
When properly bound to remote properties on an Edge device, properties on RemoteThing instances can be used for both reading values from and writing new values to devices. For the .NET SDK, this functionality is provided by default when you extend the VirtualThing class to define your device and then use annotations to define the properties for that device.
When a new value is pushed down from ThingWorx platform, the device has an opportunity to react. For the .NET Edge SDK, the processPropertyWrite(PropertyDefinition, IPrimitiveType) method on the VirtualThing class is called in response to receiving a value that has been pushed down from the ThingWorx platform. By default, the processPropertyWrite() method does nothing. However, if you expect edge devices to receive data from the ThingWorx platform, you should override this method and configure the application to validate new values that are pushed down from ThingWorx platform.
The processPropertyWrite() method executes before committing the data to device memory. It takes the following parameters:
The PropertyDefinition parameter contains the property information for the property that is being set.
The value parameter contains the new value that is pushed down from the ThingWorx platform.
If you call the method, getCurrentPropertyValue() for the property specified in the processPropertyWrite() method, the getCurrentPropertyValue() method returns the currently set value (“old”). You can then compare that “old” value to the value that was pushed down and, as applicable, reset the value of the property. If the incoming value is not valid, you can restore the “old” value.
The VirtualThing tracks the new value of the property in its internal property map. If the property is configured to be pushed to the ThingWorx platform on change and the cache option is set to read from the server cache, the typical result is that the new value of the property is sent back to the ThingWorx platform. In this case, you do not see the new value in ThingWorx Composer until the edge device confirms the new value by pushing it back up to the platform.
To ensure that a property displays an accurate value at all times, you can set the Cache Option to Fetch from Remote on Every Read. This setting increases the amount of data sent between ThingWorx platform and the edge device because every request for the property retrieves the data directly from the device. Use this option sparingly with devices on metered connections.
Setting Up Your Application
To propagate property values that are set on a remote thing on the ThingWorx platform to the VirtualThing in your edge application, follow these steps:
1. In your edge application, create the VirtualThing and use annotations to add properties to it. The samples provided with the SDK show how to use annotations to add properties.
2. As long as you have set up the VirtualThing in your edge application to connect to your ThingWorx platform, start your application.
3. In ThingWorx Composer, use the Manage Bindings button at the top of the Properties page to add the remote properties to your RemoteThing.
4. Save your RemoteThing.
5. In the Properties page for your RemoteThing, click the Set button to set the value of a property. As long as the edge device is connected, this action sends the new value to your edge application.
6. In your VirtualThing, you can override the processPropertyWrite() method in order to react to values sent down for properties from the ThingWorx platform.
The SDK also provides the method, processPropertyRead(), which you can use to react to requests from the ThingWorx platform to read property values. If you override the method, you could run some calculations or format the data before responding to such a request.