User manual

Remember: Serial output Takes Time
A script that does:
print "imagine a very long and important message here"
sleep(mode, duration)
…is not likely to be allowing enough me for the text to make it all the way out of the node (parcularly at
slower baud rates) before the sleep() command shuts the node off.
One possible soluon would be to invoke the sleep() funcon from the mer hook. This example hooks into the
HOOK_100MS event.
In the script startup code:
sleepCountDown = 0
In the code that used to do the “print + sleep
global sleepCountDown
print "imagine a very long and important message here"
sleepCountDown = 500 # actual number of milliseconds TBD
In the handler for HOOK_100MS:
global sleepCountDown
if sleepCountDown != 0:
if sleepCountDown <= 100: # timebase is 100 ms
sleepCountDown = 0
sleep(mode, duration)
else:
sleepCountDown -= 100
Remember: SNAP Engines do not have a lot of RAM
SNAPpy scripts should avoid generang a flood of text output all at once. (There will be nowhere to buffer the
output.) Instead, generate the composite output in small pieces (for example, one line at a me), triggering the
next step of the process with the HOOK_STDOUT event.
If a script generates too much output at once, the excess text will be truncated.
Remember: SNAPpy Numbers Are Integers
2/3 = 0 in SNAPpy. As in all fixed-point systems, you can work around this by “scaling” your internal calculaons
up by a factor of 10, 100, etc. You then scale your final result down before presenng it to the user.
Remember: SNAPpy Integers are Signed
SNAPpy integers are 16-bit numbers, and have a numeric range of -32768 to +32767. Adding 1 to 32767 gives
you -32768.
Be careful that any intermediate math computaons do not exceed this range, as the resulng overflow value
will be incorrect.
46 SNAP® Network Operang System