EloiStree / HelloInput

Collect of information about old project on Input in aim to do a workshop on the topic
0 stars 0 forks source link

Topic: Redirect COM based by name #160

Open EloiStree opened 2 weeks ago

EloiStree commented 2 weeks ago

On Unity3D you can access COM3-N, but you can't access the COM name because it is a bit tool native code. At least not easily.

But in C# Console with the good package or Python is possible.

As python can product code in 30 lines of code. I will do it in python.

If I have the time I can check for the Visuals Studio Code version later

import serial.tools.list_ports

def list_com_ports():
    # Retrieve a list of all available COM ports
    ports = serial.tools.list_ports.comports()

    # Display each port's name and description
    if ports:
        print("Available COM Ports:")
        for port in ports:
            print(f"Port: {port.device} - {port.description} ")
            # Display all information
            description =""
            description += f"Port: {port.device} \n"
            description += f"Description: {port.description} \n"
            description += f"HWID: {port.hwid} \n"
            description += f"VID: {port.vid} \n"
            description += f"PID: {port.pid} \n"
            description += f"Serial Number: {port.serial_number} \n"
            description += f"Location: {port.location} \n"
            description += f"Manufacturer: {port.manufacturer} \n"
            description += f"Product: {port.product} \n"
            description += f"Interface: {port.interface} \n"
            description += f"USB Description: {port.usb_description} \n"
            description += f"USB Info: {port.usb_info} \n"
            print(description)

    else:
        print("No COM ports found.")

if __name__ == "__main__":
    list_com_ports()
Can be use. Not perfect.
Available COM Ports:
Port: COM3 - USB Serial Device (COM3) 
Port: COM3 
Description: USB Serial Device (COM3) 
HWID: USB VID:PID=0D28:0204 SER=99063602000528200673221810C288AE000000006E052820 LOCATION=1-1.1.1:x.1 
VID: 3368 
PID: 516 
Serial Number: 99063602000528200673221810C288AE000000006E052820 
Location: 1-1.1.1:x.1 
Manufacturer: Microsoft 
Product: None 
Interface: None 
USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9B80>> 
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9B80>> 

Port: COM12 - Standard Serial over Bluetooth link (COM12) 
Port: COM12 
Description: Standard Serial over Bluetooth link (COM12) 
HWID: BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_VID&000102B0_PID&0000\7&1A14B62F&0&785EA278907D_C00000000 
VID: None 
PID: None 
Serial Number: None 
Location: None 
Manufacturer: Microsoft 
Product: None 
Interface: None
USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9CD0>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9CD0>>

Port: COM13 - Standard Serial over Bluetooth link (COM13)

Port: COM13
Description: Standard Serial over Bluetooth link (COM13) 
HWID: BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&1A14B62F&0&000000000000_00000002
VID: None
PID: None
Serial Number: None
Location: None
Manufacturer: Microsoft
Product: None
Interface: None
USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9C10>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9C10>>

Port: COM19 - Standard Serial over Bluetooth link (COM19)

Port: COM19
Description: Standard Serial over Bluetooth link (COM19) 
HWID: BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&1A14B62F&0&000000000000_00000003
VID: None
PID: None
Serial Number: None
Location: None
Manufacturer: Microsoft
Product: None
Interface: None
USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9BE0>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at HWIDHHWID: BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&1A14B62F&0&98DA5001A5A3_C00000000       
VID: None
PID: None
Serial Number: None
Location: None
Manufacturer: Microsoft
Product: None
Interface: None
USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9DF0>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9DF0>>

Port: COM6 - SAMSUNG Mobile USB Modem #3
Port: COM6
Description: SAMSUNG Mobile USB Modem #3
HWID: USB VID:PID=04E8:6860 SER=R8YW40DGTCE LOCATION=1-8.8
VID: 1256
PID: 26720
Serial Number: R8YW40DGTCE
Location: 1-8.8
Manufacturer: SAMSUNG Electronics Co., Ltd.
Product: None
Interface: None
USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9D90>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000020CAD2C9D90>>
EloiStree commented 2 weeks ago

Usable:

For HC05

image

EloiStree commented 2 weeks ago
import subprocess

def list_bluetooth_device_details():
    try:
        # PowerShell command to retrieve detailed Bluetooth device info
        command = [
            "powershell",
            "-Command",
            """
            Get-PnpDevice -Class Bluetooth | ForEach-Object {
                [PSCustomObject]@{
                    Name         = $_.Name
                    InstanceId   = $_.InstanceId
                    VendorID     = $_.InstanceId -match 'VID_([0-9A-F]+)' ? $matches[1] : "N/A"
                    ProductID    = $_.InstanceId -match 'PID_([0-9A-F]+)' ? $matches[1] : "N/A"
                    SerialNumber = $_.InstanceId -match 'BTHENUM\\\\DEV_(\\w+)' ? $matches[1] : "N/A"
                }
            } | Select-Object Name, VendorID, ProductID, SerialNumber
            """
        ]

        # Execute the PowerShell command
        result = subprocess.run(command, capture_output=True, text=True)

        # Display the output
        if result.stdout:
            print("Bluetooth Devices with Vendor ID, Product ID, and Serial Number:")
            print(result.stdout)
        else:
            print("No Bluetooth devices found or unable to retrieve device information.")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    list_bluetooth_device_details()
Name                                   InstanceId
----                                   ----------
Generic Access Profile                 BTHLEDEVICE\{00001800-0000-100... 
Intel(R) Wireless Bluetooth(R)         USB\VID_8087&PID_0026\5&1CCFCB... 
Device Information Service             BTHLEDEVICE\{0000180A-0000-100... 
Bluetooth LE Generic Attribute Service BTHLEDEVICE\{0000FFE0-0000-100... 
Microsoft Bluetooth LE Enumerator      BTH\MS_BTHLE\6&1C7D32E4&0&3       
Bluetooth LE Generic Attribute Service BTHLEDEVICE\{0000FE59-0000-100... 
Device Information Service             BTHLEDEVICE\{0000180A-0000-100... 
Device Identification Service          BTHENUM\{00001200-0000-1000-80... 
Generic Attribute Profile              BTHLEDEVICE\{00001801-0000-100... 
Device Information Service             BTHLEDEVICE\{0000180A-0000-100... 
HC-05                                  BTHENUM\DEV_98DA5001A5A3\7&1C7... 
Generic Access Profile                 BTHLEDEVICE\{00001800-0000-100... 
Bluetooth LE Generic Attribute Service BTHLEDEVICE\{00000001-5F60-4C4... 
Bluetooth LE Generic Attribute Service BTHLEDEVICE\{0000180F-0000-100... 
Microsoft Bluetooth Enumerator         BTH\MS_BTHBRB\6&1C7D32E4&0&1      
Bluetooth Device (RFCOMM Protocol TDI) BTH\MS_RFCOMM\6&1C7D32E4&0&0      
Generic Access Profile                 BTHLEDEVICE\{00001800-0000-100... 
HC-05                                  BTHLE\DEV_98DA5001A5A3\7&5C8DD... 
JBL TUNE230NC TWS                      BTHENUM\DEV_785EA278907D\7&1C7... 
Xbox Wireless Controller               BTHLE\DEV_EC83509993F6\7&5C8DD... 
BBC micro:bit [papav]                  BTHLE\DEV_D9CB0FB2D098\7&5C8DD... 
JBL TUNE230NC TWS Avrcp Transport      BTHENUM\{0000110C-0000-1000-80... 
Generic Attribute Profile              BTHLEDEVICE\{00001801-0000-100... 
JBL TUNE230NC TWS Avrcp Transport      BTHENUM\{0000110E-0000-1000-80... 
Generic Attribute Profile              BTHLEDEVICE\{00001801-0000-100... 
EloiStree commented 2 weeks ago

image

Port: COM3 - USB Serial Device (COM3) Exact Device Name: COM3 Port: COM3 Description: USB Serial Device (COM3) HWID: USB VID:PID=0D28:0204 SER=99063602000528200673221810C288AE000000006E052820 LOCATION=1-1.1.1:x.1 VID: 3368 PID: 516 Serial Number: 99063602000528200673221810C288AE000000006E052820 Location: 1-1.1.1:x.1 Manufacturer: Microsoft Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000025A99289BE0>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000025A99289BE0>>

EloiStree commented 2 weeks ago

image

EloiStree commented 2 weeks ago

image Port: COM18 - USB Serial Device (COM18) Exact Device Name: COM18 Port: COM18 Description: USB Serial Device (COM18) HWID: USB VID:PID=0D28:0204 SER=99063602000528200D1EFEB3EE975B55000000006E052820 LOCATION=1-1.1.1:x.1 VID: 3368 PID: 516 Serial Number: 99063602000528200D1EFEB3EE975B55000000006E052820 Location: 1-1.1.1:x.1 Manufacturer: Microsoft Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x0000018F33A69C70>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x0000018F33A69C70>>

EloiStree commented 2 weeks ago

image Port: COM7 - USB Serial Device (COM7) Exact Device Name: COM7 Port: COM7 Description: USB Serial Device (COM7) HWID: USB VID:PID=2886:0042 SER=4150323038323719 LOCATION=1-8:x.0
VID: 10374 PID: 66 Serial Number: 4150323038323719 Location: 1-8:x.0 Manufacturer: Microsoft Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x000001D965169C10>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x000001D965169C10>>

EloiStree commented 2 weeks ago

image Port: COM10 - USB Serial Device (COM10) Exact Device Name: COM10 Port: COM10 Description: USB Serial Device (COM10) HWID: USB VID:PID=2886:0042 SER=4150323038323714 LOCATION=1-8:x.0
VID: 10374 PID: 66 Serial Number: 4150323038323714 Location: 1-8:x.0 Manufacturer: Microsoft Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x000002309B1F9C10>>
USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x000002309B1F9C10>>

EloiStree commented 2 weeks ago

image Port: COM14 - USB Serial Device (COM14) Exact Device Name: COM14 Port: COM14 Description: USB Serial Device (COM14) HWID: USB VID:PID=2E8A:0005 SER=E6614C3093862A2C LOCATION=1-8:x.0 VID: 11914 PID: 5 Serial Number: E6614C3093862A2C Location: 1-8:x.0 Manufacturer: Microsoft Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x000001814FB89C10>> USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x000001814FB89C10>>

EloiStree commented 2 weeks ago

image Port: COM17 - USB Serial Device (COM17) Exact Device Name: COM17 Port: COM17 Description: USB Serial Device (COM17) HWID: USB VID:PID=2E8A:0005 SER=E66258881770B224 LOCATION=1-8:x.0
VID: 11914 PID: 5 Serial Number: E66258881770B224 Location: 1-8:x.0 Manufacturer: Microsoft Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x000002510DC49C70>> USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x000002510DC49C70>>

EloiStree commented 2 weeks ago

image image

No data (HC06 did not stay connected) And device is a XInput not a COM input 😉

EloiStree commented 2 weeks ago

image Port: COM23 - Arduino Uno (COM23) Exact Device Name: COM23 Port: COM23 Description: Arduino Uno (COM23) HWID: USB VID:PID=2A03:0043 SER=7543535303535161B132 LOCATION=1-1.4 VID: 10755 PID: 67 Serial Number: 7543535303535161B132 Location: 1-1.4 Manufacturer: Arduino Srl (www.arduino.org) Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x000002802F549DF0>> USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x000002802F549DF0>>

EloiStree commented 2 weeks ago

image Port: COM24 - USB-SERIAL CH340 (COM24) Exact Device Name: COM24 Port: COM24 Description: USB-SERIAL CH340 (COM24) HWID: USB VID:PID=1A86:7523 SER= LOCATION=1-1.1.3 VID: 6790 PID: 29987 Serial Number: Location: 1-1.1.3 Manufacturer: wch.cn Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x00000239EB069DF0>> USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x00000239EB069DF0>>

Port: COM25 - USB-SERIAL CH340 (COM25) Exact Device Name: COM25 Port: COM25 Description: USB-SERIAL CH340 (COM25) HWID: USB VID:PID=1A86:7523 SER= LOCATION=1-1.1.1 VID: 6790 PID: 29987 Serial Number: Location: 1-1.1.1 Manufacturer: wch.cn Product: None Interface: None USB Description: <bound method ListPortInfo.usb_description of <serial.tools.list_ports_common.ListPortInfo object at 0x00000239EB069FA0>> USB Info: <bound method ListPortInfo.usb_info of <serial.tools.list_ports_common.ListPortInfo object at 0x00000239EB069FA0>>

EloiStree commented 2 weeks ago

image Midi is apparently not a COM

EloiStree commented 2 weeks ago

image image

Not COM but un BLE

Consider as mouse on Window

EloiStree commented 2 weeks ago

C# in Visual Studio Code

using System;
using System.Management;
// NuGet\Install-Package System.Management -Version 4.6.0

class Program
{
    static void Main()
    {
        try
        {
            // Query all COM devices in Win32_PnPEntity
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%'");

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("Device Information:");
                Console.WriteLine("-------------------");

                // Iterate over all properties in the ManagementObject
                foreach (PropertyData property in queryObj.Properties)
                {
                    if (property.Value is Array arr) // If property is an array, join its elements
                    {
                        Console.WriteLine("{0}: {1}", property.Name, string.Join(", ", arr));
                    }
                    else
                    {
                        Console.WriteLine("{0}: {1}", property.Name, property.Value ?? "N/A");
                    }
                }

                Console.WriteLine(); // Blank line for readability
            }
        }
        catch (ManagementException ex)
        {
            Console.WriteLine("An error occurred while querying for COM ports: " + ex.Message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("An unexpected error occurred: " + ex.Message);
        }
    }
}

Device Information:

Availability: N/A Caption: USB Serial Device (COM3) ClassGuid: {4d36e978-e325-11ce-bfc1-08002be10318} CompatibleID: System.String[] ConfigManagerErrorCode: 0 ConfigManagerUserConfig: False CreationClassName: Win32_PnPEntity Description: USB Serial Device DeviceID: USB\VID_0D28&PID_0204&MI_01\8&1B049072&0&0001 ErrorCleared: N/A ErrorDescription: N/A HardwareID: System.String[] InstallDate: N/A LastErrorCode: N/A Manufacturer: Microsoft Name: USB Serial Device (COM3) PNPClass: Ports PNPDeviceID: USB\VID_0D28&PID_0204&MI_01\8&1B049072&0&0001 PowerManagementCapabilities: N/A PowerManagementSupported: N/A Present: True Service: usbser Status: OK StatusInfo: N/A SystemCreationClassName: Win32_ComputerSystem SystemName: MSI

Device Information:

Availability: N/A Caption: Standard Serial over Bluetooth link (COM12) ClassGuid: {4d36e978-e325-11ce-bfc1-08002be10318} CompatibleID: System.String[] ConfigManagerErrorCode: 0 ConfigManagerUserConfig: False CreationClassName: Win32_PnPEntity Description: Standard Serial over Bluetooth link DeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_VID&000102B0_PID&0000\7&1A14B62F&0&785EA278907D_C00000000 ErrorCleared: N/A ErrorDescription: N/A HardwareID: System.String[] InstallDate: N/A LastErrorCode: N/A Manufacturer: Microsoft Name: Standard Serial over Bluetooth link (COM12) PNPClass: Ports PNPDeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_VID&000102B0_PID&0000\7&1A14B62F&0&785EA278907D_C00000000 PowerManagementCapabilities: N/A PowerManagementSupported: N/A Present: True Service: BTHMODEM Status: OK StatusInfo: N/A SystemCreationClassName: Win32_ComputerSystem SystemName: MSI

Device Information:

Availability: N/A Caption: Standard Serial over Bluetooth link (COM19) ClassGuid: {4d36e978-e325-11ce-bfc1-08002be10318} CompatibleID: System.String[] ConfigManagerErrorCode: 0 ConfigManagerUserConfig: False CreationClassName: Win32_PnPEntity Description: Standard Serial over Bluetooth link DeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&1A14B62F&0&98DA5001A5A3_C00000000 ErrorCleared: N/A ErrorDescription: N/A HardwareID: System.String[] InstallDate: N/A LastErrorCode: N/A Manufacturer: Microsoft Name: Standard Serial over Bluetooth link (COM19) PNPClass: Ports PNPDeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&1A14B62F&0&98DA5001A5A3_C00000000 PowerManagementCapabilities: N/A PowerManagementSupported: N/A Present: True Service: BTHMODEM Status: OK StatusInfo: N/A SystemCreationClassName: Win32_ComputerSystem SystemName: MSI

Device Information:

Availability: N/A Caption: Standard Serial over Bluetooth link (COM13) ClassGuid: {4d36e978-e325-11ce-bfc1-08002be10318} CompatibleID: System.String[] ConfigManagerErrorCode: 0 ConfigManagerUserConfig: False CreationClassName: Win32_PnPEntity Description: Standard Serial over Bluetooth link DeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&1A14B62F&0&000000000000_00000002 ErrorCleared: N/A ErrorDescription: N/A HardwareID: System.String[] InstallDate: N/A LastErrorCode: N/A Manufacturer: Microsoft Name: Standard Serial over Bluetooth link (COM13) PNPClass: Ports PNPDeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&1A14B62F&0&000000000000_00000002 PowerManagementCapabilities: N/A PowerManagementSupported: N/A Present: True Service: BTHMODEM Status: OK StatusInfo: N/A SystemCreationClassName: Win32_ComputerSystem SystemName: MSI

Device Information:

Availability: N/A Caption: Standard Serial over Bluetooth link (COM20) ClassGuid: {4d36e978-e325-11ce-bfc1-08002be10318} CompatibleID: System.String[] ConfigManagerErrorCode: 0 ConfigManagerUserConfig: False CreationClassName: Win32_PnPEntity Description: Standard Serial over Bluetooth link DeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&1A14B62F&0&000000000000_0000000B ErrorCleared: N/A ErrorDescription: N/A HardwareID: System.String[] InstallDate: N/A LastErrorCode: N/A Manufacturer: Microsoft Name: Standard Serial over Bluetooth link (COM20) PNPClass: Ports PNPDeviceID: BTHENUM{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&1A14B62F&0&000000000000_0000000B PowerManagementCapabilities: N/A PowerManagementSupported: N/A Present: True Service: BTHMODEM Status: OK StatusInfo: N/A SystemCreationClassName: Win32_ComputerSystem SystemName: MSI


🤖 A PNP Device ID is an identifier used by the Plug and Play (PNP) system in Windows to identify hardware devices. This particular ID, USB\VID_0D28&PID_0204&MI_01\8&1B049072&0&0001, follows a specific structure that provides information about the type of device, its manufacturer, and other details.

Let's break down the components:

  1. USB: This is the device class, indicating the device is connected through a USB interface.

  2. VID (Vendor ID): VID_0D28

    • This part identifies the manufacturer of the device.
    • 0D28 is the hexadecimal Vendor ID assigned to a particular manufacturer (in this case, ARM for CMSIS-DAP debugging devices, which are commonly used for ARM microcontroller programming and debugging).
  3. PID (Product ID): PID_0204

    • This part identifies the specific product made by the manufacturer.
    • 0204 corresponds to a specific product model associated with VID_0D28.
  4. MI (Multiple Interface): MI_01

    • This is optional and only appears for devices that expose multiple interfaces (like composite USB devices).
    • 01 refers to the interface number, so this device has multiple interfaces, and this identifier represents the second interface (count starts from 00).
  5. Unique Identifier: 8&1B049072&0&0001

    • This part is unique to each instance of the device and varies by device and connection.
    • The specifics here aren't as standardized and are used by the operating system for unique device identification.

Overall Format

The general format of a PNP Device ID is:

<Bus Type>\<Vendor ID>_<Product ID>&[Optional Subfields]\[Unique ID]

In this example: