问题描述
我是 python 新手,我能够连接到串行端口设备 &想知道设备中发生了任何变化(如果在设备中按下任何按钮,我想捕捉事件)我该怎么做.在 python 中 pyHook 的帮助下,我能够找到键盘事件和鼠标事件调用函数OnKeyboardEvent" &OnMouseEvent"如何捕获任何串口设备事件.python OnSerailportdeviceEvent函数中有什么东西吗.
Hi i am new to python i am able to connect to the serial port device & want to know any changes are happened in the device (i want catch the event if any button is press in the device) How can i do this.With The help of pyHook in python i am able to find the keyboard events and mouse events with calling the functions "OnKeyboardEvent" & "OnMouseEvent" how to catch the any serial port device events.Is there any thing in python OnSerailportdeviceEvent function.
推荐答案
Python中没有使用串口的内置库,需要使用PySerial 库,然后,你就一行一行地从串口读取数据,看看那一行是否包含数据;如果确实如此,则意味着您的串行设备上发生了某些变化(例如按下按钮).
There is no built-in library for using serial ports in Python, you need to use the PySerial library, and then, you just read data from the serial port line by line and see if that line contains data; if it does it means that something changed on your serial device (a button press, for example).
这里有一些链接可以帮助您使用该库:
Here's a few links that will help you using that library :
官方 PySerial 文档
可能对您有用的博文
StackOverflow 上关于 PySerial 的问题以及一些有用的答案.
这篇关于Python:如何知道串口设备事件,如键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!