日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python串口通讯数据过长_Python 串口通讯

發布時間:2023/12/10 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python串口通讯数据过长_Python 串口通讯 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

摘要:

pyserial module:?https://github.com/tbusf/pyserial

Python使用pyserial進行串口通信:http://blog.csdn.net/log1100/article/details/54380325

串口通訊的python模塊——pySerial?:http://blog.csdn.net/dainiao01/article/details/5885122

Parameters for the Serial class

ser = serial.Serial(

port=None, # number of device, numbering starts at

# zero. if everything fails, the user

# can specify a device string, note

# that this isn't portable anymore

# if no port is specified an unconfigured

# an closed serial port object is created

baudrate=9600, # baud rate

bytesize=EIGHTBITS, # number of databits

parity=PARITY_NONE, # enable parity checking

stopbits=STOPBITS_ONE, # number of stopbits

timeout=None, # set a timeout value, None for waiting forever

xonxoff=0, # enable software flow control

rtscts=0, # enable RTS/CTS flow control

interCharTimeout=None # Inter-character timeout, None to disable

)

Methods of Serial instances

open() # open port

close() # close port immediately

setBaudrate(baudrate) # change baud rate on an open port

inWaiting() # return the number of chars in the receive buffer

read(size=1) # read "size" characters

write(s) # write the string s to the port

flushInput() # flush input buffer, discarding all it's contents

flushOutput() # flush output buffer, abort output

sendBreak() # send break condition

setRTS(level=1) # set RTS line to specified logic level

setDTR(level=1) # set DTR line to specified logic level

getCTS() # return the state of the CTS line

getDSR() # return the state of the DSR line

getRI() # return the state of the RI line

getCD() # return the state of the CD line

Attributes of Serial instancesreadonly

portstr # device name

BAUDRATES # list of valid baudrates

BYTESIZES # list of valid byte sizes

PARITIES # list of valid parities

STOPBITS # list of valid stop bit widths

New values can be assigned to the following attributes, the port will be reconfigured, even if it’s opened at that time:(即使是打開的情況下也會重新配置???liub)

port # port name/number as set by the user

baudrate # current baud rate setting

bytesize # byte size in bits

parity # parity setting

stopbits # stop bit with (1,2)

timeout # timeout setting

xonxoff # if Xon/Xoff flow control is enabled

rtscts # if hardware flow control is enabled

居然還有這么多好東西,看看下面:

TCP/IP – serial bridge

This program opens a TCP/IP port. When a connection is made to that port (e.g. with telnet) it forwards all data to the serial port and vice versa.

This example only exports a raw socket connection. The next example below gives the client much more control over the remote serial port.

The serial port settings are set on the command line when starting the program.

There is no possibility to change settings from remote.

All data is passed through as-is.

打開一個python shell

import serial導入模塊

然后就可以用了

ser = serial.Serial(0) 是打開第一個串口

print ser.portstr 能看到第一個串口的標識,windows下是COM1

ser.write(“hello") 就是往串口里面寫數據

ser.close() 就是關閉ser表示的串口

ser.open() 會打開這個串口

ser = serial.Serial('COM1', 115200) 來設置波特率,當然還有專門的函數

data = ser.read()可以讀一個字符

data = ser.read(20) 是讀20個字符

data = ser.readline() 是讀一行,以/n結束,要是沒有/n就一直讀,阻塞。

data = ser.readlines()和ser.xreadlines()都需要設置超時時間

ser.baudrate = 9600 設置波特率

ser 來查看當前串口的狀態

ser.isOpen() 看看這個串口是否已經被打開

importpyserial

t=serial.Serial()

t.port= 3t.baudrate= 115200t.open()

t.write(chr(0x03)) #向串口輸入ctrl+c

總結

以上是生活随笔為你收集整理的python串口通讯数据过长_Python 串口通讯的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。