python做上位機


參考文章:

https://blog.csdn.net/dgut_guangdian/article/details/78391270

https://www.cnblogs.com/lanceyu/p/10201236.html

https://blog.csdn.net/absinjun/article/details/81407790

首先安裝pip

你可以通過以下命令來判斷是否已安裝:

pip --version

如果你還未安裝,則可以使用以下方法來安裝:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # 下載安裝腳本 $ sudo python get-pip.py # 運行安裝腳本


顯示版本和路徑

pip --version

安裝serial、easygui模塊,

windows下需要安裝pyserial,安裝步驟見:

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)

  繼續。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM