A Python Serial Terminal To Get You Out Of A Jam

When fiddling around with old computers, you can occasionally find yourself in a sticky situation. What may be a simple task with today’s hardware and software can be nearly impossible given the limited resources available to machines with 20 or 30 years on the clock. That’s where [bison] recently found himself when he needed to configure a device over serial, but didn’t have any way of installing the appropriate terminal emulator on his Fujitsu Lifebook C34S.

His solution, since he had Python 2.6 installed on the Debian 6 machine, was to write his own minimal serial terminal emulator. He intended for the code to be as terse as possible so it could be quickly typed in, should anyone else ever find themselves in need of talking to a serial device on Linux but can’t get screen or minicom installed.

The code is very simple, and even if you never find yourself needing to fire up an impromptu terminal, it offers an interesting example of how straightforward serial communications really are. The code opens up the /dev/ttyS0 device for reading, and after appending the appropriate return character, pushes the user’s keyboard input into it. Keep looping around, and you’ve got yourself an interactive terminal.

With this program written, [bison] was able to connect the 266 MHz C34S to his Retro WiFi SI, a modem adapter that bridges the gap between a vintage computer and modern wireless network. Gadgets like these allow you to browse BBSes as the creator intended, and can be fashioned with nothing more exotic than an ESP8266 running some open source code.

21 thoughts on “A Python Serial Terminal To Get You Out Of A Jam

  1. And how do you configure baudrate, data bits, parity and a lot of small but sometimes critical settings that the tty driver has? It’s not that complicated, but it’s not as simple as this. A few more LoC are needed.

  2. This is a very interesting and straightforward implementation compared to PySerial. A concern I would have that maybe isn’t really an issue because of the age of the devices he’s interacting with, but in Python 3 strings are treated differently and so you’ll potentially have to deal with byte conversion and Unicode if you wanted to do something similar there.

    1. This program is fun for laughs but it will drop characters on your old slowpoke computer if you run it at high speeds, it’s only reading one character at a time from the remote system, even worse it’s converting each character to a string and then running the formatted output function on each character. This is actually a pretty good example of how NOT to do serial communications. Please don’t take lessons from poorly written code. Owen’s comment below is on the money.

  3. I don’t get it. Is the alternate title of this article “Person discovers serial port on old computer”?

    The follow up article will be “Person discovers parallel port on computer”?

      1. I still have a “PLIP” (LapLink(?)) cable!
        But forgot whether it was PLIP4 or PLIP8… :-(
        …need to check that someday.
        Maybe I should send it to a computer museum?

        Nah!
        I still have some oldtimers with parports!
        Just for fun!

        Ok… If I find a double (I’m camera shy!), the “guy rediscovers IP over parport” article can be made… :-P

          1. Oh and I can’t figure out if everybody kept getting ECP and EPP confused or it was just me, because every time I see it, it’s backwards to the last time I saw it.

  4. As mentioned above, there are multiple possible solutions for Debian…

    1. screen (screen /dev/)
    2. Minicom (an open source terminal emulator similar to the old MS-DOS “Telix” program)
    3. kermit and/or wermit
    4. Good old ‘cu’
    5. putty
    6. Good old ‘tip’

    To make matters worse, the code above appears to be line-oriented on the host->serial side while character oriented on the serial->host side and uses two processes to do what should be done with a simple use of select() in a loop.

      1. TFA makes that claim but doesn’t back it up at all. It smells like BS. If Debian was installed, of course you can install new software; the disk is clearly writable so even if apt doesn’t work for some inexplicable reason, at least dpkg -x picocom*.deb would.

Leave a Reply to zoobabCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.