7 Scripting
35
id=="dli.script.script_event" and script_data.coil_index==1
script_data and script_data.coil_state
All script-generated events have INFO severity level.
Events can also be waited for and received, and that is not limited to system-level events discussed above. An event
can have several components with integer indices (the components themselves can be any types, e.g. tables).
Events generated by the API generally have two components, a numeric timestamp (in seconds since the epoch,
1970-01-01T00:00:00Z) and a property table, but totally custom events are possible.
It is usually essential not to miss an event when processing them, so events are placed into queues waiting to be
processed. The
event.stream
function is a Lua generator to be used in a
for
loop like this:
for queue_idx,value1,value2,value3... in event.stream(queue1,queue2,queue3...) do
...
end
event.stream
accepts any number of queue arguments and waits for events to be received (causing a delay
and allowing other threads to run), then extracts and returns their components. Queues are processed in priority
order (e.g.
queue1
messages get processed before
queue2
messages).
The
event.queue
function creates a totally custom event queue not bound to any event source. Additional
custom events can be placed into any queue using
q[# q+1]={value1,value2,value3...}
regardless
of the method used to create the queue; for queues created by
event.queue
, this is also the only way for events
to appear there.
The
event.listener
function creates an event queue listening to the global system events (i.e. the ones
received by the notification system and generated by other systems and
event.send
function). Events have a
timestamp and a property table as components. The property table contains event-type-dependent properties (e.g.
the
id
is the event type identifier).
The following example function can be used to display all system events in internal form in the event log:
function dump_system_events()
for i,t,data in event.stream(event.listener()) do
dump({i,t,data})
end
end
The
event.change_listener
function takes any number of API objects
object1,object2,object3...
as arguments and creates an event queue listening to changes in the API objects' states. Events have a timestamp
and a property table as components; the property table contains the following fields:
•
object
: the changed object;
•
index
: the object's number in the argument list;
•
key
: the property of the object that has changed;
•
value
: the new value of the property.
Only a subset of the API's objects support change notifications; they include outlet objects
outlet[i]
, meter
values
meter.values[k]
and AutoPing items
autoping.items[i]
.
The following example function can be used to attempt to mirror physical state of outlet 1 to outlet 2:
DLI LPC9 User’s Guide: 1.7.24.0
Содержание LPC9
Страница 1: ...DLI LPC9 User s Guide 1 7 24 0 ...
Страница 81: ......