-1

8 つのチェックボックスを備えた UI があります。どのコマンドがチェックされているかに応じて、telnet に送信するコマンドと返すデータ ファイルを選択するという考え方です。

現在、IFステートメントは8つしかありません。これにより、書き込み時に一部のファイルが混同されます。それを解決するのは、考えられるすべての組み合わせを含むより長い if ステートメントだと思いますが、それは多くの組み合わせです。これらのステートメントが互いに上書きされないようにする簡単な方法はありますか?

コードの一部を次に示します。

        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()
4

1 に答える 1