If you have ever connected a piece of hardware to your computer that is less common than a mouse, keyboard, camera or thumb drive, you may have encountered the scenario where your software asks what the COM port number is in order to communicate with the device. What does this mean?
According to Wikipedia, a “COM (communication port) is the original, yet still common, name of the serial port interface on PC-compatible computers.” Namely, DOS and now Windows systems. Linux refers to them by by a file-based link, like: /dev/ttyS0.
Windows assigns a port number to allow a serial device to COMmunicate with your software. A serial device uses a very basic protocol or language, sending simple text based data at a specific speed or “baud” symbol rate. Finding the COM port number is the first step to connecting your software to that device. You can usually get the rest of the parameters from the hardware manual, or set them on the device itself; e.g.: baud rate, stop bits, parity.
Devices that you may encounter the COM port quandary includes modems, commercial firewalls and network switches, GPS units, telescopes, environmental sensors, battery backup, charge controllers, and two-way radios.
So, how do we get the COM port numbers, assuming the software doesn’t list the names of the devices associated with a COM port? There are a couple of methods.
- Commonly, we are instructed to pull up the device manager and dig up the device in a long list of devices:
- Tap Start and start typing “Device Manager”, or
- Right-click Computer on your desktop or in File Explorer and select Manage, and then select Device Manager in the list within the left-hand panel
- Expand “Ports (COM & LPT)” which are your serial and parallel devices
- Look for the device name that looks like the piece of hardware or the serial chipset it is using (the hardware manual should shed some light on this if there are many obscure names here)
- Use a batch file on your desktop to simply and immediately list the connected devices. (see next image)
Since I work a lot with serial devices for work and hobby, I created this batch file that can be run right from the desktop.
To use it:
- Open Notepad
- Enter the code below
- Save it to your desktop as COMPorts.bat
(make sure it’s not .txt)
- Double-click the new icon to view the list!
ECHO "Connected COM Ports"
POWERSHELL -c "Get-WmiObject Win32_SerialPort | Select-Object Name"
For the geeks among us, the batch file executes a PowerShell command that polls the WMI (Windows Management Instrumentation) database for serial devices and lists them by Name. It then pauses to keep the window open long enough for you to read the list.