stopi2/serialutils.py

18 lines
492 B
Python

import serial
import serial.tools.list_ports
def find_cam_port():
serial_devices = serial.tools.list_ports.comports()
for dev in serial_devices:
if str(dev).find('Piwebcam') != -1:
return str(dev).split(' ')[0]
return None
def send_serial_cmd(cam_port, cmd:str, clear=True):
con = serial.Serial(cam_port, baudrate=115200)
if clear:
append = b'\rclear\r'
else:
append = b'\r'
con.write(str.encode(cmd) + append)
con.close()