User manual
Remember: SNAPpy Integers have a Sign Bit
Another side-effect of SNAPpy integers being signed – negave numbers shied right are sll negave (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 desnaon, 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” acon 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 funcon that already exists counts as a re-definion of that funcon.
Other script code that used to invoke the old funcon, will now be invoking the replacement funcon instead.
Using meaningful funcon names will help alleviate this.
There is limited dynamic memory in SNAPpy
Funcons that manipulate strings (concatenaon, slicing, subscripng, chr()) all pull from a small pool of
dynamic (reusable) string buffers.
NOTE – this is different from prior versions, which only had a single fixed buffer for each type of string
operaon.
You sll do not have unlimited string space, and can run out if you try to keep too many strings. See each
plaorm’s secon 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 capabilies by having SNAPpy
scripts (running on remote nodes) invoke rounes contained within Portal scripts. This applies not only to the
scripng language differences, but also to the addional hardware a desktop plaorm adds.
SNAP® Network Operang System 47