36 lines
521 B
Python
Executable File
36 lines
521 B
Python
Executable File
#!/usr/bin/python
|
|
import sys
|
|
import tty
|
|
import serial
|
|
import time
|
|
|
|
ser = serial.Serial("/dev/ttyUSB0", 38400)
|
|
|
|
voltage = 20000
|
|
current = 0
|
|
incdec = 0
|
|
|
|
while 1:
|
|
tdata = ser.read()
|
|
time.sleep(1)
|
|
data_left = ser.inWaiting()
|
|
tdata += ser.read(data_left)
|
|
|
|
out = "A%05d,12300,%05d,1,1,1B" % (voltage, current)
|
|
print out
|
|
ser.write(out)
|
|
|
|
if incdec == 0:
|
|
current = current + 1000
|
|
else:
|
|
current = current - 1000
|
|
|
|
if current > 20000:
|
|
current = 20000
|
|
incdec = 1
|
|
|
|
if current < 0:
|
|
current = 0
|
|
incdec = 0
|
|
|