Watching serial port activity.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xkenneth

    Watching serial port activity.

    Hi,

    I'm writing a couple python applications that use the serial port
    (RS-232) quite extensively. Is there any way I can monitor all activity
    on the serial port and have it printed as the transactions occur? I'm
    trying to reverse engineer a microcontroller serial routine and I'd
    like to see any response the chip sends back.

    Regards,
    Ken

  • Grant Edwards

    #2
    Re: Watching serial port activity.

    On 2006-05-30, xkenneth <xkenneth@gmail .com> wrote:
    [color=blue]
    > I'm writing a couple python applications that use the serial port
    > (RS-232) quite extensively. Is there any way I can monitor all activity
    > on the serial port and have it printed as the transactions occur? I'm
    > trying to reverse engineer a microcontroller serial routine and I'd
    > like to see any response the chip sends back.[/color]

    What OS?

    Under windows you can use portmon from sysinternals.

    I don't think there's anything for Linux.

    I've noclue about OS X.

    --
    Grant Edwards
    grante@visi.com

    Comment

    • xkenneth

      #3
      Re: Watching serial port activity.

      I'm using linux.

      Comment

      • Grant Edwards

        #4
        Re: Watching serial port activity.

        On 2006-05-30, xkenneth <xkenneth@gmail .com> wrote:
        [color=blue]
        > I'm using linux.[/color]

        [It's generally considered good practice to quote enough context
        so that your post makes sense to people without access to older
        postings.]

        Under Linux there isn't really anything. IIRC, many years ago,
        somebody had written a kernel module that inserted itself
        between application and serial port and logged operations, but
        the last time I tried to find it, I was unsuccessful.

        If you feel like building a kernel, adding a few printk() calls
        to either the low-level serial driver or the tty
        line-discipline layer might do what you want.

        --
        Grant Edwards grante Yow! YOW!! Everybody out
        at of the GENETIC POOL!
        visi.com

        Comment

        • TheSeeker

          #5
          Re: Watching serial port activity.

          Hi,

          Have you looked into slsnif
          (http://www.dakotacom.net/~ymg/software.html)

          Duane

          Comment

          • Peter Corlett

            #6
            Re: Watching serial port activity.

            Grant Edwards <grante@visi.co m> wrote:
            [...][color=blue]
            > Under Linux there isn't really anything. IIRC, many years ago, somebody
            > had written a kernel module that inserted itself between application and
            > serial port and logged operations, but the last time I tried to find it, I
            > was unsuccessful.[/color]

            A dirty hack that might work is to rename /dev/ttyS* off somewhere else and
            replace them with named pipes. Have a process monitor the named pipes and
            relay data back and forth to the actual serial ports while logging it. The
            serial ioctls won't work to the named pipe, but the application might not
            notice it failed.

            But this is probably way too advanced for the OP.

            --
            PGP key ID E85DC776 - finger abuse@mooli.org .uk for full key

            Comment

            • Grant Edwards

              #7
              Re: Watching serial port activity.

              On 2006-05-30, TheSeeker <duane.kaufman@ gmail.com> wrote:
              [color=blue]
              > Have you looked into slsnif
              > (http://www.dakotacom.net/~ymg/software.html)[/color]

              FYI, slsnif won't work for any serial program that needs to use
              parity, 7 data bits, or any of the modem control/status lines.

              Since all of the serial applications I use need to use actual
              serial ports, I've never found slsnif to be useful. It's
              really a shame that pty devices don't support the same set of
              ioctl calls that tty devices do.

              --
              Grant Edwards grante Yow! World War Three can
              at be averted by adherence
              visi.com to a strictly enforced
              dress code!

              Comment

              • Grant Edwards

                #8
                Re: Watching serial port activity.

                On 2006-05-30, Peter Corlett <abuse@dopiaza. cabal.org.uk> wrote:
                [color=blue]
                > A dirty hack that might work is to rename /dev/ttyS* off somewhere else and
                > replace them with named pipes. Have a process monitor the named pipes and
                > relay data back and forth to the actual serial ports while logging it. The
                > serial ioctls won't work to the named pipe, but the application might not
                > notice it failed.[/color]

                If so, then that would be one pretty crappy application. ;)

                The slsnif program uses a pty so it will support at least some
                of the ioctl calls that a serial port does.

                --
                Grant Edwards grante Yow! Yow! Is my fallout
                at shelter termite proof?
                visi.com

                Comment

                • Cameron Laird

                  #9
                  Re: Watching serial port activity.

                  In article <127oj612scnl8a 0@corp.supernew s.com>,
                  Grant Edwards <grante@visi.co m> wrote:[color=blue]
                  >On 2006-05-30, xkenneth <xkenneth@gmail .com> wrote:
                  >[color=green]
                  >> I'm using linux.[/color]
                  >
                  >[It's generally considered good practice to quote enough context
                  >so that your post makes sense to people without access to older
                  >postings.]
                  >
                  >Under Linux there isn't really anything. IIRC, many years ago,
                  >somebody had written a kernel module that inserted itself
                  >between application and serial port and logged operations, but
                  >the last time I tried to find it, I was unsuccessful.
                  >
                  >If you feel like building a kernel, adding a few printk() calls
                  >to either the low-level serial driver or the tty
                  >line-discipline layer might do what you want.[/color]

                  Comment

                  • Cameron Laird

                    #10
                    Re: Watching serial port activity.

                    In article <akauk3-l2l.ln1@lairds. us>, I confused matters with:[color=blue]
                    > .
                    > .
                    > .
                    >!? I hadn't realized there's no such monitor ... What do you
                    >think of <URL: http://wiki.tcl.tk/moni >?[/color]

                    Ugh. Please ignore, all; this was a first draft of
                    what was intended for private e-mail. It escaped
                    the corral through a mistake. I apologize for the
                    distraction.

                    Comment

                    • Grant Edwards

                      #11
                      Re: Watching serial port activity.

                      On 2006-05-30, Cameron Laird <claird@lairds. us> wrote:
                      [color=blue][color=green]
                      >>If you feel like building a kernel, adding a few printk() calls
                      >>to either the low-level serial driver or the tty
                      >>line-discipline layer might do what you want.[/color]
                      > .
                      > .
                      > .
                      > !? I hadn't realized there's no such monitor ... What do you
                      > think of <URL: http://wiki.tcl.tk/moni >?[/color]

                      It's yet another a terminal program (written in TCL).

                      _If_ the pty device didn't force parity=None and bits=8, and
                      _if_ it implemented the modem control/status ioctl() calls, and
                      _if_ it went through the line discipline layer like a real
                      serial port does, then something like slsnif would be workable
                      for "real" serial port applications.

                      In a more general sense, it would mean you could actually
                      simulate a serial port with user-space code. That allows you
                      to do cool stuff like create virtual serial ports in user-space
                      that are connected via Ethernet to physical (or virtual) serial
                      ports on other hosts. [OK, I admit there are only a few of us
                      who think that's a cool thing to do.]

                      Currently, if you want to create a virtual serial port under
                      Linux you have to write a kernel-mode device driver. The only
                      practical way to do that is to write a virtual "low level"
                      serial driver that uses the line-discipline layer in the normal
                      manner. And that's a real bitch to maintain because the API
                      between the line-discipline layer and the driver you've just
                      written is constantly changing (it seems to get major overhauls
                      even between minor versions of a "stable" kernel).

                      Someday I'll write a pty driver that actually allows simulation
                      of a serial port...

                      --
                      Grant Edwards grante Yow! .. My pants just went
                      at on a wild rampage through a
                      visi.com Long Island Bowling Alley!!

                      Comment

                      • nikie

                        #12
                        Re: Watching serial port activity.

                        xkenneth wrote:
                        [color=blue]
                        > Hi,
                        >
                        > I'm writing a couple python applications that use the serial port
                        > (RS-232) quite extensively. Is there any way I can monitor all activity
                        > on the serial port and have it printed as the transactions occur? I'm
                        > trying to reverse engineer a microcontroller serial routine and I'd
                        > like to see any response the chip sends back.[/color]

                        I've done similar things in the past, and the best tools I found at
                        that time were:
                        - Serial Port sniffer from www.hhdsoftware.com
                        Similar to portmon, but (in my experience) more stable. Windows only,
                        though.
                        - VMWare
                        You can run your serial port app in a VMWare and connect the virtual
                        serial port to a file or named pipe on the host system. But this won't
                        help you if the app uses serial commands not available for files/pipes.
                        - Hardware cable
                        If you know how to use a soldering iron, this might be the best way: a
                        serial cable has an RX and a TX wire, connect each of them to the RX
                        wires of two separate serial cables, that way you can "wiretap" the
                        whole communication to two different serial ports (e.g. on your laptop)
                        in a running system. Dead useful for debugging!

                        Comment

                        • nikie

                          #13
                          Re: Watching serial port activity.

                          xkenneth wrote:
                          [color=blue]
                          > Hi,
                          >
                          > I'm writing a couple python applications that use the serial port
                          > (RS-232) quite extensively. Is there any way I can monitor all activity
                          > on the serial port and have it printed as the transactions occur? I'm
                          > trying to reverse engineer a microcontroller serial routine and I'd
                          > like to see any response the chip sends back.[/color]

                          I've done similar things in the past, and the best tools I found at
                          that time were:
                          - Serial Port sniffer from www.hhdsoftware.com
                          Similar to portmon, but (in my experience) more stable. Windows only,
                          though.
                          - VMWare
                          You can run your serial port app in a VMWare and connect the virtual
                          serial port to a file or named pipe on the host system. But this won't
                          help you if the app uses serial commands not available for files/pipes.
                          - Hardware cable
                          If you know how to use a soldering iron, this might be the best way: a
                          serial cable has an RX and a TX wire, connect each of them to the RX
                          wires of two separate serial cables, that way you can "wiretap" the
                          whole communication to two different serial ports (e.g. on your laptop)
                          in a running system. Dead useful for debugging!

                          Comment

                          • Sergei Organov

                            #14
                            Re: Watching serial port activity.

                            Grant Edwards <grante@visi.co m> writes:
                            [color=blue]
                            > On 2006-05-30, TheSeeker <duane.kaufman@ gmail.com> wrote:
                            >[color=green]
                            >> Have you looked into slsnif
                            >> (http://www.dakotacom.net/~ymg/software.html)[/color]
                            >
                            > FYI, slsnif won't work for any serial program that needs to use
                            > parity, 7 data bits, or any of the modem control/status lines.
                            >
                            > Since all of the serial applications I use need to use actual
                            > serial ports, I've never found slsnif to be useful. It's
                            > really a shame that pty devices don't support the same set of
                            > ioctl calls that tty devices do.[/color]

                            It seems that sniff on a real tty device could be implemented using the
                            same technique strace uses to intercept and show syscalls, though I'm
                            not aware of any sniffer application that does it.

                            --
                            Sergei.

                            Comment

                            • Grant Edwards

                              #15
                              Re: Watching serial port activity.

                              On 2006-05-31, Sergei Organov <osv@javad.co m> wrote:
                              [color=blue]
                              > It seems that sniff on a real tty device could be implemented using the
                              > same technique strace uses to intercept and show syscalls, though I'm
                              > not aware of any sniffer application that does it.[/color]

                              Using strace you can indeed trace read/write calls on
                              user-specified file descriptors. Figuring out which file
                              descriptors to trace is the tricky part.

                              --
                              Grant Edwards grante Yow! I was making donuts
                              at and now I'm on a bus!
                              visi.com

                              Comment

                              Working...