26 lines
595 B
Python
26 lines
595 B
Python
|
#/usr/bin/env python3
|
||
|
|
||
|
import serial
|
||
|
import time
|
||
|
|
||
|
def main():
|
||
|
ser = serial.Serial('/dev/kaboard', 38400, timeout=10)
|
||
|
ser.flush()
|
||
|
|
||
|
while True:
|
||
|
line = ser.readline()
|
||
|
while len(line) == 0:
|
||
|
line = ser.readline()
|
||
|
|
||
|
line = line.decode("ascii")[:-1]
|
||
|
print("[%s] >> %s" % (time.strftime('%H:%m:%S'), line))
|
||
|
if line == "?":
|
||
|
timestamp = "%d\n" % int(time.time())
|
||
|
print("[%s] << %s" % (time.strftime('%H:%m:%S'),timestamp[:-1]))
|
||
|
ser.write(timestamp.encode('ascii'))
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|