< Home

Supporting Resident Script

Interface Name

Supporting resident script

Application Phase

Execution phase

API Prototype

result1_value, result2_description = ops.wait()

Description

None

Return Value

The result1_value and result2_description in the API prototype indicate return values.

The first return value 0 indicates that an event is executed successfully, and the first return value 1 indicates that an event fails to be executed.

The second return value is a string of characters indicating the results.

Usage Description

In most circumstances, a process needs to be started before and stopped after a Python script is executed. It takes some time to start and stop a process. If the subscription event in the script is triggered for multiple times, the device needs to repeat starting a process before executing the action defined in the subscription phase and stopping the process after the action is complete. In this case, you can use a resident script to reduce the time a device waits for a process to start or stop.

A resident script is usually used together with a cycle counter. After a subscription event is matched, the device starts a process when it performs the action for the first time. After this action is complete, the process is suspended and the number of cycles decreases by one. When the event is matched again, the next action is triggered, and the number of cycles is decreased by one again. This step is repeated until the number of cycles in the script reaches 0, at which point the process is stopped.

You can use the Returning Event Execution Results API to return the result, and then suspend the process and wait for the next event. In this way, the resident script can be used to process events.

Example

When a subscription event is matched for the first time, the device starts a process and displays the message alarm generated. Then the process enters the waiting state and waits for the next time the subscribed event is matched. After the event is matched five times and the message alarm generated is displayed five times, the device displays the message end and stops the process.

a = 5
while a > 0:
	a = a - 1
	print("alarm generated")
	status, err_str = ops.wait()     # The message alarm generated is displayed, the process enters the waiting status and waits for the event to be matched for the next time.
print 'end'
return 0
Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >