init_serial.py 357 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import serial
import time

ser = serial.Serial(port='/dev/ttyACM0',
                    baudrate=9600)

def send(command_str):
    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))