Python serial - Attempting to use a port that is not open

十年热恋 提交于 2019-12-05 10:53:41

The first part of your code is wrong, you're making the wrong attributions for ser. Try the following way:

ser = serial.Serial(
port = "/dev/ttyUSB2",
baudrate = 115200,
bytesize = serial.EIGHTBITS, 
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE, 
timeout = 1,
xonxoff = False,
rtscts = False,
dsrdtr = False,
writeTimeout = 2
)

On my environment, the port was already open after that, but if it isn't you can try to open it:

ser.open()
ser.isOpen()

And you have to be sure that this is not a virtual port on your pc if it is, you will have to change this:

ser.rtscts = False  #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False  #disable hardware (DSR/DTR) flow control

For this:

ser.rtscts = True
ser.dsrdtr = True

Check out this issue for more info

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!