30 |
"try checking the python-serial package is installed" |
"try checking the python-serial package is installed" |
31 |
|
|
32 |
from optparse import OptionParser |
from optparse import OptionParser |
33 |
|
import sys |
34 |
|
|
35 |
SENSOR_QUERY_CMD = (None, 'S', 'T', 'U') |
SENSOR_QUERY_CMD = (None, 'S', 'T', 'U') |
36 |
USAGE = "usage: %prog [options] [action]" |
USAGE = "usage: %prog [options] [action]" |
56 |
if not(options.sensor > 0 and options.sensor <= len(SENSOR_QUERY_CMD) - 1): |
if not(options.sensor > 0 and options.sensor <= len(SENSOR_QUERY_CMD) - 1): |
57 |
parser.error("Invalid sensor") |
parser.error("Invalid sensor") |
58 |
|
|
59 |
ser = serial.Serial(options.device, 9600, timeout=1) |
try: |
60 |
|
ser = serial.Serial(options.device, 9600, timeout=1) |
61 |
|
except serial.SerialException, e: |
62 |
|
print "%s" % (e) |
63 |
|
sys.exit(1) |
64 |
|
|
65 |
ser.write(SENSOR_QUERY_CMD[options.sensor]) |
ser.write(SENSOR_QUERY_CMD[options.sensor]) |
66 |
buf = ser.read(8) |
buf = ser.read(8) |