Skip to content

Instantly share code, notes, and snippets.

@peisenhower
Created April 11, 2017 21:12
Show Gist options
  • Save peisenhower/9f2c193016ca1f70aa4f1132a674b85b to your computer and use it in GitHub Desktop.
Save peisenhower/9f2c193016ca1f70aa4f1132a674b85b to your computer and use it in GitHub Desktop.
Plumbus Heat Step
#!/usr/bin/env python
# python 3
from serial import Serial
import time
import argparse
from threading import Thread
class Command():
"""docstring for Command"""
def __init__(self, delay, cmd):
self.cmd = cmd
self.delay = delay
def has_callback(self):
if b'setpoint' in self.cmd:
return True
else:
return False
setup = [
Command(5.0, b'spoof enable 511\r\n'),
]
command_set = [
Command(30.0, b'spoof setpoint 40\r\n'),
Command(30.0, b'spoof setpoint 50\r\n'),
Command(30.0, b'spoof setpoint 60\r\n'),
Command(30.0, b'spoof setpoint 70\r\n'),
Command(30.0, b'spoof setpoint 80\r\n'),
Command(30.0, b'spoof setpoint 90\r\n'),
Command(30.0, b'spoof setpoint 100\r\n'),
Command(90.0, b'spoof setpoint 30\r\n'),
Command(90.0, b'spoof enable 0\r\n'),
]
def readline(com):
eol = b'\r\n'
leneol = len(eol)
line = bytearray()
while True:
c = com.read(1)
if c:
line += c
if line[-leneol:] == eol:
break
else:
break
if len(line) > 0:
print(line.decode())
return bytes(line)
def drainInput(com):
length = len(readline(com))
while length > 0:
length = len(readline(com))
def runner():
com = Serial()
com.port = 'COM3'
com.baudrate = 115200
com.timeout = 0
com.open()
for c in setup:
com.write(c.cmd)
print(c.cmd)
drainInput(com);
time.sleep(c.delay)
count = 0
while count < 1:
print('\r\nLoop {}'.format(count))
count += 1
for c in command_set:
com.write(c.cmd)
print(c.cmd)
drainInput(com)
time.sleep(c.delay)
com.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='loop serial commands')
runner()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment