Specifications
Beware of Accidental Local Variables
All SNAPpy functions can read global variables, but (as in Python) you need to use the “global”
keyword in your functions if you want to write to them.
count = 4
def bumpCount():
count = count + 1
…is not going to do what you want (count will still equal 4). Instead, write something like:
count = 4
def bumpCount():
global count
count = count + 1
Don’t Cut Yourself Off (Packet Serial)
Portal talks to its “bridge” (directly connected) node using a packet serial protocol.
SNAPpy scripts can change both the UART and Packet Serial settings.
This means you can be talking to a node from Portal, and then upload a script into that node that starts
using that same serial port for some other function (for example, for script text output). Portal will no
longer be able to communicate with that node serially.
Remember Serial Output Takes Time
A script that does:
print "imagine a very long and important message here"
sleep(mode, duration)
…might not be allowing enough time for the text to make it all the way out of the node (particularly at
slower baud rates) before the sleep() command shuts the node off.
One possible solution would be to invoke the sleep() function from the timer 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 timer code:
Page 88 of 202 SNAP Reference Manual Document Number 600-0007K