I'm trying to write a gui which will continually update values obtained from a data measurement device. Orginally this was accomplished using a TKinter .after loop with a specified refresh time of 500ms.

This snippet of code is called from the mainloop and updates the values once when it is executed. How might I be able to ask the device for the relevant information and then append the fields continually? The time of 500ms isn't crucial, but I would like something that refreshes at leasr every .5 seconds.

def poll(self):
        self.v=(self.lambdasupply.ask("MV?"))
        self.c=(self.lambdasupply.ask("MC?"))
        self.ch1power=(str(self.pm300.ask_for_values(":POW1:VAL?")[0]/1e-3))
        self.ch2power=(str(self.pm300.ask_for_values(":POW2:VAL?")[0]/1e-3))
        self.ophirpower=(self.ophirmeter.ask("$SP?").split('*')[1])

        self.text_voltagevalue = wx.StaticText(self, id=-1, label="%s V" % (self.v), pos=(350,190))
        self.text_currentvalue = wx.StaticText(self, id=-1, label="%s mW" % (self.c), pos=(100,190))
        self.text_onindicatortext = wx.StaticText(self, id=-1, label="%s" % (self.o), pos=(250,160))
        self.text_ch1powervalue = wx.StaticText(self, id=-1, label="%s" % (self.ch1power), pos=(100,130))
        self.text_ch2powervalue = wx.StaticText(self, id=-1, label="%s" % (self.ch2power), pos=(350,130))
        self.text_ophirpowervalue = wx.StaticText(self, id=-1, label="%s" % (self.ophirpower), pos=(100,160))

Awesome! That got it working, it was actually a lot easier than I thought it was going to be...

self.timer = wx.Timer(self)  
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(500) 
        self.Show(True)

    def OnTimer(self, event):
        self.v=(self.lambdasupply.ask("MV?"))
        self.c=(self.lambdasupply.ask("MC?"))
        self.o=(self.onindicator)
        self.l=(self.latchindicator)
        self.tc=(self.targetcurrent)
        self.ch1power=(str(self.pm300.ask_for_values(":POW1:VAL?")[0]/1e-3))
        self.ch2power=(str(self.pm300.ask_for_values(":POW2:VAL?")[0]/1e-3))
        self.ophirpower=(self.ophirmeter.ask("$SP?").split('*')[1])

        self.text_currentsettingvallabel = wx.StaticText(self, id=-1, label="%s" % (self.tc), pos=(350,220))
        self.text_voltagevalue = wx.StaticText(self, id=-1, label="%s V" % (self.v), pos=(350,190))
        self.text_currentvalue = wx.StaticText(self, id=-1, label="%s mW" % (self.c), pos=(100,190))
        self.text_onindicatortext = wx.StaticText(self, id=-1, label="%s" % (self.o), pos=(250,160))
        self.text_ch1powervalue = wx.StaticText(self, id=-1, label="%s" % (self.ch1power), pos=(100,130))
        self.text_ch2powervalue = wx.StaticText(self, id=-1, label="%s" % (self.ch2power), pos=(350,130))
        self.text_ophirpowervalue = wx.StaticText(self, id=-1, label="%s" % (self.ophirpower), pos=(100,160))

Edited 6 Years Ago by Tightmopedman9: n/a

This article has been dead for over six months. Start a new discussion instead.