c# - 在 .NETCore 3.1 和 4.7 System.IO.Ports 中获取“PlatformNotSupportedException”
问题描述
我正在开发使用 System.IO.Ports 的多平台库。
库是用 .NET Core 3.1 编写的,并使用来自 Nuget 的 System.IO.Ports 4.7,显然这个版本应该已经可以在 linux 上使用,但支持 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 上运行,但没有。
PS我也尝试了不同的库crozone.SerialPorts
,但是每个库都有一些不工作的问题,feinvlaid parameter when running /dev/stty
等......是否有一些库可以解决这个问题,linux/windows使用串行端口?
非常感谢
解决方案
您必须安装 System.IO.Ports 包(不是仅 dll 文件),其中包括:
-Microsoft.win32.Registry ...
-系统.内存
-runtime.native.System.IO.ports ...
-System.ioPorts.dll
如果您要使用的软件包版本高于 VS nuget 中存在的版本,您可以使用软件包管理器控制台安装它。
这种方法对我有用
推荐阅读
- shell - 通过 sh 脚本运行 xdtool 命令时锁定键盘和鼠标
- azure - 在 Azure AD B2C 中注册后如何让用户返回登录页面?
- bash - Shell 脚本 - 无法将随机值分配给变量
- apache-kafka - kafka消费者轮询多次不返回所有数据
- python - 网络抓取不同的 URL - 限制
- ios - Alamofire 网络错误异常处理
- c++ - 占位符变量在迭代期间不更新
- javascript - javascript:function.bind(object) 的问题 - “this”保留为全局对象
- python - 以前的表单数据应用于表单以在 django 中进行编辑
- javascript - 如何更改通过 React Router 传递的道具的状态?