init_serial.py 587 Bytes
Newer Older
1 2 3
import serial
import time

4 5 6
from app import Meteorologger

ser = Meteorologger().get_serial()
7

8
def send(command_str, response_wait=0):
9 10 11
    '''
    Send the string 'command_str' to the serial port and return the response.
    '''
12
    ser.write(bytes(command_str, encoding='utf-8'))
13
    time.sleep(response_wait)
14
    try:
15
        raw = ser.readall()
16 17 18
        return raw.decode('ascii').strip()
    except:
        print("Unable do decode raw line read:\n{}".format(raw))
19 20 21 22 23

print("\nExecuting send('help') ... waiting for board response ...")
s = send('help')
s = send('help')
print('\n' + s)