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-
plaorm coding with the Plaorm 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 Plaorm 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 plaorms.py, and you add it to your script like this:
from synapse.platforms import *
Imporng the plaorms.py file like this tells SNAP to pay special aenon to what’s in the Plaorm field, and
makes a “plaorm” 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 beer than the first code sample, though. You could just as easily assign the contents of NV
Parameter 41 to a variable named plaorm yourself without imporng the plaorms.py file. But if you look into
the contents of the plaorms.py file, you’ll see that it does more than that.
The first thing plaorms.py does is import snapsys.py. This is the file that lets the system recognize the plaorms
variable. (The actual seng of the variable happens “behind the scenes” in SNAP through the inclusion of this
file.) The plaorms.py file then uses this plaorm 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 compability), or
RF200.py for RF200 SNAP Engines.
If you peruse those files, you’ll see that each contains a collecon of constant assignments with names like
“GPIO_1”. The “GPIO” in this constant name stands for “general-purpose input/output”, and gives us the
Rosea Stone we need to translate from plaorm to plaorm. Noce 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 Operang System