2014-06-03 00:54:38 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import tty
|
|
|
|
import serial
|
|
|
|
import time
|
|
|
|
|
|
|
|
ser = serial.Serial("/dev/ttyUSB0", 38400)
|
|
|
|
|
2014-06-03 14:29:55 +00:00
|
|
|
power = 0
|
2014-06-03 00:54:38 +00:00
|
|
|
incdec = 0
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
tdata = ser.read()
|
|
|
|
time.sleep(1)
|
|
|
|
|
2014-06-03 14:29:55 +00:00
|
|
|
if tdata == 'a':
|
|
|
|
print power
|
|
|
|
ser.write(str(power) + '\n')
|
|
|
|
#ser.write('100\n')
|
|
|
|
ser.flush()
|
|
|
|
|
|
|
|
if incdec == 0:
|
|
|
|
power = power + 10
|
|
|
|
else:
|
|
|
|
power = power - 10
|
2014-06-03 00:54:38 +00:00
|
|
|
|
2014-06-03 14:29:55 +00:00
|
|
|
if power > 400:
|
|
|
|
power = 400
|
|
|
|
incdec = 1
|
2014-06-03 00:54:38 +00:00
|
|
|
|
2014-06-03 14:29:55 +00:00
|
|
|
if power < 0:
|
|
|
|
power = 0
|
|
|
|
incdec = 0
|
|
|
|
else:
|
|
|
|
data_left = ser.inWaiting()
|
|
|
|
tdata += ser.read(data_left)
|
|
|
|
print tdata
|