차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
ko:bs2_enabledevicelicense [2023/02/09 16:17]
mashin 만듦
ko:bs2_enabledevicelicense [2023/03/02 15:54] (현재)
kkshin [샘플코드(C#)]
줄 5: 줄 5:
  
 ===== BS2_EnableDeviceLicense ===== ===== BS2_EnableDeviceLicense =====
-[+ 2.8.4] 라이선스를 활성화 시킬 장치들과,​ 라이선스 파일을 지정하여 장치 라이선스를 활성화 시킵니다. \\+[+ 2.9.1] 라이선스를 활성화 시킬 장치들과,​ 라이선스 파일을 지정하여 장치 라이선스를 활성화 시킵니다. \\
 마스터 장치 및 그와 연결된 슬레이브 장치들에 대한 일괄 지정이 가능하며,​ 활성화에 대한 장치별 결과는 outResultObj 및 outNumOfResult를 통해 반환됩니다. \\ 마스터 장치 및 그와 연결된 슬레이브 장치들에 대한 일괄 지정이 가능하며,​ 활성화에 대한 장치별 결과는 outResultObj 및 outNumOfResult를 통해 반환됩니다. \\
 이 기능은 장치가 라이선스 활성화 기능을 지원해야 하며, 현재 기능을 지원하는 장치 정보는 아래와 같습니다. \\ 이 기능은 장치가 라이선스 활성화 기능을 지원해야 하며, 현재 기능을 지원하는 장치 정보는 아래와 같습니다. \\
줄 41: 줄 41:
 ==== 샘플코드(C++) ==== ==== 샘플코드(C++) ====
  
-<file cpp sample_setdebugfilelogex.cpp> +<file cpp sample_bs2_enabledevicelicense.cpp> 
-const char* CURRENT_DIR = "​.";​ +int setDeviceLicense(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<​BS2_DEVICE_ID>​ deviceIDs;​ 
 + vector<​BS2LicenseResult>​ licenseResult;​ 
 + int sdkResult = BS_SDK_SUCCESS;​ 
 + 
 + licenseBlob.licenseType = (BS2_LICENSE_TYPE)Utility::​getInput<​uint32_t>​("Enter the license type. (0None, 1: Visual QR)"); 
 + licenseBlob.numOfDevices = (uint16_t)Utility::​getInput<​uint32_t>​("​How many devices do you want to register?"​);​ 
 + if (0 < licenseBlob.numOfDevices) 
 +
 + // Device ID 
 + for (uint16_t idx = 0; idx < licenseBlob.numOfDevices;​ idx++) 
 +
 + BS2_DEVICE_ID deviceID = (BS2_DEVICE_ID)Utility::​getInput<​uint32_t>​("​Enter a device ID:"​);​ 
 + deviceIDs.push_back(deviceID);​ 
 +
 + 
 + licenseBlob.deviceIDObjs = deviceIDs.data();​ 
 + 
 + string pathName = Utility::​getLine("​Enter the path and name of license."​);​ 
 + licenseBlob.licenseLen = Utility::​getResourceSize(pathName);​ 
 + shared_ptr<​uint8_t>​ buffer(new uint8_t[licenseBlob.licenseLen]ArrayDeleter<​uint8_t>​());​ 
 + if (0 < licenseBlob.licenseLen && Utility::​getResourceFromFile(pathName,​ buffer, licenseBlob.licenseLen)) 
 +
 + licenseBlob.licenseObj = buffer.get();​ 
 + 
 + sdkResult ​= dc.enableDeviceLicense(id,​ &​licenseBlob,​ licenseResult); 
 + if (BS_SDK_SUCCESS == sdkResult) 
 + DeviceControl::​print(licenseResult);​ 
 +
 +
 + 
 + return ​sdkResult;
 } }
-</​file>​ 
  
-==== 샘플코드(C#​) ==== +int DeviceControl::​enableDeviceLicense(BS2_DEVICE_ID idconst BS2LicenseBlob* licenseBlobvector<​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_EnableDeviceLicense(context_, id, licenseBlob,​ &​result,​ &​numOfResult);​ 
 + if (BS_SDK_SUCCESS != sdkResult) 
 + { 
 + TRACE("​BS2_EnableDeviceLicense 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>​
 +==== 샘플코드(C#​) ====
 +
 +<file csharp sample_bs2_enabledevicelicense.cs>​
 + BS2LicenseBlob licenseBlob = Util.AllocateStructure<​BS2LicenseBlob>​();​
 +
 + Console.WriteLine("​Try adding a license"​);​
 +
 + Console.WriteLine("​Enter the license type. (0: None, 1: Visual QR)");
 + Console.Write(">>>>​ ");
 + licenseBlob.licenseType = Util.GetInput((UInt16)BS2LicenseType.VISUAL_QR_MASK);​
 +
 + Console.WriteLine("​How many devices do you want to register?"​);​
 + Console.Write(">>>>​ ");
 + licenseBlob.numOfDevices = Util.GetInput((UInt16)1);​
 +
 + if (0 < licenseBlob.numOfDevices)
 + {
 + // Device ID
 + List<​UInt32>​ listID = new List<​UInt32>​();​
 + UInt32 tempID = 0;
 + for (UInt16 idx = 0; idx < licenseBlob.numOfDevices;​ idx++)
 + {
 + Console.WriteLine(" ​ Slave device ID #{0}", idx);
 + Console.Write(" ​ >> ");
 + tempID = (UInt32)Util.GetInput();​
 + listID.Add(tempID);​
 + }
 +
 + byte[] byteListID = listID.SelectMany(BitConverter.GetBytes).ToArray();​
 + int byteCount = Marshal.SizeOf(typeof(UInt32)) * licenseBlob.numOfDevices;​
 +
 + licenseBlob.deviceIDObjs = Marshal.AllocHGlobal(byteCount);​
 + Marshal.Copy(byteListID,​ 0, licenseBlob.deviceIDObjs,​ byteCount);
 +
 + // License data
 + Console.WriteLine("​Enter the path and name of license."​);​
 + Console.Write(">>>>​ ");
 + string licensePath = Console.ReadLine();​
 + if (!File.Exists(licensePath))
 + {
 + Console.WriteLine("​Invalid license Path"​);​
 + return;
 + }
 +
 + if (Util.LoadBinary(licensePath,​ out licenseBlob.licenseObj,​ out licenseBlob.licenseLen))
 + {
 + IntPtr resultObj = IntPtr.Zero;​
 + UInt32 numOfResult = 0;
 +
 + BS2ErrorCode result = (BS2ErrorCode)API.BS2_EnableDeviceLicense(sdkContext,​ deviceID, ref licenseBlob,​ out resultObj, out numOfResult);​
 + Marshal.FreeHGlobal(licenseBlob.licenseObj);​
 +
 + 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);​
 + }
 + } // if (Util.LoadBinary(licensePath,​ out licenseBlob.licenseObj,​ out licenseBlob.licenseLen))
 + } // if (0 < licenseBlob.numOfDevices)
 +
 + Marshal.FreeHGlobal(licenseBlob.deviceIDObjs);​
 +</​file>​
 +