Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:bs2_querydevicelicense [2023/02/28 14:49]
mwkim created
en:bs2_querydevicelicense [2023/03/02 16:11] (current)
kkshin
Line 44: Line 44:
 ==== Sample Code(C++) ==== ==== Sample Code(C++) ====
  
-<file cpp sample_setdebugfilelogex.cpp> +<file cpp sample_bs2_querydevicelicense.cpp> 
-const char* CURRENT_DIR = "​.";​ +int getDeviceLicense(void* contextBS2_DEVICE_ID id)
-const int MAX_SIZE_LOG_FILE = 100;  // 100MB +
-int sdkResult = BS2_SetDebugFileLogEx(DEBUG_LOG_ALLDEBUG_MODULE_ALL,​ CURRENT_DIR,​ MAX_SIZE_LOG_FILE);​ +
-if (BS_SDK_SUCCESS != sdkResult)+
 { {
- printf("BS2_SetDebugFileLogEx call failed%d", sdkResult);​ + DeviceControl dc(context);​ 
- return;+ BS2LicenseBlob licenseBlob = { 0, }; 
 + vector<​BS2LicenseResult>​ licenseResult;​ 
 + int sdkResult = BS_SDK_SUCCESS;​ 
 + 
 + BS2_LICENSE_TYPE licenseType = (BS2_LICENSE_TYPE)Utility::​getInput<​uint32_t>​("Enter the license type. (0None, 1: Visual QR)"); 
 + sdkResult = dc.queryDeviceLicense(idlicenseType,​ licenseResult);​ 
 + if (BS_SDK_SUCCESS == sdkResult
 + DeviceControl::​print(licenseResult); 
 + 
 + return ​sdkResult;
 } }
-</​file>​ 
  
-==== Sample Code (C#) ==== +int DeviceControl::​queryDeviceLicense(BS2_DEVICE_ID idBS2_LICENSE_TYPE licenseTypevector<​BS2LicenseResult>&​ licenseResult)
-<file csharp sample_setdebugfilelogex.cs>​ +
-const string CURRENT_DIR = "​.";​ +
-const int MAX_SIZE_LOG_FILE = 100;  // 100MB +
-IntPtr ptrDir = Marshal.StringToHGlobalAnsi(CURRENT_DIR);​ +
-result = (BS2ErrorCode)API.BS2_SetDebugFileLogEx(Constants.DEBUG_LOG_OPERATION_ALLConstants.DEBUG_MODULE_ALLptrDir, MAX_SIZE_LOG_FILE);​ +
-Marshal.FreeHGlobal(ptrDir);​ +
-if (result != BS2ErrorCode.BS_SDK_SUCCESS)+
 { {
- Console.WriteLine("Got error({0}).", ​result); + BS2LicenseResult* result = NULL; 
- return;+ uint32_t numOfResult = 0; 
 + int sdkResult = BS2_QueryDeviceLicense(context_, id, licenseType,​ &​result,​ &​numOfResult);​ 
 + if (BS_SDK_SUCCESS != sdkResult) 
 + { 
 + TRACE("​BS2_QueryDeviceLicense call failed: %d", sdkResult);​ 
 + return sdkResult;​ 
 + } 
 + 
 + licenseResult.clear()
 + for (uint32_t idx = 0; idx < numOfResult;​ idx++) 
 +
 + licenseResult.push_back(result[idx]); 
 +
 + 
 + return ​sdkResult;
 } }
 </​file>​ </​file>​
 +
 +==== Sample Code(C#) ====
 +
 +<file csharp sample_bs2_querydevicelicense.cs>​
 + Console.WriteLine("​Trying to get a license"​);​
 +
 + Console.WriteLine("​Enter the license type. (0: None, 1: Visual QR)");
 + Console.Write(">>>>​ ");
 + UInt16 licenseType = Util.GetInput((UInt16)BS2LicenseType.VISUAL_QR_MASK);​
 +
 + IntPtr resultObj = IntPtr.Zero;​
 + UInt32 numOfResult = 0;
 +
 + BS2ErrorCode result = (BS2ErrorCode)API.BS2_QueryDeviceLicense(sdkContext,​ deviceID, licenseType,​ out resultObj, out numOfResult);​
 +
 + if (BS2ErrorCode.BS_SDK_SUCCESS != result)
 + {
 + Console.WriteLine("​Got error({0}).",​ result);
 + }
 + else
 + {
 + IntPtr curResult = resultObj;
 + int resultSize = Marshal.SizeOf(typeof(BS2LicenseResult));​
 + for (UInt32 idx = 0; idx < numOfResult;​ idx++)
 + {
 + BS2LicenseResult item = (BS2LicenseResult)Marshal.PtrToStructure(curResult,​ typeof(BS2LicenseResult));​
 + print(item,​ idx);
 + curResult += resultSize;
 + }
 +
 + API.BS2_ReleaseObject(resultObj);​
 + }
 +</​file>​
 +