- Posts: 9
- Thank you received: 0
Read Serial Custom Keyboard in Custom GUI
9 years 2 months ago #97797
by developer
Read Serial Custom Keyboard in Custom GUI was created 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?
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?
Please Log in to join the conversation.
9 years 2 months ago #97798
by andypugh
Replied by andypugh on 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?
Do you _have_ to use that keyboard?
Please Log in to join the conversation.
9 years 2 months ago #97806
by developer
Replied by developer on 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.
Please Log in to join the conversation.
Time to create page: 0.073 seconds
