Simple protocol analyzer?

I have a need to read in lines of text from a serial port onto a PC, and timestamp them.

I just need one timestamp per line, preferably for the leading character but I could collect data OK by getting the timestamp of the linefeed.

I'm hoping that someone has already written some sort of a simple protocol analyzer that does this.

Open source is a plus. Something that's already available for installation in Ubunto is a double-plus. I could make things work with Windows (ick).

I'm reading in numbers from an instrument which does not always sample at a consistent speed. Ideally what I would end up with would be a text file that goes

cr lf cr lf

etc.

(The end goal is to record this text file, read it into Scilab and analyze the bejeezus out of it).

Any suggestions?

--
Tim Wescott 
Wescott Design Services 
 Click to see the full signature
Reply to
Tim Wescott
Loading thread data ...

formatting link

--
Grant Edwards               grant.b.edwards        Yow! Hmmm ... A hash-singer 
                                  at               and a cross-eyed guy were 
 Click to see the full signature
Reply to
Grant Edwards

Grant, that's about as perfect as a command-line utility can get. It does just what I want, and the command-line clunkiness doesn't intrude too badly. It's going to save me tons of time over having to write something.

--
Tim Wescott 
Wescott Design Services 
 Click to see the full signature
Reply to
Tim Wescott

Well, it'll save you a few minutes over having to write something

;)

#!/usr/bin/python import serial,time p = serial.Serial('/dev/ttyS1', 9600) while 1: line = p.readline() print time.time(),line

In that version, the timestamp is associated with the end of the line. If you want the timestamp for the start of the line, it's a bit more complicated:

#!/usr/bin/python import serial,time p = serial.Serial('/dev/ttyS1', 9600) while 1: first = p.read(1) stamp = time.time() rest = p.readline() print stamp, first+rest

--
Grant Edwards               grant.b.edwards        Yow! Should I get locked 
                                  at               in the PRINCICAL'S 
 Click to see the full signature
Reply to
Grant Edwards

If I were to write it in python I'd first have to learn python, though.

This is better.

--
Tim Wescott 
Wescott Design Services 
 Click to see the full signature
Reply to
Tim Wescott

Does Python's serial object put the line into raw mode so you can get the first character before the linefeed is sent? or did you miss that? Just curious, not nit-picking.

Reply to
Clifford Heath

In the long term learning Python will save you much time. And you'll find examples for almost anything, because many people are using it.

One of my retro-computing examples, using binary file read/write and WAV file reading:

formatting link

Or think of automated test equipment. Buy a Raspberry Pi and download the Python library for direct IO pin access for it, and use PyGame (not just for games, good if you need to draw a lot) or Tkinter (good if you have standard text fields, buttons etc.) to show something on the HDMI output.

--
Frank Buss, http://www.frank-buss.de 
electronics and more: http://www.youtube.com/user/frankbuss
Reply to
Frank Buss

In the long run, you are better off with at least one scripting language. Python has good market share now; might as well be it.

I think there's a problem or two with Python that Tcl does not have*, but anything is better than nothing.

*they are all a compromise, and I am biased.
--
Les Cargill
Reply to
Les Cargill

True.

Python is awfully handing for banging together little tools to do testing on embedded systems that have either serial or ethernet ports. If you have to do that sort of stuff, learning Python might be worth it (it's pretty easy to learn).

--
Grant Edwards               grant.b.edwards        Yow! Now we can become 
                                  at               alcoholics! 
 Click to see the full signature
Reply to
Grant Edwards

Yes. The port defaults to raw mode (8,none,1). The author of pyserial is an embedded systems developer who (I believe) wrote it to support a set of tools used for downloading/testing/debugging microcontroller-based widgets that had serial ports. Since that's mainly what I use it for, I find pyserial pretty much always defaults to doing the "right" thing.

What it doesn't do is deal with the UARTs RX FIFO threshold setting or the Linux tty layer's low_latency flag. If you're using a UART with a large FIFO (e.g. 128 bytes), the incoming lines of text are short, don't have significant gaps between them, and you care about millisecond accuracy, then you'll need to go to some extra work to select a low rx FIFO threshold and set the low-latency flag on the device using something like the setserial utility (or the underlying ioctl() call that it uses).

--
Grant Edwards               grant.b.edwards        Yow! DIDI ... is that a 
                                  at               MARTIAN name, or, are we 
 Click to see the full signature
Reply to
Grant Edwards

I forgot to post a link to the pyserial project:

formatting link

Pyserial isn't part of the Python standard library, but I think most Linux distros have a package for it -- even if they don't, installing only requires a couple commands.

--
Grant Edwards               grant.b.edwards        Yow! PARDON me, am I 
                                  at               speaking ENGLISH? 
 Click to see the full signature
Reply to
Grant Edwards

Right, nice.

I've done that at the C level (CMIN, CTIME, etc). Even got the developer to fix a driver bug I found in the low_latency implementation. Seems like a lifetime ago.

My scripting language of choice is Ruby, but it's been a long time since I did any serial port things with it, and I think for someone choosing a scripting language to support embedded work, Python is probably better because it has more users in that community.

One technique I've used in serial port work is to use separate threads for input and output. You have to synchronise, but it's nicer than using select().

Clifford Heath

Reply to
Clifford Heath

I'm a fan of Forth. It is a general purpose language with nice debugging features. The learning curve is not so much the language as the philosophy. It is really very nice and highly interactive which is a big advantage when doing something like a script.

--

Rick
Reply to
rickman

Python is interactive too, or can be (ipython).

Quite a nice environment for data manipulation, plotting etc.

--

John Devereux
Reply to
John Devereux

Python is brilliant for doing data analysis and visualization, and there is a large scientific/engineering computing community. Back when I did things like curve fitting and surface triangulation for calibrating various sorts of sensors, I used Scientific Python and SciPy (two different, somewhat competing, libraries). I higly recommend both:

formatting link
formatting link

FWIW, I found gnuplot-py to be easier to use for sophisticated plots than matplotlib, but that's probably just because I already had 15 years experience using gnuplot:

formatting link
formatting link

If you want everything all bundered together, Enthought provides Python distributions bundled with a pretty complete set of scientific and data visualization libraries:

formatting link

I haven't used it for a couple years, but it's especially nice if you have to make something work on Windows. [If you're using a decent Linux distro, then there should already be native packages for most of what's included in Enthought's distribution.]

--
Grant Edwards               grant.b.edwards        Yow! I KAISER ROLL?! 
                                  at               What good is a Kaiser Roll 
 Click to see the full signature
Reply to
Grant Edwards

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.