Python PySerial.How 知道一个端口是否已经打开? [英] Python PySerial.How to know if a port is already open?

查看:80
本文介绍了Python PySerial.How 知道一个端口是否已经打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 python 和 PySerial 编写一个在 Linux PC 中使用串行端口的应用程序.但是在这台 PC 中还有其他使用串行端口的应用程序.在尝试使用之前,我如何知道某个端口是否已被其他应用打开?

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 already open by other App before trying to use it?

谢谢

推荐答案

PySerial 网站上的文档似乎很糟糕,这对我有用:

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.

这篇关于Python PySerial.How 知道一个端口是否已经打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆