next up previous contents
Next: 2.5.14 An example of Up: 2.5 More Examples Previous: 2.5.12 An example of   Contents

2.5.13 An example of event parameters

The EVENT macro is predefined and is used to output an event in a model. This macro accepts one to three parameters. The first parameter is a string that specifies the event name. The second parameter is usually a Python list containing arbitrary parameters that are sent with the event. (By default, it is an empty list.) The transition that handles the event can thus retrieve the parameter list with macro PARAMS. Individual parameter is accessible with [PARAMS][i], where i is the index of the parameter in the list. The third parameter of the EVENT macro may be a lock to be released when the event has been handled (discussed later).

The following example (param1.des) demonstrates the use of the two macros:

STATECHART:
    A [DS]
    B

TRANSITION:
    S: A
    N: A
    E: e
    O: [EVENT("f", ["message", "Hello World"])]

TRANSITION:
    S: A
    N: B
    E: f
    O: [DUMP([PARAMS][0]+": "+[PARAMS][1])]

The simulation result is as following:

['A'] > e
message: Hello World
['B'] > exit

In this example, the user sends event e to the model. The event triggers a self-loop on A. In the output of the self-loop, event f is output with two parameters: Python strings "message" and "Hello World". This event is then handled by the other transition defined in the model. In the output of that transition, [PARAMS][0] is equal to "message", and [PARAMS][1] is equal to "Hello World".


next up previous contents
Next: 2.5.14 An example of Up: 2.5 More Examples Previous: 2.5.12 An example of   Contents
Thomas Huining Feng
2004-04-05