Python:如何了解键盘事件等串口设备事件 [英] Python : How to know serial port device events like keybord events

查看:45
本文介绍了Python:如何了解键盘事件等串口设备事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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:如何了解键盘事件等串口设备事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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