【问题标题】:Getting "PlatformNotSupportedException" in .NETCore 3.1 and 4.7 System.IO.Ports在 .NETCore 3.1 和 4.7 System.IO.Ports 中获取“PlatformNotSupportedException”
【发布时间】:2020-05-18 08:43:26
【问题描述】:

我正在开发使用 System.IO.Ports 的多平台库。

库是用 .NET Core 3.1 编写的,并使用 Nuget 的 System.IO.Ports 4.7,显然这个版本应该已经支持 linux 了。但是当我运行主应用程序时,它仍然会导致同样的问题

System.PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows.
   at System.IO.Ports.SerialPort..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits)

当我在谷歌上搜索这个问题时,我发现 System.IO.Ports 4.7 和 .NET Core 3.1 的组合应该可以在 linux 上运行,但没有。

附:我还尝试了不同的库,例如crozone.SerialPorts,但是每个库都有一些无法正常工作的问题,例如invlaid parameter when running /dev/stty 等... 是否有一些库可以解决这个问题,linux/windows 使用串行端口?

非常感谢

【问题讨论】:

  • 我用前面提到的库 crozone.SerialPorts 解决了我的问题。我推荐这个库,它就像一个魅力,它实际上很容易为 Windows 和 Linux 设置。

标签: c# linux .net-core serial-port


【解决方案1】:

您必须安装 System.IO.Ports 包(不是仅 dll 文件),其中包括:

-Microsoft.win32.Registry ...

-System.Memory

-runtime.native.System.IO.ports ...

-System.ioPorts.dll

如果您要使用的软件包版本高于 VS nuget 中的版本,您可以使用软件包管理器控制台安装它。

这个方法对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 2021-11-25
    • 2015-07-29
    • 2021-05-07
    • 1970-01-01
    • 2020-12-05
    相关资源
    最近更新 更多