Specifications
You can use a special type of comment called a “docstring”............................................................ 21
4. SNAPpy versus Python...................................................................................................................... 22
Modules.............................................................................................................................................. 22
Variables ............................................................................................................................................ 22
Functions............................................................................................................................................ 22
Data Types ......................................................................................................................................... 22
Keywords ........................................................................................................................................... 23
Operators............................................................................................................................................ 23
Slicing ................................................................................................................................................ 23
Concatenation .................................................................................................................................... 23
Subscripting ....................................................................................................................................... 23
Expressions ........................................................................................................................................ 24
Python Built-ins ................................................................................................................................. 24
Print.................................................................................................................................................... 24
5. SNAPpy Application Development................................................................................................... 25
Event-Driven Programming............................................................................................................... 25
SNAP Hooks...................................................................................................................................... 25
Transparent Data (Wireless Serial Port) ............................................................................................ 27
Scripted Serial I/O (SNAPpy STDIO)............................................................................................... 27
The Switchboard ................................................................................................................................ 27
Debugging.......................................................................................................................................... 30
Sample Application – Wireless UART.............................................................................................. 30
Code Density...................................................................................................................................... 33
6. Advanced SNAPpy Topics ................................................................................................................ 34
Interfacing to external CBUS slave devices ...................................................................................... 34
Interfacing to external SPI slave devices........................................................................................... 35
Interfacing to external I
2
C slave devices ........................................................................................... 38
Interfacing to multi-drop RS-485 devices.......................................................................................... 39
Encryption between SNAP nodes...................................................................................................... 40
Recovering an Unresponsive Node.................................................................................................... 41
7. SNAPpy – The API............................................................................................................................ 43
Alphabetical SNAP API .................................................................................................................... 43
bist() – Synapse internal use only.................................................................................................. 43
call(rawOpcodes, functionArgs…) – Call embedded C code....................................................... 43
callback(callback, remoteFunction, remoteFunctionArgs…).................................................... 43
callout(nodeAddress, callback, remoteFunction, remoteFunctionArgs…) ............................... 44
cbusRd(numToRead) – Read bytes in from the CBUS................................................................ 45
cbusWr(str) – Write bytes out to the CBUS................................................................................. 45
chr(number) – Generate a single-character-string........................................................................ 45
crossConnect(endpoint1, endpoint2) – Tie two endpoints together ............................................ 45
eraseImage() – Erase any SNAPpy image from the node ............................................................ 46
errno() – Read and reset latest error code..................................................................................... 46
flowControl(uart, isEnabled, isTxEnable) – Enable/disable flow control.................................. 47
getChannel() – Get which channel the node is on ........................................................................ 48
getEnergy() – Get energy reading from current channel .............................................................. 49
getI2cResult() – Get status code from most recent I
2
C operation ................................................ 50
Page 4 of 202 SNAP Reference Manual Document Number 600-0007K