Read Serial Custom Keyboard in Custom GUI

More
20 Aug 2017 22:26 - 20 Aug 2017 22:29 #97797 by developer
developer created the topic: Read Serial Custom Keyboard in Custom GUI
Hi
I am working on a new custom GUI for linuxcnc that read some input commands from a custom keyboard that connected via a serial to usb port. I'v got a problem when read serial port in an infinite loop (like while True) and that is although the code at first is running correctly, but after a few seconds it is consuming high cpu. My GUI python code in this section is like follow:

def serial_read():
.... ser = serial.Serial('/dev/ttyUSB0', 57600)
.... while True:
........ c = ser.read(20)
........ # process input data by few codes here

thread = threading.Thread(target=serial_read).start()

Any one can help me?
Last Edit: 20 Aug 2017 22:29 by developer.
More
20 Aug 2017 22:49 #97798 by andypugh
andypugh replied the topic: Read Serial Custom Keyboard in Custom GUI
Have you logged the serial stream? perhaps it supplies characters faster than your loop?

Do you _have_ to use that keyboard?
More
21 Aug 2017 04:42 #97806 by developer
developer replied the topic: Read Serial Custom Keyboard in Custom GUI
I actually use a sampling method to get what keys pressed and what is changed. This method works correctly and without any performance problem out of the linuxcnc GUI program. But when called during run of linuxcnc, raises the cpu usage of a related process I determine with name "python" in System Monitor.
Time to create page: 0.060 seconds
Powered by Kunena Forum