The GUI connects with any port that is found, even if it's not the correct teensy port. For debugging, the teensy is used in dual-serial mode. Only one can be used for bidirectional communication. A handshake with the teensy should fix this issue.
The handshake implementation was a bit difficult, due to confusion decoding.
The handling is done in the GUI.
Readings from the serial bus are represented as bytearrays, which have to be decoded with
ans = answer.decode('utf-8') .
This returns a string, which is shown by print(ans). The teensy is configured to send the string "tconn" upon request, which I double checked is the case.
But the comparison of ans == "tconn" didn't work, even if print(ans) returned the correct string.
After some troubleshooting, I found the solution. The repr(ans) function returns the exact representation of the string. And apparently, the string contained a newline character, which should've been removed after reading. Naturally "tconn\n" == "tconn" returned false every time.
The issue was fixed in the readline function of the special linereader class. It returns the first value in a buffer which is separated by a newline character. The linereader looks for the next index i where "\n" is located in the buffer and returns all characters by accessing
r = buffer[:i+1] (representing "tconn\n") .
removing the "+1" solved the problem.
This fix is stored in a separate branch "BugFix_Handshake"