<s> """<STR_LIT>""" <EOL> from xbee import XBee <EOL> from xbee . helpers . dispatch import Dispatch <EOL> import time <EOL> import serial <EOL> PORT = '<STR_LIT>' <EOL> BAUD_RATE = <NUM_LIT> <EOL> ser = serial . Serial ( PORT , BAUD_RATE ) <EOL> def status_handler ( name , packet ) : <EOL> print "<STR_LIT>" , packet [ '<STR_LIT:status>' ] <EOL> def io_sample_handler ( name , packet ) : <EOL> print "<STR_LIT>" , packet [ '<STR_LIT>' ] <EOL> dispatch = Dispatch ( ser ) <EOL> dispatch . register ( <EOL> "<STR_LIT:status>" , <EOL> status_handler , <EOL> lambda packet : packet [ '<STR_LIT:id>' ] == '<STR_LIT:status>' <EOL> ) <EOL> dispatch . register ( <EOL> "<STR_LIT>" , <EOL> io_sample_handler , <EOL> lambda packet : packet [ '<STR_LIT:id>' ] == '<STR_LIT>' <EOL> ) <EOL> xbee = XBee ( ser , callback = dispatch . dispatch ) <EOL> while True : <EOL> try : <EOL> time . sleep ( <NUM_LIT> ) <EOL> except KeyboardInterrupt : <EOL> break <EOL> xbee . halt ( ) <EOL> ser . close ( ) </s>
