Grabserial

From eLinux.org
Revision as of 11:54, 31 October 2008 by Tim Bird (talk | contribs) (add grabserial page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

grabserial - grab the serial port output

Introduction

grabserial is a small program which reads a serial port and writes the data to standard output. The main purpose of this tool is to collect messages written to the serial console from a target board running Linux, and save the messages on a host machine.

Download and Installation

Download grabserial from here: Media:grabserial

Grabserial requires the python "serial" module. This module is not shipped with most distributions of python by default. Here's a copy you can install if you don't have it. (You can check if you already have it by typing: 'python', then "import serial" in the interactive python interpreter.

Media:pyserial-2.2.zip

To install this, download the archive, unzip it, and following the installation instructions in pyserial-2.2/README.txt.

The latest Pyserial can be obtained from: [1] The latest version as of this writing is 2.4, which is newer than what I've got here.


Instructions

The grabserial program is very simple, but it provides some useful extra features. Normally, the program will run in an infinite loop, reading from the serial port and writing to standard out until it is interrupted by the user (usually by typing control-C). However, you can tell the program to stop after a certain amount of time. This is useful for including the script in automated test scenarios.

Also, you can tell the program to provide timing information for each line received. This is useful to measure the time it takes for events to happen on the target. One of the more common things to measure on a target is bootup time. With grabserial, you can specify a pattern to match against the lines read from the serial port. When this pattern is seen, it sets a "base time", and all subsequent time values printed out will be relative to this base. Thus, you can customize the start time for the time measurements, to make it easier to see the duration of events in the system.

The online usage of the program is available using 'grabserial -h' The serial configuration options, including the specific Linux serial port device to use, and the port speed settings, can all be specified on the grabserial command line.

Usage Examples

Here are some examples of use:

grabserial

This will echo data seen on device /dev/ttyS0, until the user pressed ctrl-C.

grabserial -v -d "/dev/ttyUSB0" -b 115200 -w 8 -p N -s 1 -e 30 -t -m "Kernel start" 

This opens /dev/ttyUSB0, at baud rate 115200, and 8-bit chars, No parity and 1 stop bit. This will capture and display data for 30 seconds, putting a timestamp on each line received, and restarting the timestamp at 0 when a line containing "Kernel start" is seen. The '-v' makes grabserial verbose (printing some extra messages before starting.

Sample Output

Here is sample output from grabserial