Search code examples
c#dji-sdkbatterylevel

Get Real-time battery percentage Dji Drone


I'm trying to get access to the Battery percentage of my DJI drone using the windows SDK, but I'm not able to initialize the battery handler.

This is the API documentation https://developer.dji.com/api-reference/windows-api/Components/BatteryHandler.html

How can I initialize the batteryHandler?

DJI.WindowsSDK.Components.BatteryHandler batteryHandler = new DJI.WindowsSDK.Components.BatteryHandler();

What I should pass in the constructor? The documentation doesn't explain how to use it.

Best, Paolo


Solution

  • Quickly looking at the documentation you need to use the API through the DJISDKManagerclass

    "This class is the entry point for using the SDK with a DJI product. Most importantly, this class is used to register the SDK, and to connect to and access the product. This class also provides access to important feature managers. SDK Registration using must be successful before the SDK can be used with a DJI product."

    When you have this class you can use :

    DJISDKManager.ComponentManager.GetBatteryHandler(productIndex, componentIndex)
    

    see : https://developer.dji.com/api-reference/windows-api/Components/ComponentManager.html#componentmanager_getbatteryhandler_inline