.NET Core-在Visual Studio代码中使用System.IO.Ports.SerialPort [英] .NET Core - Use System.IO.Ports.SerialPort in visual studio code

查看:1100
本文介绍了.NET Core-在Visual Studio代码中使用System.IO.Ports.SerialPort的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio代码和.Net Core创建一个控制台应用程序,并获取所有可用端口。如何使用 System.IO.Ports.SerialPort
我尝试使用使用语句声明它,但唯一可用的是 Compression 命名空间 System.IO 中的MemoryMappedFiles

I'm trying to create an console application using visual studio code with .Net Core and get all available ports. How to use System.IO.Ports.SerialPort class in visual studio code? I try to declare it with using statement but the only available is Compression and MemoryMappedFiles in namespace System.IO.

我正在使用.Net Core 1.1.1 SDK

I'm using .Net Core 1.1.1 SDK

推荐答案

如果您使用的是Linux OS,则可以使用 SerialPortStream 库。它需要libserial二进制文件,而我只能在linux上编译(不适用于MacOS或Windows)。

If you are using linux OS you can use SerialPortStream library. It requires the libserial binaries and I was able to compile it only for linux (not for MacOS or Windows).

其他方法是使用Mono实现和 Mono.Posix.NETStandard 软件包。这种方式仅适用于NETStandard 2.0项目。

Other way is using the Mono implementation and Mono.Posix.NETStandard package. This way works only for NETStandard 2.0 projects.

我将System.IO.Ports类的源代码从Mono复制到了我的NETStandard 2.0项目中,并添加了Mono.Posix.NETStandard, Microsoft.Win32.Registry引用并将< AllowUnsafeBlocks> true< / AllowUnsafeBlocks> 部分包括到我的.csproj文件中。它可以在MacO和Windows上使用。

I copied sources of System.IO.Ports classes from Mono into my NETStandard 2.0 project, added the Mono.Posix.NETStandard, Microsoft.Win32.Registry references and included <AllowUnsafeBlocks>true</AllowUnsafeBlocks> section into my .csproj file. And it works on MacOs and Windows.

这篇关于.NET Core-在Visual Studio代码中使用System.IO.Ports.SerialPort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆