OBDII data pass to wxpython staticText continues update issues(raspberry PI2) -
i total beginner in programming. start small project using raspberry pi connect car obd port , reading data wxpython gui. obd library using http://brendan-w.com/work/python-obd using instruction above, successful print living rpm data in python shell line line. code here:
import obd import time connection = obd.async("/dev/rfcomm0") # same constructor 'obd.obd()' cmd = obd.commands.rpm connection.watch(cmd) # keep track of rpm connection.start() # start async update loop while(true): response_rpm = connection.query(cmd).value print(response_rpm) # non-blocking, returns time.sleep(0.01) #obd.debug.console = true
after this, created gui using wxformbuilder , change wxpython code. test gui wxpython code in raspberry pi no problem. after add obd library code and, whole frame not working thing want using statictext.setlabel() display living data in while loop. code after add obd library here :http://pastebin.com/4hyxn4cv after running in raspberry pi got gray frame , nothing work
the problem blocking gui sleep
statement in tight while(true)
loop. polling sensor in fixed time intervals.
the smart way poll in wxpython
using timer (wx.timer
). can let call content of while
loop (do not call more 20 times per second, more useless , clog event loop). sleep
has removed, because eating unscheduled time , blocking gui.
python-odb ansynchronuous (see, second example), solution above requires least restructuring of program.
Comments
Post a Comment