0
votes

I'm trying to list the serial ports in my Windows based PC.

This is my port list: (COM3 & COM8)

enter image description here

Code:

if sys.platform.startswith("win32"):
    from serial.tools.list_ports_windows import *

elif sys.platform.startswith("linux"):
    from serial.tools.list_ports import *

else:
    raise ImportError("Sorry: no implementation for your platform {} available".format(sys.platform))

.........Class definition and other methods..................

def GetList(self, verbose=True):
        """
            gets the list of all available ports
        """

        results = []

        hits = 0

        iterator = sorted(comports())

        # list them
        for port, desc, hwid in iterator:
            comPort = port
            if verbose:
                descValue = desc
                hwidValue = hwid
                results.append({'comPort': comPort, 'descValue': descValue, 'hwidValue': hwidValue})
            else:
                results.append({'comPort': comPort})
            hits += 1

        results.append({"available": "{} ports found".format(hits)})

        return results

Output:

[{'hwidValue': 'PCI\\VEN_8086&DEV_1E3D&SUBSYS_21F317AA&REV_04', 'descValue': 'Intel(R) Active Management Technology - SOL (COM3)', 'comPort': 'COM3'}, {'available': '1 ports found'}]

Question:

Why can't i see all the ports in my PC is there a problem in my code?

as you can see in the picture i have 2 ports COM3 and COM8.

Does list_ports_windows has limitations for Virtual com ports?

1

1 Answers

1
votes

I can tell you that using the WMI (python wmi module: https://pypi.python.org/pypi/WMI/)

import wmi
c = wmi.WMI()
wql = "Select * From Win32_SerialPort"
for item in c.query(wql):
    print item

The result is the same, only hardware serial ports are listed. So I suppose the same happens with your implementation for the same reason, eg. you can get ONLY the hardware ports.

Edit: according to Kobi K this does list virtual ports.

You can check however for all the virtual ports in the registry: HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\