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 PROPERTYKEY | WPD Automation Name |
---|---|
WPD_OBJECT_ID | ObjectId |
WPD_OBJECT_NAME | ObjectName |
WPD_OBJECT_PERSISTENT_UNIQUE_ID | ObjectPersistentUniqueId |
WPD_OBJECT_FORMAT | ObjectFormat |
WPD_FUNCTIONAL_OBJECT_CATEGORY | FunctionalObjectCategory |
WPD_DEVICE_FIRMWARE_VERSION | DeviceFirmwareVersion |
WPD_DEVICE_MANUFACTURER | DeviceManufacturer |
WPD_DEVICE_MODEL | DeviceModel |
WPD_DEVICE_SERIAL_NUMBER | DeviceSerialNumber |
WPD_DEVICE_POWER_LEVEL | DevicePowerLevel |
WPD_DEVICE_POWER_SOURCE | DevicePowerSource |
WPD_DEVICE_PROTOCOL | DeviceProtocol |
WPD_DEVICE_SUPPORTS_NON_CONSUMABLE | DeviceSupportsNonConsumable |
WPD_DEVICE_FRIENDLY_NAME | DeviceFriendlyName |
WPD_DEVICE_TYPE | DeviceType |
WPD_DEVICE_NETWORK_IDENTIFIER | DeviceNetworkIdentifier |
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