0

This is what my devices print out on the terminal while waiting for commands(ser.write)

Image of terminal output

I am writing a simple PYQT5 terminal in python to display information on a terminal from a connected device using Qserial.

The output from the connected device always begins with a time stamp in a similar format which displays every second but on a newline each time thereby flooding the whole Qtextbrowser Terminal.

this makes it difficult to communicate with the device since this line prints every seconds even if I interrupt it with a command, the command executes successfully and hen the time loops continues again. Is there a way to overwrite this loop so that it prints only on the first line all the time without going to next line.

beneath is a snippet from my script. self.Terminal = QTextBrowser()

  def read_serial(self):
    b = bytes(self.serialport.readAll())
    try:
        read_all = b.decode("utf-8")

        try:
            lastline = self.Terminal.toPlainText().split("\n")[-1]

            read_all_nodate = re.sub(r"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}", "", read_all)
            last_line_nodate = re.sub(r"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}", "", lastline)

            if read_all_nodate == last_line_nodate:
                cursor = self.Terminal.textCursor()
                cursor.movePosition(QTextCursor.End)
                cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.KeepAnchor)
                cursor.removeSelectedText()
                self.Terminal.setTextCursor(cursor)

        except:
            pass

        #read_all = read_all.replace("\r", "")
        self.Terminal.moveCursor(QTextCursor.End)
        self.Terminal.insertPlainText(read_all)

    except UnicodeDecodeError:
        read_all = str(b)[2:-1]

Any help will be really appreciated. Thank you.

Using Terminals like Tera Term and Putty solves the problem because these Terminals prints only on the first line each second there is a time loop output from my device without moving to the next line.

This is a terminal display from tera term

  • Can't you just remove the new line from the output of the serial port? `read_all = b.decode("utf-8").rstrip('\n')` – musicamante Dec 03 '21 at 00:14
  • Shall try that one out and give you my feedback. Thanks for the suggestion – user16794957 Dec 03 '21 at 07:32
  • unfortunately, the use of read_all = b.decode("utf-8").rstrip('\n') doesnt solve my problem. Using Terminals like Tera Term and Putty solves the problem because these Terminals prints only on the first line each second there is a time loop output from my device moving to the next line. – user16794957 Dec 03 '21 at 13:21
  • So the new line character is at the beginning of the string? In that case, use the simple `strip()` or `lstrip()`. – musicamante Dec 03 '21 at 13:29

0 Answers0