简体   繁体   English

强制从pyserial释放串口

[英]Forcing serial port release from pyserial

When my application crashes, some of the serial ports apparently remain locked and I have no choice but to reboot the Raspberry Pi.当我的应用程序崩溃时,某些串行端口显然保持锁定状态,我别无选择,只能重新启动 Raspberry Pi。

I was wondering if there is a way to ensure that, before crashing, the ports are released.我想知道是否有办法确保在崩溃之前释放端口。 Another alternative would be to create a function that forces the release of a certain port when my code starts.另一种选择是创建一个 function,它在我的代码启动时强制释放某个端口。

Is there such a thing within pyserial , or another Python library? pyserial或另一个 Python 库中是否有这样的东西?

You have the command top to list all applications that are running.您可以使用命令top列出所有正在运行的应用程序。

You can retrieve your PID of the instance of your application and terminate it with the command kill -9 YOUR_PID .您可以检索应用程序实例的 PID 并使用命令kill -9 YOUR_PID终止它。

Killing the app will free your serial port.杀死该应用程序将释放您的串行端口。

Else you can open your serial port with exclusive to False : https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial否则你可以用False exclusive打开你的串口: https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial

A port cannot be opened in exclusive access mode if it is already open in exclusive access mode.如果端口已经以独占访问模式打开,则不能以独占访问模式打开。

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

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