39 lines
601 B
Python
Executable File
39 lines
601 B
Python
Executable File
#!/usr/bin/python
|
|
import sys
|
|
import tty
|
|
import serial
|
|
import time
|
|
|
|
ser = serial.Serial("/dev/ttyUSB0", 38400)
|
|
|
|
power = 0
|
|
incdec = 0
|
|
|
|
while 1:
|
|
tdata = ser.read()
|
|
|
|
if tdata == 'a':
|
|
print 'Local power = ' + str(power)
|
|
ser.write(str(power) + '\x0d')
|
|
#ser.write('100\n')
|
|
ser.flush()
|
|
|
|
if incdec == 0:
|
|
power = power + 10
|
|
else:
|
|
power = power - 10
|
|
|
|
if power > 400:
|
|
power = 400
|
|
incdec = 1
|
|
|
|
if power < 0:
|
|
power = 0
|
|
incdec = 0
|
|
else:
|
|
sys.stdout.write(tdata)
|
|
sys.stdout.write(ser.readline())
|
|
#data_left = ser.inWaiting()
|
|
#tdata += ser.read(data_left)
|
|
#print tdata
|