我正在尝试连接到d-link 1210 我使用这段代码
import os
import sys
import time
import serial
import serial.tools.list_ports
print('Search...')
ports = serial.tools.list_ports.comports(include_links=False)
for port in ports :
print('Find '+ port.device)
ser = serial.Serial(port.device)
if ser.isOpen():
ser.close()
ser = serial.Serial(port.device, 9600, timeout=1)
ser.flushInput()
ser.flushOutput()
print('Connect to ' + ser.name)
ser.write(" \r\n".encode())
ser.write("sh sw \r\n".encode())
while True:
response = ser.readline()
print(response)
响应 Response
如何从输出中删除符号?并停止传输而不断开连接?