不支持 System.IO.Ports 5.0 Xamarin.Forms 串行端口 [英] System.IO.Ports 5.0 Xamarin.Forms Serial Port not supported

查看:45
本文介绍了不支持 System.IO.Ports 5.0 Xamarin.Forms 串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Xamarin.Forms 应用程序,它通过 RS232 从外部设备读取数据 ->USB.我一直在寻找如何从串行端口读取并遇到 System.IO.Ports,它说它可以与 .netstandard2.0 一起使用,并且具有 MonoAndroid1.0、MonoTouch、Xamarin.iOS、...支持.我正在运行 Xamarin 表单 4.8(很快将升级到 5),它在针对 Android 8+ 时实现了 netstandard2.0,而我的目标是 9,所以我不确定为什么这不起作用.当我尝试新建一个串行端口时,它抛出异常

I'm creating a Xamarin.Forms app that reads data from an external device via RS232 -> USB. I was looking for how to read from a Serial port and ran into System.IO.Ports which says it will work with .netstandard2.0 and has MonoAndroid1.0, MonoTouch, Xamarin.iOS, ... support. I'm running Xamarin forms 4.8 (will upgrade to 5 soon) which implements netstandard2.0 when targeting Android 8+ and I'm targeting 9 so I'm not sure why this doesn't work. When I try to new up a serial port, it throws an exception

System.PlatformNotSupportedException: 'System.IO.Ports 目前仅在 Windows 上受支持.'

更令人困惑的是,MS Doc 站点说它支持.NET 框架 2.0 - 4.8.NET 平台 2.1 - 5.0Xamarin.Mac 3.0

What's even more confusing, is the MS Doc site says that it supports .NET Framework 2.0 - 4.8 .NET Platform 2.1 - 5.0 Xamarin.Mac 3.0

Nuget 包说它支持.netstandard 2.0.netcoreapp2.1单人机器人单点触控xamarin.macxamarin.ios

The Nuget package says it supports .netstandard 2.0 .netcoreapp2.1 monoandroid monotouch xamarin.mac xamarin.ios

github 页面有针对 linx、mac、windows 的实现,所以不知道为什么异常明确说明只针对 windows.

The github page has implementations for linx, mac, windows, ... so not sure why the exception explicitly says only for windows.

Microsoft Doc 站点:https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view=dotnet-plat-ext-5.0

Microsoft Doc site: https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view=dotnet-plat-ext-5.0

Github:https://github.com/dotnet/corefx/tree/master/src/System.IO.Ports/src/System/IO/Ports

Nuget 包:https://www.nuget.org/packages/System.IO.端口/

推荐答案

因为 Xamarin.Forms 使用 .Net Standard 作为目标框架..Net Standard 不支持 System.IO.Ports.

Because Xamarin.Forms is using .Net Standard as Target Framework. And System.IO.Ports is not supported in .Net Standard.

您可以改用 UsbDeviceConnection.此类用于向 USB 设备发送和接收数据和控制消息.详情请查看 MS 文档.https://docs.microsoft.com/en-us/dotnet/api/android.hardware.usb.usbdeviceconnection?view=xamarin-android-sdk-9

You could use UsbDeviceConnection instead. This class is used for sending and receiving data and control messages to a USB device. For more details, please check the MS document. https://docs.microsoft.com/en-us/dotnet/api/android.hardware.usb.usbdeviceconnection?view=xamarin-android-sdk-9

您可以从下面的链接下载源文件.Xamarin.Forms:使用 UsbDeviceConnection 库读取数据

You could download the source file from the link below. Xamarin.Forms: Read Data using UsbDeviceConnection Library

这篇关于不支持 System.IO.Ports 5.0 Xamarin.Forms 串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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