client.py
881 Bytes
import serial
from threading import Thread
s = serial.Serial(
port = 'COM3',
baudrate= 9600,
)
print('[+] connected')
buffer = []
def cb_recv():
while True:
l = s.readline().decode(encoding='ascii', errors='ignore')
buffer.append(l)
Thread(target=cb_recv).start()
while True:
if len(buffer) != 0:
for l in buffer:
print('received:', l)
buffer.clear()
inst = input("Input:")
tokens = inst.split(' ')
if tokens[0] == 'i': # inject a code
with open(tokens[1], 'rb') as f:
s.write(f.read())
elif tokens[0] == 's': # input string
type = int(tokens[1])
msg = tokens[2].encode(encoding='ascii')
payload = bytes([len(msg), type]) + msg
print('sent:', payload)
s.write(payload)
elif tokens[0] == 'q': # quit
s.close()
break