Python:如何知道串口设备事件,如键盘事件

2023-07-23Python开发问题
12

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

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11