Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
ezeio2:scriptref:start [2019-09-02 20:50] – andreh | ezeio2:scriptref:start [2019-09-02 21:27] – andreh | ||
---|---|---|---|
Line 31: | Line 31: | ||
The estimated requirements for a script is displayed when compiling. | The estimated requirements for a script is displayed when compiling. | ||
- | === Programming | + | === Programming |
Although the user script runs in a sandboxed runtime engine, the recommended programming pattern is similar to [[https:// | Although the user script runs in a sandboxed runtime engine, the recommended programming pattern is similar to [[https:// | ||
Line 37: | Line 37: | ||
This means that you should avoid long-running loops, and instead make use of blocking calls or system callbacks provided in the function library. | This means that you should avoid long-running loops, and instead make use of blocking calls or system callbacks provided in the function library. | ||
- | The following calls are blocking: | + | The following calls are blocking |
| '' | | '' | ||
Line 57: | Line 57: | ||
| '' | | '' | ||
- | | '' | + | | '' |
| '' | | '' | ||
| '' | | '' | ||
Line 63: | Line 63: | ||
| '' | | '' | ||
+ | === State machines === | ||
+ | |||
+ | A common programming pattern in control applications is to use state machines. PAWN and the ezeio implements strong support for state machines. The following is a typical pattern: | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | new count = 0; | ||
+ | |||
+ | main() | ||
+ | { | ||
+ | SetTickInterval(500); | ||
+ | state WAITING; | ||
+ | } | ||
+ | | ||
+ | @Tick(uptime) < | ||
+ | { | ||
+ | if( GetField(1) < 100 ) // condition to start up the process | ||
+ | state IGNITION; | ||
+ | } | ||
+ | | ||
+ | // ***** the IGNITION state | ||
+ | |||
+ | entry() < | ||
+ | { | ||
+ | | ||
+ | count = 0; | ||
+ | } | ||
+ | | ||
+ | @Tick(uptime) < | ||
+ | { | ||
+ | if( GetField(2) > 100 ) // Did the engine start? | ||
+ | state RUNNING; | ||
+ | |||
+ | | ||
+ | state WAITING; | ||
+ | } | ||
+ | | ||
+ | exit() < | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | | ||
+ | // ***** the RUNNING state | ||
+ | |||
+ | @Tick(uptime) < | ||
+ | { | ||
+ | if( GetField(2) < 100 ) | ||
+ | state WAITING; | ||
+ | } | ||
+ | | ||
+ | </ | ||