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:49] – andreh | ezeio2:scriptref:start [2019-11-19 01:51] – 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 cooperative multitasking. | + | Although the user script runs in a sandboxed runtime engine, the recommended programming pattern is similar to [[https:// |
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 45: | Line 45: | ||
| '' | | '' | ||
| '' | | '' | ||
- | | '' | ||
| '' | | '' | ||
| '' | | '' | ||
Line 57: | Line 56: | ||
| '' | | '' | ||
- | | '' | + | | '' |
| '' | | '' | ||
| '' | | '' | ||
Line 63: | Line 62: | ||
| '' | | '' | ||
+ | === 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 showing the startup sequence of an engine. Note that there are three @Tick handlers; one for each state. Also note the " | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | new count = 0; | ||
+ | |||
+ | main() | ||
+ | { | ||
+ | SetTickInterval(100); | ||
+ | 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 ) // Check if the engine stopped | ||
+ | state WAITING; | ||
+ | } | ||
+ | | ||
+ | </ | ||