Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

直接连接 Direct connection #60

Open
Styxxxxxxxx opened this issue Jan 12, 2024 · 1 comment
Open

直接连接 Direct connection #60

Styxxxxxxxx opened this issue Jan 12, 2024 · 1 comment

Comments

@Styxxxxxxxx
Copy link

Hi,
By using the demo scene you provided,I can subscribe my sensor's character and read the poll back data successfully.So i'm wondering if i get the service id and character id in advance,can i use SubscribeCharacteristic directly to get the data?Cause I don't know how the underlying layer of this DLL works

@adabru
Copy link
Owner

adabru commented Jan 12, 2024

Not sure. If I remember correctly I had problems doing that. But just try it out. If it doesn't work, you can do it like here:

ble.Connect(deviceId,
"{f6f04ffa-9a61-11e9-a2a3-2a2ae2dbcce4}",
new string[] { "{f6f07c3c-9a61-11e9-a2a3-2a2ae2dbcce4}",
"{f6f07da4-9a61-11e9-a2a3-2a2ae2dbcce4}",
"{f6f07ed0-9a61-11e9-a2a3-2a2ae2dbcce4}" });
for(int guard = 0; guard < 2000; guard++)
{
BLE.ReadPackage();

and here:

BleWinrtDll/DebugBle/BLE.cs

Lines 192 to 206 in f2635b7

public bool Connect(string deviceId, string serviceUuid, string[] characteristicUuids)
{
if (isConnected)
return false;
Debug.Log("retrieving ble profile...");
RetrieveProfile(deviceId, serviceUuid);
if (GetError() != "Ok")
throw new Exception("Connection failed: " + GetError());
Debug.Log("subscribing to characteristics...");
bool result = Subscribe(deviceId, serviceUuid, characteristicUuids);
if (GetError() != "Ok" || !result)
throw new Exception("Connection failed: " + GetError());
isConnected = true;
return true;
}

BleWinrtDll/DebugBle/BLE.cs

Lines 167 to 179 in f2635b7

public static void RetrieveProfile(string deviceId, string serviceUuid)
{
Impl.ScanServices(deviceId);
Impl.Service service = new Impl.Service();
while (Impl.PollService(out service, true) != Impl.ScanStatus.FINISHED)
Debug.Log("service found: " + service.uuid);
// wait some delay to prevent error
Thread.Sleep(200);
Impl.ScanCharacteristics(deviceId, serviceUuid);
Impl.Characteristic c = new Impl.Characteristic();
while (Impl.PollCharacteristic(out c, true) != Impl.ScanStatus.FINISHED)
Debug.Log("characteristic found: " + c.uuid + ", user description: " + c.userDescription);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants