User manual

Remember: SNAPpy Integers have a Sign Bit
Another side-effect of SNAPpy integers being signed negave numbers shied right are sll negave (the sign
bit is preserved).
You might expect 0x8000 >> 1 to be 0x4000 but really it is 0xC000. You can use a bitwise “and” to get the
desired effect if you need it.
X = X >> 1
X = X & 0x7FFF
Pay Attention to Script Output
Any SNAPpy script errors that occur can be printed to the previously configured STDOUT desnaon, such as
serial port 1. If your script is not behaving as expected, be sure and check the output for any errors that may be
reported.
If the node having the errors is a remote one (you cannot see its script output), remember that you can invoke
the “Intercept STDOUT” acon from the Node Info tab for that node. The error messages will then appear in the
Portal event log, depending on the preferences specified in Portal.
Don’t Define Functions Twice
In SNAPpy (as in Python), defining a funcon that already exists counts as a re-definion of that funcon.
Other script code that used to invoke the old funcon, will now be invoking the replacement funcon instead.
Using meaningful funcon names will help alleviate this.
There is limited dynamic memory in SNAPpy
Funcons that manipulate strings (concatenaon, slicing, subscripng, chr()) all pull from a small pool of
dynamic (reusable) string buffers.
NOTEthis is different from prior versions, which only had a single fixed buffer for each type of string
operaon.
You sll do not have unlimited string space, and can run out if you try to keep too many strings. See each
plaorm’s secon in the SNAP Reference Manual for a breakdown of how many string buffers are available, and
what size those buffers are.
Use the Supported Form of Import
In SNAPpy scripts you should use the form:
from moduleName import *
from synapse.moduleName import *
from moduleName import specificFunction
Remember Portal Speaks Python Too
SNAPpy scripts are a very powerful tool, but the SNAPpy language is only a small modified subset of full-blown
Python.
In some cases, you may be able to take advantage of Portal’s more powerful capabilies by having SNAPpy
scripts (running on remote nodes) invoke rounes contained within Portal scripts. This applies not only to the
scripng language differences, but also to the addional hardware a desktop plaorm adds.
SNAP® Network Operang System 47