차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
ko:bs2_enabledevicelicense [2023/03/02 15:53]
kkshin [샘플코드(C++)]
ko:bs2_enabledevicelicense [2023/03/02 15:54] (현재)
kkshin [샘플코드(C#)]
줄 100: 줄 100:
 </​file>​ </​file>​
 ==== 샘플코드(C#​) ==== ==== 샘플코드(C#​) ====
-<file csharp ​sample_setdebugfilelogex.cs> + 
-const string CURRENT_DIR ​= "​.";​ +<file csharp ​sample_bs2_enabledevicelicense.cs> 
-const int MAX_SIZE_LOG_FILE ​100 // 100MB + BS2LicenseBlob licenseBlob ​Util.AllocateStructure<​BS2LicenseBlob>​();​ 
-IntPtr ptrDir ​= Marshal.StringToHGlobalAnsi(CURRENT_DIR); + 
-result = (BS2ErrorCode)API.BS2_SetDebugFileLogEx(Constants.DEBUG_LOG_OPERATION_ALLConstants.DEBUG_MODULE_ALLptrDirMAX_SIZE_LOG_FILE); + Console.WriteLine("Try adding a license"​);​ 
-Marshal.FreeHGlobal(ptrDir); + 
-if (result != BS2ErrorCode.BS_SDK_SUCCESS) + Console.WriteLine("Enter the license type. (0: None, 1: Visual QR)")
-+ Console.Write(">>>>​ "); 
- Console.WriteLine("​Got error({0}).",​ result); + licenseBlob.licenseType ​Util.GetInput((UInt16)BS2LicenseType.VISUAL_QR_MASK); 
- return+ 
-}+ 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(sdkContextdeviceID, ref licenseBlobout resultObjout 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>​ </​file>​
 +