參考文章:html
https://blog.csdn.net/dgut_guangdian/article/details/78391270python
https://www.cnblogs.com/lanceyu/p/10201236.htmlbootstrap
https://blog.csdn.net/absinjun/article/details/81407790windows
首先安裝pipless
你能夠經過如下命令來判斷是否已安裝:curl
pip --version
若是你還未安裝,則可使用如下方法來安裝:ui
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # 下載安裝腳本 $ sudo python get-pip.py # 運行安裝腳本
顯示版本和路徑url
pip --version
安裝serial、easygui模塊,spa
windows下須要安裝pyserial,安裝步驟見:.net
https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/installing-python-and-pyserial
幫助文檔見:
https://pyserial.readthedocs.io/en/latest/shortintro.html
代碼:
import serial import time ser = serial.Serial() ser.baudrate = 9600 ser.port = 'COM3' print(ser) ser.open() print(ser.is_open) i=1 while(1): demo=b"1" ser.write(demo) s = ser.read(1) print(s) time.sleep(0.1) demo = b"2" ser.write(demo) s = ser.read(1) print(s) time.sleep(0.1)
繼續。。