我想写一个程序在python读取RS232端口。我的笔记本电脑没有这个端口。有没有人能推荐一个好的模拟器和一个从RS232端口读取数据的python示例程序?
发布于 2014-05-12 14:13:40
我找到解决方案了。我使用了一个虚拟串行端口模拟器来创建虚拟的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)https://stackoverflow.com/questions/23534506
复制相似问题