This code will help you to find the list of connected devices through serial port with system. You will need serial module to access system COM ports,to download serial module for python 2.7 use this link https://pypi.python.org/pypi/pyserial/2.7 .
Code:
import serial.tools.list_ports # import serial module
comPorts = list(serial.tools.list_ports.comports()) # get list of all devices connected through serial port
print ‘List of devices connected on com ports : ‘, comPorts
numPortsUsed = len(comPorts) # get number of com ports used # get number of com ports used in system
print ‘Number of com ports used in system : ‘, numPortsUsed
Output:
>>>
List of devices connected on com ports : [(‘COM1’, ‘Communications Port (COM1)’, ‘ACPI\\PNP0501\\1’), (‘COM4’, ‘Arduino Uno (COM4)’, ‘USB VID:PID=2341:0043 SNR=75433313639351C09102’)]
Number of com ports used in system : 2
>>>