User manual

With an RF200, in order to flash an LED connected to the SNAP
Engine’s third pin, as we did above with the RF100, you would need to
use a command like this (simplified from the above example):
pulsePin(6, 500, True)
Fortunately, SNAP provides an easy mechanism for simplifying cross-
plaorm coding with the Plaorm value, stored in NV Parameter 41.
SNAP nodes produced by Synapse Wireless will come with this field
populated with the node type, e.g., “RF100” or “RF200” or “RF300”.
You can modify the value just as you could any other NV Parameter,
but first let’s take a look at why you might want to keep the default.
For starters, let’s approach this problem the hard way. You could easily
make use of the contents of the Plaorm parameter like this:
if loadNvParam(41) == 'RF100':
pulsePin(1, 500, True)
elif loadNvParam(41) == 'RF200':
pulsePin(6, 500, True)
But SNAP includes some things to improve on this. When you install Portal, a number of example scripts are
added to your PC in the snappyImages directory. That directory contains a subdirectory named Synapse, which
contains more scripts that help support the example scripts, and which you can use in your own scripts. The one
we’re most interested in at the moment is named plaorms.py, and you add it to your script like this:
from synapse.platforms import *
Imporng the plaorms.py file like this tells SNAP to pay special aenon to what’s in the Plaorm field, and
makes a “plaorm” variable available to you within your SNAPpy script. So now, you could do something like
this:
from synapse.platforms import *
if platform == 'RF100':
pulsePin(1, 500, True)
elif platform == 'RF200':
pulsePin(6, 500, True)
That isn’t a lot beer than the first code sample, though. You could just as easily assign the contents of NV
Parameter 41 to a variable named plaorm yourself without imporng the plaorms.py file. But if you look into
the contents of the plaorms.py file, you’ll see that it does more than that.
The first thing plaorms.py does is import snapsys.py. This is the file that lets the system recognize the plaorms
variable. (The actual seng of the variable happens “behind the scenes” in SNAP through the inclusion of this
file.) The plaorms.py file then uses this plaorm variable to select another file to import, such as RF100.py for
RF100s (or nodes that contain “RFEngine” in NV Parameter 41, for purposes of backwards compability), or
RF200.py for RF200 SNAP Engines.
If you peruse those files, you’ll see that each contains a collecon of constant assignments with names like
“GPIO_1”. The “GPIO” in this constant name stands for “general-purpose input/output”, and gives us the
Rosea Stone we need to translate from plaorm to plaorm. Noce that for the RF100, GPIO_1 is set to 1,
while for the RF200, GPIO_1 is set to 6. (These numbers may look familiar, if you’ve been reading closely.)
28 SNAP® Network Operang System