這篇網誌主頁介紹的是 PySerial這個套件
下面就開始介紹如何安裝與使用
透過pip安裝pyserial套件
$ pip install pyserial
安裝完畢之後,即可開始使用pyserial
首先我們必須先開啟我們想使用的port,以下提供兩種方式
1.第一種直接將連接資訊傳入初始化資料,此方法會直接開啟PORT
import serial
ser = serial.Serial('COM1', 19200, timeout=1)
2.第二種用設定的方式設定資料,此方法必須在呼叫開啟PORT的函式
import serial
ser.baudrate = 19200
ser.port = 'COM1'
ser.open()
在開啟PORT之後,就剩下讀取和輸出的功能
讀取的方法常見的有以下幾種:
ser.read(1) # 小括號內可以填入一次要讀取的byte數
ser.readline() # 讀取一列資料直到換行符號
ser.readlines() # 讀取全部的資料
讀取進來的資料為Byte,要處理成字串的話記得加上decode()
寫入的方法:
ser.write("hello".encode())
最後使用完畢記得關閉port
ser.clode()
最後PySerial有提供一個指令供我們查看有哪些PORT可以使用
$ python -m serial.tools.list_ports
The slot machines out there in} numerous configurations and dimensions befitting the needs of all kinds of consumers. Beautifully 메리트카지노 designed and masterly engineered for enhanced functionality, these gaming machines showcase fast-paced, progressive games to offer players with a heart-pounding slot experience. Slot machine manufacturers craft the machines with numerous sporty and skilled graphics and alluring colors. Shoppers also can discover choices which might be} specifically designed for kids with cute motifs and characters. Most fashionable slot machines are designed to appear and feel just like the old mechanical fashions, however they work on a totally different principle.
回覆刪除