pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

Greets, ye holy.

I've got a device connected to a serial port. I normally use mincom (or hyperterminal) to control it manually. I was on the verge of writing a bunch of expect stuff to control the minicom session when I thought there has to be an easy perl way to talk directly over the serial port without using a terminal program at all.

Sadly, I don't really know where to start. Any ideas?

Update: Sorry, forgot to mention that I'm on Linux.

Thanks!
-Pileofrogs

Replies are listed 'Best First'.
Re: serial console
by Joost (Canon) on Aug 14, 2007 at 22:13 UTC
Re: serial console
by Argel (Prior) on Aug 15, 2007 at 00:04 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: serial console
by spadacciniweb (Curate) on Aug 14, 2007 at 23:35 UTC
Re: serial console
by quester (Vicar) on Aug 15, 2007 at 07:06 UTC
    If talking to your device involves sending a command and waiting for any of several different responses... or a timeout... I would try Expect. It is almost always easier than home-brewing your own logic for figuring out which state the wretched device has wandered into this time. Expect can talk to any program that has a conventional interactive interface. Most people spawn a telnet or ssh session, but you could use Expect to drive minicom. I think that it is also possible to use Expect->exp_init(\*FILEHANDLE) to connect directly to a Linux tty port, but I haven't had a chance to try it.

      I tried that. Apparently, Expect doesn't provide cursor control and that freaks out minicom.

      Does anyone know a way to:

      1. make Expect provide cursor control (or the illusion thereof)
      2. make minicom Ok without cursor control
      3. find an alternative to minicom that doesn't require cursor control (needs to run on linux).

        Actually, it's minicom that would be doing cursor control, by sending the escape sequences for whatever kind of terminal it thinks you are using. You might need to specify a valid terminal type in the environment, $ENV{TERM}="vt100" or "xterm" for instance. Ordinarily you can ignore the escape sequences coming back and look for printable characters that act as prompts. When you send to minicom, you would send exactly the same characters that would be sent by the keys you would press if you started minicom by hand.
Re: serial console
by pileofrogs (Priest) on Sep 06, 2007 at 20:34 UTC

    In the unlikely event that anyone cares:

    I found that setting the correct terminal options with stty, opening /dev/ttyS1, using Expect and getting /r and /n straightened out solved my problems.

    Thanks everyone!