RegisterForNotification
is used to register for notification with a sensor channel to receive channel data or channel property changes. This is associated with the transaction ID of an asynchronous request.
These notifications are continuous in nature and are stopped by invoking the Cancel
command on the retrieved transaction ID.
The following is an example for using RegisterForNotification
:
Asynchronous
sensor_handle.call('RegisterForNotification', {'ListeningType': u'ChannelData', 'ChannelInfoMap': {'ChannelId': result['ChannelId'], 'ContextType': result['ContextType'], 'Quantity': result['Quantity'], 'ChannelType': result['ChannelType'], 'Location': result['Location'], 'VendorId': result['VendorId'], 'DataItemSize': result['DataItemSize'], 'ChannelDataTypeId': result['ChannelDataTypeId']}}, callback=sensor_callback)
where, sensor_callback
is the user defined callback function.
The following table summarizes the specification of RegisterForNotification
:
Interface | ISensor |
Description | Registers for notification with a sensor channel to receive channel data. |
Response Model | Asynchronous |
Pre-condition | ISensor interface is loaded. |
Post-condition | Client application receives an array of channel information to open channels. |
Input Parameters
Input parameter is a set of arguments that specifies the Listening
Type and the ChannelInfoMap
.
|
Output Parameters
Output contains ReturnValue
. It also contains ErrorCode
and an ErrorMessage
if the operation fails. ReturnValue
is an object, which contains output parameter details depending on the listening type and channel selected.
|
Errors
The following table lists the error codes and their values:
|
Error Messages
The following table lists the error messages and their description:
|
Example
The following sample code illustrates how to receive notification for channel data, on registering:
import scriptext import e32 # Using e32.Ao_lock() to make main function wait till callback is hit lock = e32.Ao_lock() # Callback function will be called when the requested service is complete def register_operation(trans_id, event_id, input_params): if trans_id != scriptext.EventCompleted: print "DataType: ", input_params["ReturnValue"]["DataType"] print "TimeStamp: ", input_params["ReturnValue"]["TimeStamp"] print "X-Axis Rotation: ", input_params["ReturnValue"]["XRotation"] print "Y-Axis Rotation: ", input_params["ReturnValue"]["YRotation"] print "Z-Axis Rotation: ", input_params["ReturnValue"]["ZRotation"]
See About this document... for information on suggesting changes.