Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Option | Description
`-o, --output=VALUE` | Output file prefix (defalut port name)
`--pipe` | Use named pipe instead of file
`-h, --help` | Show this message and exit
`-s, --stdout` | Use stdout instead of file

`portName` is `COM1`, `\\.\COM15` or `/dev/ttyUSB0` or similar definition.

Expand All @@ -37,3 +38,10 @@ It is possible to run the application in pipe mode, so you can see realtime traf
mono SerialPcap -o /tmp/wspipe --pipe [options] <portName>

More info on Wireshark capture pipes can be seen on https://wiki.wireshark.org/CaptureSetup/Pipes


Using stdout (realtime) mode in both Windows and Linux
-----------
Another useful option to see realtime traffic in Wireshark is to use stdout piping:

SerialPcap -s <portName> | wireshark -k -i -
55 changes: 34 additions & 21 deletions SerialPCAP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ class MainClass
static char parity = 'n';
static int stopbits = 1;
static bool pipe = false;
static bool stdout = false;

static void ShowHelp(OptionSet options)
{
Console.WriteLine("{0} v{1}", AssemblyExtensions.Description(), AssemblyExtensions.Version());
Console.WriteLine("usage: serialpcap [options] <portName>");
options.WriteOptionDescriptions(Console.Out);
Console.WriteLine();
Console.WriteLine("Available portName:");
// Get a list of serial port names.
string[] ports = SerialPort.GetPortNames();
// Display each port name to the console.
Console.WriteLine("Available portName:");
// Get a list of serial port names.
string[] ports = SerialPort.GetPortNames();
// Display each port name to the console.
foreach (string port in ports)
{
Console.WriteLine(" " + port);
Expand All @@ -51,27 +52,37 @@ static void Capture(CaptureSerial capture, BinaryWriter writer)

static void RunCapture()
{
Console.WriteLine("Serial port: " + portName);
Console.WriteLine("Baud rate: " + baudRate + " Bd");
Console.WriteLine("Parity: " + parity);
Console.WriteLine("Stopbits: " + stopbits);
Console.WriteLine("Frame gap: " + frameGapMs + " ms");
Console.WriteLine("DLT: " + dlt);
Console.WriteLine("Output file: " + outputFile);
Console.WriteLine();
Console.WriteLine("Starting capture (press Ctrl+c to stop)");

if (stdout == false)
{
Console.WriteLine("Serial port: " + portName);
Console.WriteLine("Baud rate: " + baudRate + " Bd");
Console.WriteLine("Parity: " + parity);
Console.WriteLine("Stopbits: " + stopbits);
Console.WriteLine("Frame gap: " + frameGapMs + " ms");
Console.WriteLine("DLT: " + dlt);
Console.WriteLine("Output file: " + outputFile);
Console.WriteLine();
Console.WriteLine("Starting capture (press Ctrl+c to stop)");
}

using (var capture = new CaptureSerial(portName, baudRate, parity, stopbits, frameGapMs))
{
if (pipe && Environment.OSVersion.Platform != PlatformID.Unix)
if (stdout)
{
using (BinaryWriter writer = new BinaryWriter(Console.OpenStandardOutput()))
{
Capture(capture, writer);
}
}
else if (pipe && Environment.OSVersion.Platform != PlatformID.Unix)
{
using (BinaryWriter writer = new BinaryWriter(new NamedPipeServerStream(outputFile, PipeDirection.Out)))
{
Capture(capture, writer);
}
}
else {
else
{
using (BinaryWriter writer = new BinaryWriter(File.Open(outputFile, FileMode.Create)))
{
Capture(capture, writer);
Expand All @@ -94,17 +105,18 @@ public static void Main(string[] args)
{"o|output=", "Output file prefix or pipe (defalut port name)", o => outputFilePrefix = o},
{"pipe", "Use named pipe instead of file", p => pipe = p != null},
{"h|help", "Show this message and exit", h => shouldShowHelp = h != null},
{"s|stdout", "Use stdout instead of file", s => stdout = s != null},
};

List<string> extra;
try
{
// parse the command line
{
// parse the command line
extra = options.Parse(args);
}
catch (OptionException e)
{
// output some error message
{
// output some error message
Console.Write("serialpcap: ");
Console.WriteLine(e.Message);
Console.WriteLine("Try `serialpcap --help' for more information.");
Expand All @@ -127,7 +139,8 @@ public static void Main(string[] args)
}
outputFile = outputFilePrefix;
}
else {
else
{
if (outputFilePrefix == "")
{
var s = portName.Split(new char[] { '/', '\\' });
Expand Down