Datasheet

Python Script
The following code performs the same function, but has been placed inside a Python
wrapper using PySerial to show how you can script actions for the AT parser.
import io
import sys
import serial
import random
from time import sleep
filename = "hrm.py"
ser = None
serio = None
verbose = True # Set this to True to see all of the incoming serial data
def usage():
"""Displays information on the command-line parameters for this script"""
print "Usage: " + filename + " <serialPort>\n"
print "For example:\n"
print " Windows : " + filename + " COM14"
print " OS X : " + filename + " /dev/tty.usbserial-DN009WNO"
print " Linux : " + filename + " /dev/ttyACM0"
return
def checkargs():
"""Validates the command-line arguments for this script"""
if len(sys.argv) < 2:
print "ERROR: Missing serialPort"
usage()
sys.exit(-1)
if len(sys.argv) > 2:
print "ERROR: Too many arguments (expected 1)."
usage()
sys.exit(-2)
def errorhandler(err, exitonerror=True):
"""Display an error message and exit gracefully on "ERROR\r\n" responses"""
print "ERROR: " + err.message
if exitonerror:
ser.close()
sys.exit(-3)
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m0-bluefruit-le Page 193 of 238