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

Unable to reconnect to GATT characteristics after disconnecting #446

Open
h2oboi89 opened this issue Dec 16, 2024 · 0 comments
Open

Unable to reconnect to GATT characteristics after disconnecting #446

h2oboi89 opened this issue Dec 16, 2024 · 0 comments

Comments

@h2oboi89
Copy link

h2oboi89 commented Dec 16, 2024

Want to be able to connect, disconnect, and then reconnect from BLE devices in a longer running process. Currently the code only calls BluetoothDevice.DisposeAllNativeObjects in a deconstructor I can't manually invoke.

Overall workflow:

  1. Connect to Gatt
  2. Connect to Service
  3. Connect to characteristics
  4. Do the BLE things
  5. Dispose of entire stack
  6. Reconnect if desired (start back at 1)

Was able to successfully implement my workflow by making BluetoothDevice implement IDisposable and have that call DisposeAllNativeObjects()

private void Dispose(bool disposing)
{
    if (!disposedValue)
    {
        if (disposing)
        {
            // TODO: dispose managed state (managed objects)
        }

        DisposeAllNativeObjects();
        disposedValue = true;
    }
}

~BluetoothDevice()
{
    Dispose(disposing: false);
}

public void Dispose()
{
    Dispose(disposing: true);
    GC.SuppressFinalize(this);
}

NOTE: implemented this in Platforms/Windows/BluetoothDevice.windows.cs

Now calling BluetoothDevice.Dispose() properly frees up resources and allows for follow on connects if needed.

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

1 participant