Python : How to know serial port device events like keybord events

允我心安 提交于 2019-12-02 00:01:07

问题


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.


回答1:


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 :

Official PySerial documentation

Blog post that may be useful to you

Question on StackOverflow about PySerial with some helpful answers.



来源:https://stackoverflow.com/questions/19152254/python-how-to-know-serial-port-device-events-like-keybord-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!