Assigning and Getting Object Properties

The main objects in the WPD Automation object model are the Device object, the Service object and the Storage object. These objects provide access to the full set of properties that have been defined for the particular device, service, or storage that they represent.

The following table shows the mapping between WPD PROPERTYKEYs and the equivalent WPD Automation names for the Device object properties. For example, the WPD-defined property WPD_DEVICE_MANUFACTURER is accessed by using the corresponding WPD Automation property name: deviceObject.DeviceManufacturer

For a complete list of WPD PROPERTYKEYs and their corresponding WPD Automation names, see Names for WPD PROPERTYKEYs.

WPD PROPERTYKEYWPD Automation Name
WPD_OBJECT_IDObjectId
WPD_OBJECT_NAMEObjectName
WPD_OBJECT_PERSISTENT_UNIQUE_IDObjectPersistentUniqueId
WPD_OBJECT_FORMATObjectFormat
WPD_FUNCTIONAL_OBJECT_CATEGORYFunctionalObjectCategory
WPD_DEVICE_FIRMWARE_VERSIONDeviceFirmwareVersion
WPD_DEVICE_MANUFACTURERDeviceManufacturer
WPD_DEVICE_MODELDeviceModel
WPD_DEVICE_SERIAL_NUMBERDeviceSerialNumber
WPD_DEVICE_POWER_LEVELDevicePowerLevel
WPD_DEVICE_POWER_SOURCEDevicePowerSource
WPD_DEVICE_PROTOCOLDeviceProtocol
WPD_DEVICE_SUPPORTS_NON_CONSUMABLEDeviceSupportsNonConsumable
WPD_DEVICE_FRIENDLY_NAMEDeviceFriendlyName
WPD_DEVICE_TYPEDeviceType
WPD_DEVICE_NETWORK_IDENTIFIERDeviceNetworkIdentifier

 

Assigning and Getting Object Properties

The following HTML and JScript example demonstrates how to get the property values of a device and display them. In this example, deviceObject represents a WPD Device object injected into the scripting environment through the command window.external. The Device object properties DeviceFriendlyName, DeviceManufacturer, DeviceModel, and DeviceFirmwareVersion are all WPD Automation names that correspond to WPD PROPERTYKEYs.


<html>
<head>
<script language="jscript" type="text/jscript">    

function GetDeviceProperties()
{
    var deviceObject = window.external;

    nameDiv.childNodes[0].nodeValue = deviceObject.DeviceFriendlyName;
    manufacturerDiv.childNodes[0].nodeValue = deviceObject.DeviceManufacturer;
    modelDiv.childNodes[0].nodeValue = deviceObject.DeviceModel;
    firmwareDiv.childNodes[0].nodeValue = deviceObject.DeviceFirmwareVersion;
}   
</script>

</head>
<body >
Device Name = <div id="nameDiv">?</div>
Device Manufacturer = <div id="manufacturerDiv">?</div>
Device Model = <div id="modelDiv">?</div>
Firmware = <div id="firmwareDiv">?</div>
</body>
</html>

Assigning and Getting Binary Array Properties

Some object properties may contain binary arrays in which each element of the array represents a byte. The array supports a length property that returns the number of elements (bytes) in the array. It also supports a zero-based numeric index that can be used to get or set bytes in the array. Setting a particular byte modifies the array, but does not modify the binary property.

To update a binary property on an object, assign the array to the object's property, as shown in the following example.


wpdObject.SomeWritableBinaryProperty = updatedArray;

The following JScript example shows how to get and set a binary array as an object property.


// Getting a binary array as an object property.
var binaryArray = wpdObject.SomeBinaryProperty;
var strBytes = "";

for (i=0; i < binaryArray.length; i++)
{
    strBytes += binaryArray [i];
}

// Setting a binary array as an object property.
var newArray = new Array();

for (i=0; i < 10; i++)
{
    newArray[i] = i;
}

wpdObject.SomeWritableBinaryProperty = newArray;

Further Examples

For further examples of assigning and getting object properties, see the reference pages for Device.wpdProperty, Service.wpdProperty, Service.AbstractServices, Service.ServiceProperty, and Storage.WpdProperty.

Related topics

Device Object
Service Object
Storage Object
WPDObject
WPD Automation Programming Guide

 

 

Community Additions

ADD
Show: