user interface - Integrating serial communication in wx GUI -
def updatev(self, event): """""" global v v=random.uniform(1,10) print('battery voltage =') print(v) if v>3: self.labelone.setbackgroundcolour('red') self.labelone.setlabel('battery voltage : ' + str(v)) else: self.labelone.setbackgroundcolour('white') self.labelone.setlabel('battery voltage : ' + str(v)) self.refresh() this function in wxpython gui use generating random values.i have added function in panel class of gui. have put wx.bind function assigns timer value , refreshes regularly value change regularly.
now gui needs have serial communication need sensor values , them input in gui screen. found code serially inputing value:
def updatev(self, event): """""" global v v=ser.readline() print v if v>3: self.labelone.setbackgroundcolour('red') self.labelone.setlabel('battery voltage : ' + str(v)) else: self.labelone.setbackgroundcolour('white') self.labelone.setlabel('battery voltage : ' + str(v)) self.refresh() i went init part of panel class , added code:
ser = serial.serial('com3', 9600, timeout=0) on running gui, value doesnt appear nor print on gui. know doing big mistake here. anyways values right come through arduino uno connected xbee shield receives 1-20 values through arduino conencted xbee shield. way, random variables generated , printed in gui there is'nt proble function. need way python read value serially , assign variable such can print value in gui screen. ps: used same serial code 0 1 2 3 4 5 6 7 8 9 10 value on command screen of python module.
import serial import time ser = serial.serial('com3', 9600, timeout=0) while 1: v=ser.readline() print v time.sleep(1) i trying used python, these small things hinder progress.. new python, please bear me!
your problem reading serial interface in while loop ser.readline() in last example (edit1: , when polling wx.timer event) block gui when waiting data on serial interface. calling the app.mainloop() will loop wxpython event system. however, thing gui example blocking @ ser.readline(). data comes continue in updatev method. because next timer event waiting already, run ser.readline() , block there again , preventing gui updates.
did try out wxterminal example in pyserial package?
it shows how spin of thread reading , sending user-defined serialrxevent thread-safe.
you should read longrunningtasks in wxpython wiki idea how use threads long running/blocking tasks in wxpython , communicate main gui thread safely.
Comments
Post a Comment