0

I have a microcontroller and I'm using UART to connect between the controller and my PC. I need to determine in the PC to which COM port the microcontroller is connected and change it by a list of open COM ports. I wanted to use OS moudle of Python for changing but in every guide I looked people are doing in the Device Manager.

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29

1 Answers1

1

You can use the following code to list the COM ports

import serial.tools.list_ports

all_comports = serial.tools.list_ports.comports()

for comport in all_comports:
    print(comport.device, comport.name, comport.description, comport.interface)

You can also list other information about the device using the following reference

veedata
  • 1,048
  • 1
  • 9
  • 15
  • This is for getting all the COM ports, what I am searching is a way to change the actual COM port my microcontroller is connected to – DarkKnight35 Aug 06 '21 at 16:45