我想用Python编写一个读取RS 232端口的程序,但我的笔记本电脑没有这个接口。
请问有没有好的仿真器可以使用,并提供一个从RS 232端口读取数据的Python示例程序。
我想用Python编写一个读取RS 232端口的程序,但我的笔记本电脑没有这个接口。
请问有没有好的仿真器可以使用,并提供一个从RS 232端口读取数据的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)