<分区>
我想用 python 编写一个程序来从 RS 232 端口读取数据。 我的笔记本电脑没有这个端口。 任何人都可以推荐任何好的模拟器和一个从 RS 232 端口读取的示例 python 程序。
<分区>
我想用 python 编写一个程序来从 RS 232 端口读取数据。 我的笔记本电脑没有这个端口。 任何人都可以推荐任何好的模拟器和一个从 RS 232 端口读取的示例 python 程序。
最佳答案
我得到了解决方案。我使用虚拟串行端口模拟器来创建虚拟 2 个端口并将这些端口配对。然后我使用 pyserial python 库读取和写入端口。 从端口读取的示例代码
import time
import serial
# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(
port='COM2',
baudrate=9600,
timeout=1,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS
)
ser.isOpen()
# Reading the data from the serial port. This will be running in an infinite loop.
while 1 :
# get keyboard input
bytesToRead = ser.inWaiting()
data = ser.read(bytesToRead)
time.sleep(1)
print(data)
关于python - 使用python从RS 232端口读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23534506/
相关文章:
python - ./python : error while loading shared libraries: libssl. so.1.1: 无法打开共享对象文件: 没有这样的文件或目录
python - django-rest-framework : restrict RelatedField queryset according to request
python - Flask 运行 request.method 默认为 'POST' 而不是 'GET'
c# - SerialPort.GetPortNames 多次返回同一个端口