简体   繁体   English

Python pyserial-如何确定串行端口的数量?

[英]Python pyserial - how can I determine the number of serial ports?

I would like to determine the number of available serial ports, including those provided by USB adapters, under both Linux and windows without having to adapt the program for specific platforms. 我想确定Linux和Windows下可用串行端口的数量,包括USB适配器提供的串行端口,而不必使程序适应特定平台。

I seem to be chasing my tail at the moment and would appreciate another angle on this. 此刻我似乎在追尾,对此我将不胜感激。

Using pyserial is easy enough on either platform for using the ports, but how do you find out how many ports are available? 在任何一个平台上使用pyserial都足够容易使用端口,但是如何找出可用的端口?

Does the example not work for you: 该示例对您不起作用吗?

http://pyserial.svn.sourceforge.net/viewvc/ checkout /pyserial/trunk/pyserial/examples/scan.py http://pyserial.svn.sourceforge.net/viewvc/ 结帐 /pyserial/trunk/pyserial/examples/scan.py

It is a bit brute force (it just tries to connect to every port and ones that throw an exception are ignored as not present). 这有点蛮力(它只是尝试连接到每个端口,并且抛出异常的端口将被忽略(因为不存在))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM