Read Serial Custom Keyboard in Custom GUI

More
20 Aug 2017 22:26 - 20 Aug 2017 22:29 #97797 by developer
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.

Please Log in or Create an account to join the conversation.

More
20 Aug 2017 22:49 #97798 by andypugh
Have you logged the serial stream? perhaps it supplies characters faster than your loop?

Do you _have_ to use that keyboard?

Please Log in or Create an account to join the conversation.

More
21 Aug 2017 04:42 #97806 by developer
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.

Please Log in or Create an account to join the conversation.

Time to create page: 0.120 seconds
Powered by Kunena Forum