Python PySerial.How to know if a port is already open?

前端 未结 3 1168
面向向阳花
面向向阳花 2021-02-20 12:54

I\'m trying to write an App that uses serial ports in a Linux PC, using python and PySerial. But in this PC there are other Apps using serial ports. How can I know if a port is

3条回答
  •  野的像风
    2021-02-20 13:49

    Check the return output of Serial.serial, it returns an invalid exception that can be caught

    http://pyserial.sourceforge.net/pyserial_api.html http://pyserial.sourceforge.net/pyserial_api.html#serial.SerialException

    Other than that, if the port is in fact closed when your program attempts to access it, the error thrown is non-fatal and is fairly clear about the reason it failed.

提交回复
热议问题