.Get() equivalent in Mono

Hi
I want the full name of the COM port. For example: “Arduino UNO (COM3)”.
With SerialPort.GetPortNames (), I just get the list of COM ports,
COM 1
COM 3

immmm hosted at ImgBB — ImgBB [/IMG]

To get this information, I use this code:

using System.Collections.Generic;
using System.Management;

public class GetInfoCom
{

    public List<string> getInfoCom()
    {
        List<string> serial_ports = new List<string>();

        try
        {
            System.Management.ManagementScope connectionScope = new System.Management.ManagementScope();
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_SerialPort");
            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
            if (searcher.Get().Count > 0)
            {
                foreach (ManagementObject item in searcher.Get())
                {
                    string desc = item["Description"].ToString();
                    string deviceID = item["DeviceID"].ToString();

                    if (desc.Contains("Arduino"))
                    {
                        serial_ports.Add(desc);
                        serial_ports.Add(deviceID);
                    }
                }
            }
        }
        catch (ManagementException e)
        {

        }

        return serial_ports;
    }
}

Since in Mono there is no .Get () method, I created a separate class, which does not inherit from mono, but which must return me a list with various information, but despite this, it keeps bringing me the error:
NotImplementedException: The method or operation is not implemented.
System.Management.ManagementObjectSearcher.Get () (at <42893b42476b490b89469d371d3f6cbe>:0)
(wrapper remoting-invoke-with-check) System.Management.ManagementObjectSearcher.Get()

Advice? Thanks
(In visual studio I added the System Management reference)

I’m going to guess that anything specific only to Win32 C# extensions won’t be findable in Unity. There may be another mechanism to get device information though… check on the arduino forums or other places people write code to bang on UARTs and COM ports in general.

1 Like