如何解决Xamarin C#,我无法运行 Plugin.BLE 代码
我正在尝试制作一个非常简单和基本的移动应用程序,用于通过蓝牙控制我的 Arduino。 没有很多 C# 经验,但在蓝牙部分出现之前一切顺利。 我到处搜索并找到了这个https://github.com/xabre/xamarin-bluetooth-le 并开始在自述文件中做说明。但我每次都会出错。
首先,我将这些代码复制到 androidmanifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
之后,我将这些代码添加到 mainpage.xml.cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var ble = CrossBluetoothLE.Current;
var adapter = CrossBluetoothLE.Current.Adapter;
var state = ble.State;
}
}
但这导致了 2 个错误:错误 CS0103 The name 'CrossBluetoothLE' 在当前上下文 BlueT 中不存在
我添加了使用 Plugin.BLE;所以错误消失了。然后我继续写;
adapter.DeviceDiscovered += (s,a) => deviceList.Add(a.Device);
await adapter.StartScanningForDevicesAsync();
在我粘贴这些之后,我遇到了错误:
错误 CS4033 'await' 操作符只能在 async 中使用 方法。考虑使用 'async' 修饰符标记此方法并 将其返回类型更改为“任务” 错误 CS0103 名称“deviceList”在当前不存在 上下文
我尝试了一切但无法解决这个问题,很抱歉像我说的那样,没有太多#或Android编程经验,只想将这些滑块和按钮数据发送到我的Arduino: This is my mobile controller app
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。