Please note: this site is from a previous course iteration and is no longer updated.
Source code for pneumatics_animation.SensorProtocol
"""\
SensorProtocol.py : application-specific class to manage serial communication with an Arduino sketch reporting sensor data.
Copyright (c) 2015-2017, Garth Zeglin. All rights reserved. Licensed under the terms
of the BSD 3-clause license.
"""
#================================================================
from __future__ import print_function
import time
from .ArduinoProtocol import ArduinoProtocol
#================================================================
[docs]class SensorProtocol(ArduinoProtocol):
"""Example class to communicate with an Arduino sketch which reports lists of numbers.
"""
def __init__(self, **kwargs ):
# initialize the parent class
ArduinoProtocol.__init__(self, **kwargs)
# define attributes to hold sensor and status values
self.values = list() #: List of the most recent values received.
return
[docs] def message_received(self, tokens):
"""Application-specific message processing to parse lists of tokens received
from the Arduino sketch. This implementation just converts every token
to a number and stores them in a list in an instance attribute. This
method overrides the null implementation in the parent class.
:param tokens: list of string tokens
"""
# Assume all messages are a list of numbers.
self.values = [float(token) for token in tokens]
return
################################################################