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

前端 未结 3 1166
面向向阳花
面向向阳花 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:59

    Seems to be badly documented on the PySerial website, this works for me:

    ser = serial.Serial(DEVICE,BAUD,timeout=1)
    if(ser.isOpen() == False):
        ser.open()
    

    A bit of a contrived example, but you get the idea. I know this question was asked a long time ago, but I had the same question today and felt anyone else finding this page would appreciate finding an answer.

提交回复
热议问题