0

i try to develop an app that accesses a COM Port. To select a matching COM Port it would be good to recognize the system automatically. Is there a way to read the system (Windoews, Linux or MAC) as a string or something similar? Later I would like to select a Virtual Com port using the USB VID or PID. It would be great if you could give me one or two or even three ... advice.

I am currently start working with Mono and would be glad about something help ;)

thx Thommy

  • Possible duplicate of [How to check the OS version at runtime e.g. windows or linux without using a conditional compilation statement](http://stackoverflow.com/questions/5116977/how-to-check-the-os-version-at-runtime-e-g-windows-or-linux-without-using-a-con) – SushiHangover Mar 09 '17 at 13:17

1 Answers1

0

I have found a solution and have created a few lines of code:

    /// <summary>
    /// Get Execution Platform / OS
    ///     return value
    ///     0: nicht erkannt/Error
    ///     1: Windows
    ///     2: MacOSX 
    ///     2: Unix (Linux)
    /// </summary>
    static public int DetectingExecutionPlatform()
    {
        OperatingSystem os = Environment.OSVersion;
        PlatformID pid = os.Platform;
        switch (pid)
        {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                return 1;
            case PlatformID.MacOSX:
                return 2;
            case PlatformID.Unix:
                return 3;
            default:
                return 0;
        }
    }  

Unfortunately, OS X (macOS 10.12.3 Sierra) is displayed as UNIX :|

It would be great if someone could test the code and present me the result. Or who knows a solution is also welcome ;)

thx and cya Thommy