By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Watching serial port activity.

P: n/a
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

May 30 '06 #1
Share this Question
Share on Google+
15 Replies


P: n/a
On 2006-05-30, xkenneth <xk******@gmail.com> wrote:
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.


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
gr****@visi.com
May 30 '06 #2

P: n/a
I'm using linux.

May 30 '06 #3

P: n/a
On 2006-05-30, xkenneth <xk******@gmail.com> wrote:
I'm using linux.


[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
May 30 '06 #4

P: n/a
Hi,

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

Duane

May 30 '06 #5

P: n/a
Grant Edwards <gr****@visi.com> wrote:
[...]
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.


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 ab***@mooli.org.uk for full key
May 30 '06 #6

P: n/a
On 2006-05-30, TheSeeker <du***********@gmail.com> wrote:
Have you looked into slsnif
(http://www.dakotacom.net/~ymg/software.html)


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!
May 30 '06 #7

P: n/a
On 2006-05-30, Peter Corlett <ab***@dopiaza.cabal.org.uk> wrote:
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.


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
May 30 '06 #8

P: n/a
In article <12*************@corp.supernews.com>,
Grant Edwards <gr****@visi.com> wrote:
On 2006-05-30, xkenneth <xk******@gmail.com> wrote:
I'm using linux.


[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.

May 30 '06 #9

P: n/a
In article <ak************@lairds.us>, I confused matters with:
.
.
.
!? I hadn't realized there's no such monitor ... What do you
think of <URL: http://wiki.tcl.tk/moni >?


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.
May 30 '06 #10

P: n/a
On 2006-05-30, Cameron Laird <cl****@lairds.us> wrote:
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.

.
.
.
!? I hadn't realized there's no such monitor ... What do you
think of <URL: http://wiki.tcl.tk/moni >?


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!!
May 30 '06 #11

P: n/a
xkenneth wrote:
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.


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!

May 30 '06 #12

P: n/a
xkenneth wrote:
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.


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!

May 30 '06 #13

P: n/a
Grant Edwards <gr****@visi.com> writes:
On 2006-05-30, TheSeeker <du***********@gmail.com> wrote:
Have you looked into slsnif
(http://www.dakotacom.net/~ymg/software.html)


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.


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.

May 31 '06 #14

P: n/a
On 2006-05-31, Sergei Organov <os*@javad.com> wrote:
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.


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
May 31 '06 #15

P: n/a
Grant Edwards <gr****@visi.com> writes:
On 2006-05-31, Sergei Organov <os*@javad.com> wrote:
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.
Using strace you can indeed trace read/write calls on user-specified
file descriptors.


I've actually meant to take strace in source code and modify it for
particular purpose. The fact that it almost can do it in unmodified form
is quite impressive though.
Figuring out which file descriptors to trace is the tricky part.


Provided I have port name, say, /dev/ttyM0, and have running application:

osv@osv ~$ fuser /dev/ttyM0
/dev/ttyM0: 5134
osv@osv ~$ ls -l /proc/5134/fd | grep /dev/ttyM0
lrwx------ 1 osv osv 64 2006-05-29 15:33 8 -> /dev/ttyM0
osv@osv ~$

so I need to track fd #8 of the process with pid 5134. Guess one can
attach to a running process as gdb does it.

Alternatively, if the process to be sniffed sporadically opens/closes
the port at run-time, it is required to track open()/close() syscalls as
well as read()/write() ones, I think. Overall, seems not that trivial
but doable.

--
Sergei.

Jun 1 '06 #16

This discussion thread is closed

Replies have been disabled for this discussion.