473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

May 30 '06 #1
15 8150
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
I'm using linux.

May 30 '06 #3
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
Hi,

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

Duane

May 30 '06 #5
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
1
by: Dabeule | last post by:
Hello, I would like to make a DOS aplication with VC++ and Win2000 which use the serial port to communicate with another PC. I have downloaded DLPortIO (via port95nt.exe), but I cannot compile...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
4
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. ...
4
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available...
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
4
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.