我尝试开发一个可以访问COM端口的应用程序。要选择匹配的COM端口,最好能自动识别系统。有没有办法将系统(Windoews、Linux或MAC)读取为字符串或类似的内容?稍后,我想使用USB VID或PID选择虚拟Com端口。如果你能给我一个或两个甚至三个...建议。
我目前正在开始使用Mono,如果有什么帮助,我会很高兴;)
thx汤米
发布于 2017-03-09 23:07:29
我找到了一个解决方案,并创建了几行代码:
/// <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;
}
} 不幸的是,OS X (macOS 10.12.3 Sierra)显示为UNIX :|
这将是伟大的,如果有人可以测试代码,并呈现给我的结果。或者谁知道解决方案也是受欢迎的;)
thx和cya Thommy
https://stackoverflow.com/questions/42693471
复制相似问题