Windows COM port I/O from command line
[page last modified 4/28/2017]

Tiny (6k) tool to play around with reading and writing a Windows COM port from the command line.  I wrote this to talk to an X10 CM11A (yes... stone age X-10) via a USB<->serial dongle.  The serial I/O capability is limited but sufficed for the experimenting I wished to do with the CM11A.

I needed display of incoming serial data in hex; also output of hex data to the COM port at the command line.  To test the initial version's code I enabled re-routing to stdin/stdout instead of a COM port -- that's when things got interesting and how I'll likely use it most.

Read examples:

   C>echo hello | phcom -c -b r
   68 65 6c 6c 6f 20 d a 

   C>echo hello | phcom -c -b2 r
   1101000 1100101 1101100 1101100 1101111 100000 1101 1010 
You can limit the number of bytes displayed via the -s switch.

Write examples:

   C>phcom -c w 68 65 6c 6c 6f 20 d a

   C>phcom -c w -r10 'ab'
The -r option is a 64-bit value, so you can write (quickly) 10 terabytes to your hard disk via:
   C>phcom -c w -r10000000000 ff >10tb.bin
The -r applies to the following argument only, but that argument can hold multiple values if enclosed in quotes:
   C>phcom -c w -r2 "31 'hello' 32" 20'lastarg'
   1hello21hello2 lastarg
An argument can be a filename in double quotes (empty for stdin).
   C>echo hello|phcom -c w 'start' \"\" 'end'

   C>echo hello >foo.txt
   C>phcom -c w 'start' \"foo.txt\" 'end'

Source is included.  It can be built 32 or 64 bit.

Change Log

Version 1.1 released 4/28/2017  Fixed bug when using multiple -s switches.  Added -b0 to reset base to entry default.  Added "x" function to write then read data in one invocation -- necessary for COM devices that require a write/read transaction without an intervening close/open of the port.

Click here to download

version 1.0 released 4/11/2017

Click here to download

Widget is loading comments...

You are visitor 161       Go to Home Page

COM port I/O, ver 1.1. (c) 4/28/2017 Syntax: phcom {-opts} func {write data} func: m (mode) displays port used and its settings r (read) reads data from COM port w (write) writes {write data} to COM port x (w+r) writes then reads, final -s specifies read amount -opts (may be anywhere): -c# Force COM port # (no -c scans down from 30, -c0 from 256) [-c alone I/O's stdin/stdout instead of COM port] -m$ Sets COM mode to string $ (same format as MODE COMx command) -i# read interval timeout ms (empty value sets to MAXDWORD) -s# Limit, but not increase, byte size of func [must precede {write data} elements] -x/X# read(x)/write(X) timeout per-byte multiplier ms -t/T# read(t)/write(T) timeout constant ms -r# repeat following data arg # times -b# sets base of write data (-b is hex, -b0 resets to none); other than -b0 causes read output to be numeric -z# debug: set data buffer size to # (1..n, default is 16k) {write data}: hex bytes (by default, see -b), or single-quoted ascii strings, or \"filename\" (filename empty for stdin)