UInt32 id = Util.GetInputMasterOrSlaveID(deviceID); BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS; if (id == deviceID) // set key to master { BS2OsdpStandardDeviceSecurityKey keyInfo = Util.AllocateStructure(); Util.HighlightLine(">>>> Please enter the OSDP security key.", "security key"); Console.Write(">>>> "); string keyString = Console.ReadLine(); byte[] buff = Encoding.UTF8.GetBytes(keyString); Array.Clear(keyInfo.key, 0, BS2Environment.BS2_OSDP_STANDARD_KEY_SIZE); Array.Copy(buff, 0, keyInfo.key, 0, keyString.Length); IntPtr ptrKey = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BS2OsdpStandardDeviceSecurityKey))); Marshal.StructureToPtr(keyInfo, ptrKey, false); result = (BS2ErrorCode)API.BS2_SetOsdpStandardDeviceSecurityKey(sdkContext, id, ptrKey); Marshal.FreeHGlobal(ptrKey); } else { result = (BS2ErrorCode)API.BS2_SetOsdpStandardDeviceSecurityKey(sdkContext, id, IntPtr.Zero); } if (result != BS2ErrorCode.BS_SDK_SUCCESS) Console.WriteLine("Got error({0}).", result); else Console.WriteLine("Call success."); return result;