问题
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