So here is my problem, I have data from a serial cable being read every 5 seconds and being stored on a CSV file. I am also taking that data and making it into a list. What I would like to do is take variables 5, 7, and 9 and have them be displayed in my GUI where I have Qtextboxes... how do I do that?
The list of variables will be in a value known as listvalues. I want to call 5, 7, and 9 and have them display in their respective text boxes in my PyQt window.
here is my code:
from PyQt4 import QtGui
import sys
import masimo
import csv
import time
import datetime as DT
import threading
from threading import Thread
import serial
import os
os.chdir(r"C:\Users\SpO2\Desktop\Data")
time = time.strftime("%d %b %Y %H%M%S")
location = r'%s.csv' % time
outputfile = open(location, mode='x', newline='')
outputWriter = csv.writer(outputfile)
outputWriter.writerow(["start"])
outputfile.close()
port = "COM4"
class ExampleApp(QtGui.QMainWindow, masimo.Ui_MainWindow):
def __init__(self, parent=None):
super(self.__class__, self).__init__()
self.setupUi(self)
def SerialRead():
delay1 = DT.datetime.now()
ser = serial.Serial(port, baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
out = ser.read(167)
reading = str(out)
plaintext1 = reading.replace(' ', ', ')
plaintext = plaintext1.replace('=', ', ')
listvalue = plaintext.split(", ")
ser.close()
outputfile = open(location, mode='a', newline='')
outputWriter = csv.writer(outputfile)
outputWriter.writerow([plaintext])
outputfile.close()
delay2 = DT.datetime.now()
differencetime = (delay2 - delay1).total_seconds()
writedelay = int(5)
restart = (writedelay - differencetime)
threading.Timer(restart, SerialRead).start()
def main():
app = QtGui.QApplication(sys.argv)
form = ExampleApp()
QtGui.QApplication.processEvents()
form.show()
app.exec_()
if __name__ == '__main__':
Thread(target = SerialRead).start()
Thread(target = main).start()