Python pyserial - 如何确定串行端口的数量?
我想确定 Linux 和 Windows 下可用串行端口的数量,包括 USB 适配器提供的端口数量,而无需针对特定平台调整程序。
我现在似乎在追我的尾巴,希望能从另一个角度来看待这个问题。
在任一平台上使用 pyserial 都很容易使用端口,但如何找出有多少端口可用?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该示例不适合您:
http://pyserial.svn.sourceforge.net/viewvc/checkout/pyserial/trunk/pyserial/examples/scan.py
这有点暴力(它只是尝试连接到每个端口,并且抛出异常的端口被忽略为不存在)。
Does the example not work for you:
http://pyserial.svn.sourceforge.net/viewvc/checkout/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).