| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | port = '/dev/cu.wchusbserial1420' |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import sys |
| | import serial |
| | import threading |
| | from time import sleep |
| | import readchar |
| |
|
| | |
| |
|
| | ser = serial.Serial(port, 9600, timeout = 0.3, xonxoff = True) |
| |
|
| | |
| | |
| | |
| |
|
| | def sendline(l): |
| | sleep(0.1) |
| | for ch in l: |
| | sleep(0.01) |
| | chp = ch.encode('utf-8') |
| | ser.write(chp) |
| |
|
| | cont = True; |
| | saveflag = False; |
| |
|
| | def loadfile(): |
| | fn = input("Loading from file: ") |
| | f = open(fn, "r") |
| | for line in f: |
| | sendline(line) |
| |
|
| | |
| | |
| | |
| | def readfunction(): |
| | while cont: |
| | ch = ser.read() |
| | chp = ch.decode('utf-8') |
| | if ( chp == "\n"): |
| | sys.stdout.write("\r"); |
| | if ( chp == "\r"): |
| | sys.stdout.write("\r"); |
| | sys.stdout.write("\n"); |
| | if ( chp == "\x7f" ): |
| | sys.stdout.write("\b") |
| | sys.stdout.write(chp) |
| | sys.stdout.flush() |
| | if (saveflag): |
| | if (chp != "\r"): |
| | f2.write(chp) |
| |
|
| | reader = threading.Thread(target=readfunction) |
| | reader.start() |
| |
|
| | |
| | |
| | |
| | while cont: |
| | ch = readchar.readchar() |
| | chp = ch.encode('utf-8') |
| | if (chp == b'\x04'): |
| | cont = False |
| | elif (chp == b'\x0c'): |
| | loadfile() |
| | elif (chp == b'\x13'): |
| | if (not saveflag): |
| | print("Save on") |
| | fn = input("Save to file: ") |
| | f2 = open(fn, "w") |
| | saveflag = True |
| | else: |
| | saveflag = False |
| | print("Save off") |
| | f2.close() |
| | else: |
| | ser.write(chp) |
| |
|
| | reader.join() |
| |
|