在.NET Core 1.1中使用System.IO.Ports.SerialPort [英] Using System.IO.Ports.SerialPort in .NET Core 1.1

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

问题描述

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

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.

我从Mono复制了System.IO.Ports类的源代码到我的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 1.1中使用System.IO.Ports.SerialPort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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