Tiny (7k) 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: Write examples:
Source is included. It can be built 32 or 64 bit.
Windows COM port I/O from command line
[page last modified 2018-03-12]
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
C>phcom -c w 68 65 6c 6c 6f 20 d a
hello
C>phcom -c w -r10 'ab'
abababababababababab
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
The 64-bit -d option allows dropping data from the front of the output:
C>phcom -c w -d5 '123456789' -d2 '123456789'
67893456789
An argument can be a filename in double quotes (empty for stdin).
C>echo hello|phcom -c w 'start' \"\" 'end'
starthello
end
C>echo hello >foo.txt
C>phcom -c w 'start' \"foo.txt\" 'end'
starthello
end
The number of bytes output can be limited by the 64-bit -s switch.
Change Log
Version 1.2 released 3/11/2018 Added "-d" switch to drop data from beginning of output.
Click here to download phcom180311.zip
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 phcom170428.zip
version 1.0 released 4/11/2017
Click here to download phcom170411.zip
You are visitor 11647 Go to Home Page
COM port I/O, ver 1.2. (c) paulhoule.com 3/11/2018 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 (-s, -r, -d are 64-bit values): -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) -x/X# read(x)/write(X) timeout per-byte multiplier ms -t/T# read(t)/write(T) timeout constant ms -s# Limit, but not increase, output size -r# repeat following data arg # times -d# drop # bytes from subsequent output -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)