我正在创建一个Xamarin.Forms应用程序,通过RS232从外部设备读取数据-
System. PlatformNotSupport dException:'System.IO.端口目前仅在Windows上受支持。'
更令人困惑的是,MS Doc网站称其支持.NET Framework 2.0-4.8.NET Platform 2.1-5.0 Xamarin.Mac 3.0
Nuget软件包表示它支持.netstandard 2.0.netcoreapp2.1 monorandroid monotouch xamarin.mac xamarin.ios
github页面有linx、mac、windows等实现。。。因此,不确定为什么异常明确表示只针对windows。
微软文档网站:https://learn . Microsoft . com/en-us/dot net/API/system . io . ports . serial port?view=dotnet-plat-ext-5.0
吉图布:https://github.com/dotnet/corefx/tree/master/src/System.IO.Ports/src/System/IO/Ports
Nuget包:https://www.nuget.org/packages/System.IO.Ports/
因为Xamarin.Forms正在使用.Net标准作为目标框架。.Net标准中不支持System.IO.Ports。
您可以使用UsbDeviceConnection
代替。此类用于向USB设备发送和接收数据和控制消息。有关详细信息,请查看MS文档。https://learn.microsoft.com/en-us/dotnet/api/android.hardware.usb.usbdeviceconnection?view=xamarin-android-sdk-9
您可以从下面的链接下载源文件。Xamarin. Forms:使用UsbDeviceConnection库读取数据