#!/usr/bin/python3
from time import sleep
import serial
import sys
import datetime

while (True):
    serial_not_open = True
    while serial_not_open:
        try:
            ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1) 
        except: 
            sleep(0.5)
        else:
            serial_not_open = False

    no_exception = True
    while no_exception:
        try:
            while True:
                while ser.inWaiting():
                    print(ser.read().decode('utf-8'), end='')
                sleep(0.1) 
        except: 
            print(datetime.datetime.now().strftime("%d.%m.%Y %H:%M:%S")," - Serial Device disappeared...")
            ser.close()
            no_exception = False
