serial中python通信

2020-12-13 05:56

阅读:452

标签:load   write   roo   usr   模块   串口   default   ports   end   

1、需要导入pyserial 的模块

脚本如下:

# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
reload(sys);
sys.setdefaultencoding("utf-8")
import serial
# 导入串口模块
import threading
import time
import serial
ser = serial.Serial("COM3",115200)
send = ser.write("\n")
send = ser.write("\n")
time.sleep(2)
send = ser.write("root")
send = ser.write("\n")
print ser.portstr
print send
time.sleep(2)
send = ser.write("nE7jA%5m")
send = ser.write("\n")
print send
time.sleep(2)
send = ser.write("export")
send = ser.write("\n")
print send
time.sleep(2)
data = ""
while ser.in_waiting > 0 :
    data+=ser.read(1)
if data != "":
    print data

 

serial中python通信

标签:load   write   roo   usr   模块   串口   default   ports   end   

原文地址:https://www.cnblogs.com/classics/p/11155875.html


评论


亲,登录后才可以留言!