<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:10pt"><div><div class="yiv1496782098MsoNormal">I have 2 .py programs one main and the other starts serial communication to Arduino and has a function that loops around to process data from Arduino. So I use QProgressBar in the main program to indicate data being processed (takes about 2 minutes). In the second program when it is first called, it will serial connected and then it calls the functions to process data. At the end of data processing, it emits signal back to the main. So far all works fine. But a second and subsequent call to the second program function to re-process data, the QProgressBar does not indicate anymore and it is not even showing 0% to begin with, why? But it does show 100% each time when data processing is completed. Here's my code related to my problem. I research all over stackoverflow and google and tried so
 hard to find a solution.</div><div class="yiv1496782098MsoNormal"> </div><div class="yiv1496782098MsoNormal"><b>Main program.... ..etc...</b></div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def connectDevice(self)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          if self.usb_serial != None:</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">            self.ui.ProgressBar.setMinimum(0)           <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">       </span> # settings for showing pyqt4 progress bar           </div><div class="yiv1496782098MsoNormal" style="margin-bottom:
 0.0001pt;">            self.ui.ProgressBar.setMaximum(0)  <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">              </span> # not indicating as expected         </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">            self.ui.ProgressBar.setValue(0)    <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                        </span> # first showing 0%</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">            self.device = ScopeDev(self.usb_serial)   <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">      </span> # device.py my second Python program</div><div class="yiv1496782098MsoNormal" style="margin-bottom:
 0.0001pt;">            self.device.start()                       <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                      </span> # Connect Call... class ScopeDev/def run(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">            self.device.init_received.connect(self.init_received)     <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">    </span># end of data processing signal received</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          else:</div><div class="yiv1496782098MsoNormal" style="margin-bottom:
 0.0001pt;">            self.Display_MSG("Connection Error", "device not plug into USB port." )</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> def reprocessdata(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          logging.info("Re-Processing Data...")</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.ui.ProgressBar.setMaximum(0)     <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">            </span> # hoping to kick off the progress bar again. Not even showing 0%</div><div class="yiv1496782098MsoNormal" style="margin-bottom:
 0.0001pt;">          self.ui.ProgressBar.setValue(0)       <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                      </span> # I tried insert QApplication.processEvents() here but did not work</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.device.init()                   <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                              </span> # Call class ScopeDev/def init(self): data was being processed</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> def init_received(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom:
 0.0001pt;">          logging.debug("Init received")</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.ui.ProgressBar.setMaximum(1)        <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">            </span> # indicated 100% on both times, when data processing completed</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.ui.ProgressBar.setValue(1)           <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">              </span> # first from connectDevice and second time from reprocessdata</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom:
 0.0001pt;"><b>My second python program... ...etc...</b></div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">class ScopeDev (QtCore.QThread):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          init_received = QtCore.pyqtSignal()</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def __init__(self, usb_serial, usb_serial_baud=9600, timeout=2):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          QtCore.QThread.__init__(self, None)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.serial = serial.Serial(usb_serial,
 usb_serial_baud, timeout=timeout)   <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">      </span># connect to Arduino</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          logging.debug("Connected (%s)" % usb_serial)</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def run(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.init()                   <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                                        </span> #1 Call...def init(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div
 class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">def init(self):</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.serial.readline().rstrip()            <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">          </span># read println put out by Arduino/plaser.ino</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.serial.write(b'init')                   </div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">          self.sread(expect=b'^done_init$')</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;"> </div><div
 class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">  def sread(self, expect=b'^cmd$'):   <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                        </span> # loops around to process data from Arduino...etc. when completed...</div><div class="yiv1496782098MsoNormal" style="margin-bottom: 0.0001pt;">            self.init_received.emit()      <span class="yiv1496782098Apple-tab-span" style="white-space: pre;">                        </span> # emits the outbound signal back to the main program.</div></div></div></body></html>