I have a UI with 8 checkboxes. The idea is that depending on which ones are checked, it will choose what commands to send to telnet and what data files to return.
Currently I just have 8 IF statements. This is causing some of the files to be mixed up when they are written. I think what would solve it is a longer if statement that contains every possible combo, but that is a lot of combinations. Is there a simple way so these statements dont overwrite each other?
Here is some of the code:
if self.EHbox.isChecked():
tn.write("geh,".encode('ascii') + TS2Dur.encode() + b"\n\r")
out_file = open(self.linePATH.text() + date + "_001.csv", "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.AHbox.isChecked():
tn.write("DAT,".encode('ascii') + TS2Dur.encode() + b"\n\r")
out_file = open(self.linePATH.text() + date + "_001.csv", "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.DHbox.isChecked():
tn.write("GDH,".encode('ascii') + TS2Dur.encode() + b"\n\r")
out_file = open(self.linePATH.text() + date + "_001.csv", "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.L1box.isChecked():
tn.write("gl1,".encode('ascii') + TS2Dur.encode() + b"\n\r")
out_file = open(self.linePATH.text() + date + "_001.csv", "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.L2box.isChecked():
tn.write("gl2,".encode('ascii') + TS2Dur.encode() + b"\n\r")
out_file = open(self.linePATH.text() + date + "_001.csv", "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.CMbox.isChecked():
tn.write("gsf,0".encode('ascii') + b"\n\r")
out_file = open(self.linePATH.text(), "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.CNbox.isChecked():
tn.write("gsf,1".encode('ascii') + b"\n\r")
out_file = open(self.linePATH.text(), "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()
if self.FLbox.isChecked():
tn.write("gsf,2".encode('ascii') + b"\n\r")
out_file = open(self.linePATH.text(), "wt")
out_file.write(tn.read_until(b"EOF").replace(b'\r\n',b'\n').replace(b'ACK',b'').replace(b'EOF',b'').strip().decode())
out_file.close()