init_serial.py 441 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):
9 10 11
    '''
    Send the string 'command_str' to the serial port and return the response.
    '''
12 13 14 15 16 17 18
    ser.write(bytes(command_str, encoding='utf-8'))
    time.sleep(1.5)
    try:
        raw = ser.readline()
        return raw.decode('ascii').strip()
    except:
        print("Unable do decode raw line read:\n{}".format(raw))