Simple serial sniffer

Simple serial sniffer

I needed to see what’s going on my serial port to test some new hardware. Screen isn’t very usable when these values aren’t printable ASCII characters and using hexdump isn’t very practical due to buffering and printing it when whole line accumulates. So I have created this simple piece of code in python: serial_hexsniffer.py.

How it works

It uses python library serial to read byte by byte from selected serial port. All these bytes are printed to stdout in hexadecinal and decadic representation. If the value is between 0x20 (space) and 0x7E it’s printed as ascii character too.

What it needs to run

Linux and python (developed on 2.7)


serial_hexsniffer.py /dev/ttyUSB0 115200

Pri debuggovani ruzneho hardware obcas potrebuji videt, co se deje na seriovem portu. Screen funguje pekne, dokud jsou vsechny znaky tisknutelne ASCII. Hexdump bufferuje a ceka, dokud nemuze vypsat cely radek, takze mi nezbylo, nez si napsat svoje reseni:

Jak to funguje

Cte to ve smycce byte po bytu ze seriaku za pomovi pythonovske knihovny serial. Vsechny vypise na standardni vystup v hexa a dekadicky, pokud je znak navic tisknutelny (0x20-0xFE), vypise i ASCII znak.

Co to potrebuje k behu

Linux a python (vyvinuto na verzi 2.7)


serial_hexsniffer.py /dev/ttyUSB0 115200

Posted by Low Hateria Count in Linux, 0 comments