我正在使用用于 C++的 Windows api Gatt Client BLE,我的目标是连接两个设备(但在这种情况下我将只尝试一个)并在不关闭设备的情况下不断读取和写入数据。我所有的设备都有一个特定的服务,其中包含一个读取特性和一个写入特性。
如何测试:
使用 Visual Studio 2017 (v141) 和 Windows SDK 版本:10.0.18362.0,创建一个新的控制台 (.exe) 解决方案,将 Project -> Properties 中的 Platform 更改为 Win32 并转到 Project -> Properties -> C/C++ ->命令行并添加以下选项:
/std:c++17 /await
Run Code Online (Sandbox Code Playgroud)
然后将以下代码复制到一个文件中(您可以将所有代码复制到同一个 .cpp 文件中):
#pragma once
#include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
#include <queue>
#include <map>
#include <mutex>
#include <condition_variable>
#include <string>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Web.Syndication.h>
#include "winrt/Windows.Devices.Bluetooth.h"
#include "winrt/Windows.Devices.Bluetooth.GenericAttributeProfile.h"
#include "winrt/Windows.Devices.Enumeration.h"
#include "winrt/Windows.Storage.Streams.h"
#pragma comment(lib, "windowsapp")
using namespace std;
using namespace winrt; …
Run Code Online (Sandbox Code Playgroud) 我在 Unity 中有代码,使用 AndroidJavaClass 和 AndroidJavaObject 调用 Android 的 Java 编程函数,我想将此代码传递给 C# .Net 中的 dll,但我找不到使用 C# .Net 调用 Java 函数的简单方法由于 AndroidJavaObject 和 AndroidJavaClass 类是 Unity dll 独有的,因此以下是我的代码示例:
Java(安卓):
public class DeviceManager {
public interface DeviceListener {
void DoSomething();
}
private DeviceListener deviceListener;
public DeviceManager(DeviceListener deviceListener){
this.deviceListener = deviceListener;
}
public String[] getSomeData(){
return new String[]{};
}
}
Run Code Online (Sandbox Code Playgroud)
C#(统一):
public class DeviceListener : AndroidJavaProxy
{
DeviceManager deviceManager;
public DeviceListener(DeviceManager manager) : base("com.myapp.DeviceManager$DeviceListener")
{
this.deviceManager = manager;
}
public void DoSomething();
} …
Run Code Online (Sandbox Code Playgroud)