The example below shows how to import the DJI Windows SDK into a new UWP project. The same steps can be used for integrating into an existing application project.
Screenshots in this section are generated using Visual Studio 2017.
Create a New UWP Application
Open Visual Studio 2017.
Select File->New->Project.
Choose Blank App(Universal Windows) template.
Fill in the project name and choose the location of the project
Press OK.
"DJIWSDKDemo" will be used as the Project Name.
Choose the Target version and Minimum version
Import WSDK into the Project
Firstly, create a folder named "DJIWindowsSDK", and copy all the DJI Windows SDK library files in it.
Secondly, add reference of DJIWindowsSDK to your project.
a. Right-click on DJIWSDKDemo project, and select Add Reference.
b. Select Browse, and select DJIWindowsSDK.dll. Click Add.
c. Click OK.
Thirdly, add dll files of third parties to the project.
a. Copy dll files of third parties(pthread_dll.dll and libcrypto-1.1.dll, for x86) to the root path of the project
b. Right-click on DJIWSDKDemo project, select Add->Existing Item, and click the dlls needed.
Configure Properties
Right-click on the Solution 'DJIWSDKDemo', select Properties.
Make sure that the Platform configuration is suitable for DJI Windows SDK x86.
Double-click on Package.appxmanifest, select Packaging, and fill in the Package name with your application's package name. Here, we use "com.dji.wsdkdemo".
Configure serial port authority in order to connect the application to DJI Aircraft's remote controller. Right-click on Package.appxmanifest, select View Code, add the following code in the Capabilities element.
//Replace with your registered App Key. Make sure your App Key matched your application's package name on DJI developer center. DJISDKManager.Instance.RegisterApp("Please enter your App Key here."); }
//The product connection state will be updated when it changes here. DJISDKManager.Instance.ComponentManager.GetProductHandler(0).ProductTypeChanged += asyncdelegate (object sender, ProductTypeMsg? value) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { if (value != null && value?.value != ProductType.UNRECOGNIZED) { System.Diagnostics.Debug.WriteLine("The Aircraft is connected now."); //You can load/display your pages according to the aircraft connection state here. } else { System.Diagnostics.Debug.WriteLine("The Aircraft is disconnected now."); //You can hide your pages according to the aircraft connection state here, or show the connection tips to the users. } }); };
//If you want to get the latest product connection state manually, you can use the following code var productType = (await DJISDKManager.Instance.ComponentManager.GetProductHandler(0).GetProductTypeAsync()).value; if (productType != null && productType?.value != ProductType.UNRECOGNIZED) { System.Diagnostics.Debug.WriteLine("The Aircraft is connected now."); //You can load/display your pages according to the aircraft connection state here. } } else { System.Diagnostics.Debug.WriteLine("Register SDK failed, the error is: "); System.Diagnostics.Debug.WriteLine(resultCode.ToString()); } }
Run WSDK Demo
Internet connection is required to registration the application successfully. As this application is only demonstrating the registration process of DJI Windows SDK and not interact directly with a DJI product, so no need to connect to a DJI product to run this application.
If everything goes well, you should be able to see the following log in the popup window: Register app successfully.