### BS2_SetMasterAdmin C++ Sample Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_setmasteradmin Example implementation of master admin enrollment in C++, including blob preparation and cleanup. ```cpp BS2UserFaceExBlob userBlob = { 0, }; BS2User& user = userBlob.user; if (BS_SDK_SUCCESS != (sdkResult = getUserBlobPINCode(userBlob.pin, deviceInfo))) return sdkResult; user.numFingers = 0; user.numCards = 0; user.numFaces = 0; if (faceExScanSupported) { if (BS_SDK_SUCCESS != (sdkResult = getUserBlobFaceInfoTemplateOnly(&userBlob.faceExObjs, user.numFaces, id, deviceInfoEx))) return sdkResult; } int sdkResult = BS2_SetMasterAdmin(context_, id, &userBlob); if (BS_SDK_SUCCESS != sdkResult) TRACE("BS2_SetMasterAdmin call failed: %d", sdkResult); if (userBlob.faceExObjs) { delete[] userBlob.faceExObjs; } return sdkResult; ``` -------------------------------- ### BS2_SetMasterAdmin C# Sample Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_setmasteradmin Example implementation of master admin enrollment in C#, utilizing structure allocation and memory management. ```csharp BS2ErrorCode sdkResult = BS2ErrorCode.BS_SDK_SUCCESS; BS2UserFaceExBlob userBlob = Util.AllocateStructure(); userBlob.user.numCards = 0; userBlob.user.numFingers = 0; userBlob.user.numFaces = 0; userBlob.cardObjs = IntPtr.Zero; userBlob.fingerObjs = IntPtr.Zero; userBlob.faceObjs = IntPtr.Zero; userBlob.faceExObjs = IntPtr.Zero; if (BS2ErrorCode.BS_SDK_SUCCESS != (sdkResult = getUserBlobPINCode(sdkContext, ref userBlob.pin))) return; if (BS2ErrorCode.BS_SDK_SUCCESS != (sdkResult = getUserBlobFaceExInfoTemplateOnly(sdkContext, deviceID, ref userBlob.faceExObjs, ref userBlob.user.numFaces))) return; Console.WriteLine("Trying to set master admin"); sdkResult = (BS2ErrorCode)API.BS2_SetMasterAdmin(sdkContext, deviceID, ref userBlob); if (BS2ErrorCode.BS_SDK_SUCCESS != sdkResult) Console.WriteLine("BS2_SetMasterAdmin call failed {0}", sdkResult); if (userBlob.faceExObjs != IntPtr.Zero) { Marshal.FreeHGlobal(userBlob.faceExObjs); } ``` -------------------------------- ### BS2_GetMasterAdmin C# Implementation Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_getmasteradmin Example usage of BS2_GetMasterAdmin in C#, demonstrating how to handle the user blob and release associated objects. ```C# BS2UserFaceExBlob userBlob; Console.WriteLine("Trying to get master admin"); BS2ErrorCode sdkResult = (BS2ErrorCode)API.BS2_GetMasterAdmin(sdkContext, deviceID, out userBlob); if (sdkResult != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0})." , sdkResult); return; } print(userBlob); if (userBlob.cardObjs != IntPtr.Zero) API.BS2_ReleaseObject(userBlob.cardObjs); if (userBlob.fingerObjs != IntPtr.Zero) API.BS2_ReleaseObject(userBlob.fingerObjs); if (userBlob.faceObjs != IntPtr.Zero) API.BS2_ReleaseObject(userBlob.faceObjs); if (userBlob.faceExObjs != IntPtr.Zero) API.BS2_ReleaseObject(userBlob.faceExObjs); ``` -------------------------------- ### BS2_GetAllLockOverride Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_getalllockoverride Gets all Lock Override information from the device. This function is available starting from version 2.9.12. ```APIDOC ## BS2_GetAllLockOverride ### Description Gets all Lock Override information from the device. This function is available starting from version 2.9.12. ### Declaration ```c #include "BS_API.h" int BS2_GetAllLockOverride(void* context, BS2_DEVICE_ID deviceId, BS2LockOverride** responseObj, uint32_t* numOfResponse); ``` ### Parameters - **context** (void*) - In - Context - **deviceId** (BS2_DEVICE_ID) - In - Device ID - **responseObj** (BS2LockOverride**) - Out - Pointer to receive Lock Override information - **numOfResponse** (uint32_t*) - Out - Number of Lock Override information ### Return Value Returns `BS_SDK_SUCCESS` when performed successfully, and returns the corresponding error code when an error occurs. ### Notes - The responseObj variable must return memory to the system through the BS2_ReleaseObject function after use. - Up to 8 Lock Overrides can be enrolled per user. - Up to 1,000 Lock Overrides can be enrolled per device. - Cards that can be used as Lock Override are CSN cards and Secure cards. ``` -------------------------------- ### BS2_InitializeEx Sample (C#) Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_initializeex Sample C# code from sample_bs2_initializeex.cs. It allocates the SDK context, reads the device IP address, calls API.BS2_InitializeEx, and handles failure by releasing the context. ```csharp public void initializeSDK() { sdkContext = API.BS2_AllocateContext(); if (sdkContext == IntPtr.Zero) { Console.WriteLine("Can't allocate sdk context."); return; } string deviceIpAddress = Console.ReadLine(); IntPtr ptrIPAddr = Marshal.StringToHGlobalAnsi(deviceIpAddress); BS2ErrorCode result = (BS2ErrorCode)API.BS2_InitializeEx(sdkContext, ptrIPAddr); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("SDK initialization failed with : {0}, {1}", result, deviceIpAddress); API.BS2_ReleaseContext(sdkContext); sdkContext = IntPtr.Zero; return; } } ``` -------------------------------- ### BS2_InitializeEx Sample (C++) Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_initializeex Sample C++ code from sample_bs2_initializeex.cpp. It allocates the context, reads the host address, calls BS2_InitializeEx, and cleans up if the call fails. ```cpp void initializeSDK() { void* context_ = BS2_AllocateContext(); string hostAddr = Utility::getInput("Please enter the host network address."); sdkResult = BS2_InitializeEx(context_, hostAddr.c_str()); if (BS_SDK_SUCCESS != sdkResult) { TRACE("BS2_InitializeEx call failed: %d", sdkResult); BS2_ReleaseContext(context_); context_ = NULL; } } ``` -------------------------------- ### BS2_GetLogFromDir Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_getlogfromdir Gets the maximum amount of logs starting from the given log record ID from storage path in device. ```APIDOC ## BS2_GetLogFromDir ### Description Gets the maximum amount of logs starting from the given log record ID from storage path in device. ### Declaration ```c #include "BS_API.h" int BS2_GetLogFromDir(void* context, const char* szDir, BS2_EVENT_ID eventId, uint32_t amount, BS2Event** logsObj, uint32_t* numLog); ``` ### Parameters - **context** (void*) - In - Context - **szDir** (const char*) - In - Storage path in device - **eventId** (BS2_EVENT_ID) - In - Log record ID. When the value is 0, gets the logs from the beginning. - **amount** (uint32_t) - In - Maximum number of logs. When the value is 0, gets the logs starting from the event ID. - **logsObj** (BS2Event**) - Out - Pointer to store the log record's address. - **numLog** (uint32_t*) - Out - Number of log record. ### Return Value If successfully done, `BS_SDK_SUCCESS` will be returned. If there is an error, the corresponding error code will be returned. ### Remarks - The logsObj variable needs to return the memory to the system by the BS2_ReleaseObject function after being used. ### See Also - BS2_AllocateUsbContext - BS2_ReleaseUsbContext - BS2_GetUserDatabaseInfoFromDir - BS2_GetUserListFromDir - BS2_GetUserInfosFromDir - BS2_GetUserDatasFromDir - BS2_GetUserInfosExFromDir - BS2_GetUserDatasExFromDir - BS2_GetLogBlobFromDir - BS2_GetFilteredLogFromDir ``` -------------------------------- ### Retrieve logs with BS2_GetLog and BS2_GetFilteredLog Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Aquick_guide Use BS2_GetLog to retrieve all logs and BS2_GetFilteredLog to retrieve logs within a specified time range. The example shows how to get logs from the last week and iterate through the results. Ensure to call BS2_ReleaseObject on the logs array after processing. ```c uint32_t deviceId = 1; BS2Event* logs = NULL; uint32_t numLogs = 0; uint32_t endTime = time(NULL); uint32_t startTime = endTime - 7*24*60*60; //last week // Get all logs int result = BS2_GetLog(context, deviceId, 0, 0, &logs, &numLogs); if(result == BS_SDK_SUCCESS) { uint32_t idx = 0; for(idx = 0 ; idx < numLogs ; idx++) { // TODO handle it } BS2_ReleaseObject(logs); } // Filtering logs result = BS2_GetFilteredLog(context, deviceId, NULL, 0, startTime, endTime, 0, &logs, &numLogs); if(result == BS_SDK_SUCCESS) { uint32_t idx = 0; for(idx = 0 ; idx < numLogs ; idx++) { // TODO handle it } BS2_ReleaseObject(logs); } ``` -------------------------------- ### BS2_Initialize context example Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Aquick_guide Shows the minimal C++ code to allocate and initialize the SDK context. It checks for allocation failure, initializes the context, and releases it at the end. Calling other SDK functions without initialization returns BS_SDK_ERROR_UNINITIALIZED. ```cpp int main(int argc, char* argv[]) { void* context = NULL; context = BS2_AllocateContext(); if(context != NULL) { int result = BS2_Initialize(context); if(result == BS_SDK_SUCCESS) { // do something ... } } else { printf("Out of memory\n"); } if(context != NULL) { BS2_ReleaseContext(context); } return 0; } ``` -------------------------------- ### BS2_InitializeEx Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_initializeex Initializes the SDK context and socket connection to the specified host IP address. Must be called before any device control API. ```APIDOC ## BS2_InitializeEx ### Description Initializes the context and initializes the socket with the IP address specified as the second argument. It must be called before calling the device control API. ### Declaration ```c int BS2_InitializeEx(void* context, const char* hostIPAddr); ``` ### Parameters - **context** (void*) - [In] Context - **hostIPAddr** (const char*) - [In] Host IP Address ### Return Value If successfully done, `BS_SDK_SUCCESS` will be returned. If there is an error, the corresponding error code will be returned. ### Sample Code (C++) ```cpp void initializeSDK() { void* context_ = BS2_AllocateContext(); string hostAddr = Utility::getInput("Please enter the host network address."); sdkResult = BS2_InitializeEx(context_, hostAddr.c_str()); if (BS_SDK_SUCCESS != sdkResult) { TRACE("BS2_InitializeEx call failed: %d", sdkResult); BS2_ReleaseContext(context_); context_ = NULL; } } ``` ### Sample Code (C#) ```csharp public void initializeSDK() { sdkContext = API.BS2_AllocateContext(); if (sdkContext == IntPtr.Zero) { Console.WriteLine("Can't allocate sdk context."); return; } string deviceIpAddress = Console.ReadLine(); IntPtr ptrIPAddr = Marshal.StringToHGlobalAnsi(deviceIpAddress); BS2ErrorCode result = (BS2ErrorCode)API.BS2_InitializeEx(sdkContext, ptrIPAddr); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("SDK initialization failed with : {0}, {1}", result, deviceIpAddress); API.BS2_ReleaseContext(sdkContext); sdkContext = IntPtr.Zero; return; } } ``` ``` -------------------------------- ### BS2_GetUserList example call Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Arelease_note_230 Example call to BS2_GetUserList passing null for the IsAcceptableUserID parameter. ```c BS2_GetUserList(context, deviceId, uidsObjs, numUid, null); ``` -------------------------------- ### BS2_GetUserDatasEx Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_getuserdatasex Gets selected data of user. You can get selected data of the user ID using userMask. ```APIDOC ## BS2_GetUserDatasEx ### Description Gets selected data of user. You can get selected data of the user ID using userMask. ### Declaration ```c #include "BS_API.h" int BS2_GetUserDatasEx(void* context, uint32_t deviceId, char* uids, uint32_t uidCount, BS2UserBlobEx* userBlob, BS2_USER_MASK userMask); ``` ### Parameters - **context** (void*) - In - Context - **deviceId** (uint32_t) - In - Device ID - **uids** (char*) - In - User ID list trying to get - **uidCount** (uint32_t) - In - Number of user ID - **userBlob** (BS2UserBlobEx*) - Out - Pointer to store the user information - **userMask** (BS2_USER_MASK) - In - User Mask ### User Mask Values | Value | Description | |---|---| | 0x0000 | User ID | | 0x0001 | User data | | 0x0002 | User setting | | 0x0004 | User name | | 0x0008 | Image | | 0x0010 | PIN | | 0x0020 | Card | | 0x0040 | Fingerprint | | 0x0080 | Face | | 0x0100 | Access group | | 0x0200 | Jobcode | | 0x0400 | User phrase(personal message) | | 0x0800 | Face (FaceStation F2) | | 0x1000 | User setting (FaceStation F2) | | 0xFFFF | All information | ### Return Value If successfully done, BS_SDK_SUCCESS will be returned. If there is an error, the corresponding error code will be returned. ### See Also - BS2_GetUserList - BS2_RemoveUser - BS2_RemoveAllUser - BS2_GetUserInfos - BS2_GetUserInfosEx - BS2_EnrolUser - BS2_EnrolUserEx - BS2_GetUserDatas - BS2_GetUserDatasEx ``` -------------------------------- ### BS2_FactoryReset Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_factoryreset This function initializes all configurations and the database on the specified device. It takes a context and device ID as input parameters and returns a success or error code. ```APIDOC ## BS2_FactoryReset ### Description Initializes all configurations and the database. ### Declaration ```c #include "BS_API.h" int BS2_FactoryReset(void* context, uint32_t deviceId); ``` ### Parameters - **context** (void*) - [In] Context - **deviceId** (uint32_t) - [In] Device ID ### Return Value If successfully done, `BS_SDK_SUCCESS` will be returned. If there is an error, the corresponding error code will be returned. ``` -------------------------------- ### BS2_GetServerPort Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Acommunication_api [+ 2.6.3] Gets the server Port. ```APIDOC ## BS2_GetServerPort ### Description [+ 2.6.3] Gets the server Port. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### BS2_GetDevices Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Acommunication_api Gets the managed device information. ```APIDOC ## BS2_GetDevices ### Description Gets the managed device information. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### C# Sample: Registering OSDP Device Status Listener Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_setosdpstandarddevicestatuslistener Creates a callback delegate and calls the API, then checks for BS_SDK_SUCCESS and prints an error message on failure. ```csharp cbOnOsdpStandardDeviceStatusChanged = new API.OnOsdpStandardDeviceStatusChanged(onOSDPStandardDeviceStatusChanged); BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetOsdpStandardDeviceStatusListener(sdkContext, cbOnOsdpStandardDeviceStatusChanged); if (BS2ErrorCode.BS_SDK_SUCCESS != result) Console.WriteLine("Got error({0}).", result); return result; ``` -------------------------------- ### BS2_GetFilteredLogSinceEventId Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Alog_management_api [Deprecated] Gets filtered logs from the device. ```APIDOC ## BS2_GetFilteredLogSinceEventId ### Description [Deprecated] Gets filtered logs from the device. ### Method N/A (SDK function) ### Endpoint N/A (SDK function) ### Parameters No parameters documented. ### Request Example No request example documented. ### Response #### Success Response No response fields documented. #### Response Example No response example documented. ``` -------------------------------- ### C++ Sample: getDeviceLicense and DeviceControl::queryDeviceLicense Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_querydevicelicense C++ sample code from sample_bs2_querydevicelicense.cpp. It prompts for a license type (0: None, 1: Visual QR), calls BS2_QueryDeviceLicense through DeviceControl::queryDeviceLicense, and prints the results on success. The wrapper copies the returned result array into a vector. ```cpp int getDeviceLicense(void* context, BS2_DEVICE_ID id) { DeviceControl dc(context); BS2LicenseBlob licenseBlob = { 0, }; vector licenseResult; int sdkResult = BS_SDK_SUCCESS; BS2_LICENSE_TYPE licenseType = (BS2_LICENSE_TYPE)Utility::getInput("Enter the license type. (0: None, 1: Visual QR)"); sdkResult = dc.queryDeviceLicense(id, licenseType, licenseResult); if (BS_SDK_SUCCESS == sdkResult) DeviceControl::print(licenseResult); return sdkResult; } int DeviceControl::queryDeviceLicense(BS2_DEVICE_ID id, BS2_LICENSE_TYPE licenseType, vector& licenseResult) { BS2LicenseResult* result = NULL; 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; } ``` -------------------------------- ### BS2_GetFilteredLog Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Alog_management_api [Deprecated] Gets filtered logs from the device. ```APIDOC ## BS2_GetFilteredLog ### Description [Deprecated] Gets filtered logs from the device. ### Method N/A (SDK function) ### Endpoint N/A (SDK function) ### Parameters No parameters documented. ### Request Example No request example documented. ### Response #### Success Response No response fields documented. #### Response Example No response example documented. ``` -------------------------------- ### BS2_SetCustomCardConfig C++ Sample Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_setcustomcardconfig A C++ implementation demonstrating how to retrieve device capabilities, fetch existing configuration, and update Mifare and DESFire custom card settings. ```cpp ConfigControl cc(context); DeviceControl dc(context); BS2DeviceCapabilities capabilies = { 0, }; BS2CustomCardConfig config = { 0, }; BS2_DEVICE_ID id = Utility::getSelectedDeviceID(device); int sdkResult = dc.getDeviceCapabilities(id, capabilies); if (BS_SDK_SUCCESS != sdkResult) return sdkResult; if (!capabilies.customSmartCardSupported) { TRACE("Not supported function."); return BS_SDK_ERROR_NOT_SUPPORTED; } sdkResult = cc.getCustomCardConfig(id, config); if (BS_SDK_SUCCESS != sdkResult) return sdkResult; string msg = "Please enter a data type of cards. (0: Binary, 1: ASCII, 2: UTF16, 3: BCS)"; config.dataType = (BS2_CARD_DATA_TYPE)Utility::getInput(msg); config.useSecondaryKey = Utility::isYes("Do you want to use secondary key?"); ostringstream oss; if (Utility::isYes("Do you want to change mifare custom card settings?")) { memset(&config.mifare.primaryKey, 0x0, sizeof(config.mifare.primaryKey)); oss << "Please enter the hexadecimal " << sizeof(config.mifare.primaryKey) << "-bytes primary key for mifare card." << endl; oss << " [Like 12 34 56 ... EF]" << endl; Utility::getLineHexaString(oss.str(), config.mifare.primaryKey, sizeof(config.mifare.primaryKey)); if (config.useSecondaryKey) { memset(&config.mifare.secondaryKey, 0x0, sizeof(config.mifare.secondaryKey)); oss.str(""); oss << "Please enter the hexadecimal " << sizeof(config.mifare.secondaryKey) << "-bytes secondary key for mifare card." << endl; oss << " [Like 12 34 56 ... EF]" << endl; Utility::getLineHexaString(oss.str(), config.mifare.secondaryKey, sizeof(config.mifare.secondaryKey)); } msg = "Please enter the start block index of mifare card."; config.mifare.startBlockIndex = (uint16_t)Utility::getInput(msg); msg = "Please enter the card data size of mifare card."; config.mifare.dataSize = (uint8_t)Utility::getInput(msg); msg = "Please enter the skip bytes of mifare card."; config.mifare.skipBytes = (uint8_t)Utility::getInput(msg); } if (Utility::isYes("Do you want to change desfire custom card settings?")) { msg = "Please enter a operation mode for desfire card. (0: Legacy, 1: Advanced(AppLevelKey))"; config.desfire.operationMode = (uint8_t)Utility::getInput(msg); if (DESFIRECARD_OPERATION_MODE_LEGACY == config.desfire.operationMode) { memset(&config.desfire.primaryKey, 0x0, sizeof(config.desfire.primaryKey)); oss.str(""); oss << "Please enter the hexadecimal " << sizeof(config.desfire.primaryKey) << "-bytes primary key for desfire card." << endl; oss << " [Like 12 34 56 ... EF]" << endl; Utility::getLineHexaString(oss.str(), config.desfire.primaryKey, sizeof(config.desfire.primaryKey)); if (config.useSecondaryKey) { memset(&config.desfire.secondaryKey, 0x0, sizeof(config.desfire.secondaryKey)); oss.str(""); oss << "Please enter the hexadecimal " << sizeof(config.desfire.secondaryKey) << "-bytes secondary key for desfire card." << endl; oss << " [Like 12 34 56 ... EF]" << endl; Utility::getLineHexaString(oss.str(), config.desfire.secondaryKey, sizeof(config.desfire.secondaryKey)); } } else // DESFIRECARD_OPERATION_MODE_APPLEVELKEY { memset(&config.desfire.desfireAppKey.appMasterKey, 0x0, sizeof(config.desfire.desfireAppKey.appMasterKey)); memset(&config.desfire.desfireAppKey.fileReadKey, 0x0, sizeof(config.desfire.desfireAppKey.fileReadKey)); memset(&config.desfire.desfireAppKey.fileWriteKey, 0x0, sizeof(config.desfire.desfireAppKey.fileWriteKey)); oss.str(""); oss << "Please enter the hexadecimal " << sizeof(config.desfire.desfireAppKey.appMasterKey) << "-bytes appMasterKey for desfire card." << endl; oss << " [Like 12 34 56 ... EF]" << endl; ``` -------------------------------- ### Enable Device License in C# (BS2_EnableDeviceLicense) Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_enabledevicelicense C# sample for enabling a device license using the BS2 SDK. It prompts for license type and device IDs, loads a license file, and calls API.BS2_EnableDeviceLicense. Handles memory allocation with Marshal and prints results or errors. ```csharp BS2LicenseBlob licenseBlob = Util.AllocateStructure(); 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 listID = new List(); 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); ``` -------------------------------- ### BS2_GetFilteredLog Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_getfilteredlog Gets all log records that match the given condition. Deprecated. ```APIDOC ## BS2_GetFilteredLog ### Description Gets all the log records that match the given condition. This API is deprecated. ### Declaration ```c #include "BS_API.h" int BS2_GetFilteredLog(void* context, uint32_t deviceId, char* uid, uint16_t eventCode, uint32_t start, uint32_t end, uint8_t tnakey, BS2Event** logsObj, uint32_t* numLog); ``` ### Parameters - **context** (void*) - [In] Context - **deviceId** (uint32_t) - [In] Device ID - **uid** (char*) - [In] User ID. When the value is NULL, it means all users. - **eventCode** (uint16_t) - [In] Log event code. When the value is 0, it means all events. - **start** (uint32_t) - [In] Filtered search start time. When the value is 0, it means there are no limitations. - **end** (uint32_t) - [In] Filtered search end time. When the value is 0, it means there are no limitations. - **tnakey** (uint8_t) - [In] TNA key. When the value is 0, it means all TNA keys. - **logsObj** (BS2Event**) - [Out] Pointer to store the log record's address. - **numLog** (uint32_t*) - [Out] Number of log records. ### Return Value If successfully done, BS_SDK_SUCCESS will be returned. If there is an error, the corresponding error code will be returned. ### Notes - The logsObj variable needs to return the memory to the system by the BS2_ReleaseObject function after being used. - This API is deprecated. It is recommended to use BS2_GetLog and BS2_StartMonitoringLog instead. ### See Also - BS2_GetLog - BS2_ClearLog ``` -------------------------------- ### C++ Sample for BS2_GetOsdpStandardConfig Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_getosdpstandardconfig C++ sample code for calling BS2_GetOsdpStandardConfig. It initializes a BS2OsdpStandardConfig structure, calls the API, and prints an error message if the call fails. ```cpp BS2OsdpStandardConfig config = { 0, }; int sdkResult = BS2_GetOsdpStandardConfig(context_, id, &config); if (BS_SDK_SUCCESS != sdkResult) printf("BS2_GetOsdpStandardConfig call failed: %d", sdkResult); return sdkResult; ``` -------------------------------- ### BS2_Version() Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_version Gets the version of the SDK. Returns the SDK version information as a string. ```APIDOC ## BS2_Version() ### Description Gets the version of the SDK. ### Declaration ```c #include "BS_API.h" const char* BS2_Version(); ``` ### Return Value Returns the SDK version information. ``` -------------------------------- ### C# Sample: BS2_SetVoipConfigExt Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_setvoipconfigext C# sample code from sample_setvoipconfigext.cs. It allocates a BS2VoipConfigExt structure, sets the same VoIP settings as the C++ example, and calls API.BS2_SetVoipConfigExt, printing an error message if the result is not BS_SDK_SUCCESS. ```csharp BS2VoipConfigExt config = Util.AllocateStructure(); config.enabled = Convert.ToByte(1); config.useOutboundProxy = Convert.ToByte(0); config.registrationDuration = 300; string strIpAddr = "192.168.0.9"; byte[] arrIpAddr = Encoding.UTF8.GetBytes(strIpAddr); Array.Clear(config.address, 0, BS2Environment.BS2_URL_SIZE); Array.Copy(arrIpAddr, 0, config.address, 0, arrIpAddr.Length); config.port = 5060; config.volume.speaker = 50; config.volume.mic = 50; string strSIPID = "myAccount"; byte[] arrSIPID = Encoding.UTF8.GetBytes(strSIPID); Array.Clear(config.id, 0, BS2Environment.BS2_USER_ID_SIZE); Array.Copy(arrSIPID, 0, config.id, 0, arrSIPID.Length); string strSIPPW = "myPassword"; byte[] arrSIPPW = Encoding.UTF8.GetBytes(strSIPPW); Array.Clear(config.password, 0, BS2Environment.BS2_USER_ID_SIZE); Array.Copy(arrSIPPW, 0, config.password, 0, arrSIPPW.Length); string strAuthCode = "1234"; byte[] arrAuthCode = Encoding.UTF8.GetBytes(strAuthCode); Array.Clear(config.authorizationCode, 0, BS2Environment.BS2_USER_ID_SIZE); Array.Copy(arrAuthCode, 0, config.authorizationCode, 0, arrAuthCode.Length); config.exitButton = Convert.ToByte('0'); // keypad 0 config.showExtensionNumber = Convert.ToByte(true); config.numPhoneBook = 2; string strPhoneNum = "600"; byte[] arrPhoneNum = Encoding.UTF8.GetBytes(strPhoneNum); Array.Clear(config.phonebook[0].phoneNumber, 0, BS2Environment.BS2_USER_ID_SIZE); Array.Copy(arrPhoneNum, 0, config.phonebook[0].phoneNumber, 0, arrPhoneNum.Length); string strPhoneDesc = "LB James"; byte[] arrPhoneDesc = Encoding.UTF8.GetBytes(strPhoneDesc); Array.Clear(config.phonebook[0].description, 0, BS2Environment.BS2_VOIP_MAX_DESCRIPTION_LEN_EXT); Array.Copy(arrPhoneDesc, 0, config.phonebook[0].description, 0, arrPhoneDesc.Length); strPhoneNum = "601"; arrPhoneNum = Encoding.UTF8.GetBytes(strPhoneNum); Array.Clear(config.phonebook[1].phoneNumber, 0, BS2Environment.BS2_USER_ID_SIZE); Array.Copy(arrPhoneNum, 0, config.phonebook[1].phoneNumber, 0, arrPhoneNum.Length); strPhoneDesc = "C Kershaw"; arrPhoneDesc = Encoding.UTF8.GetBytes(strPhoneDesc); Array.Clear(config.phonebook[1].description, 0, BS2Environment.BS2_VOIP_MAX_DESCRIPTION_LEN_EXT); Array.Copy(arrPhoneDesc, 0, config.phonebook[1].description, 0, arrPhoneDesc.Length); BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetVoipConfigExt(sdkContext, deviceID, ref config); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); } ``` -------------------------------- ### BS2_GetUserDatasFromDir Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_getuserdatasfromdir Gets User ID corresponding UserMask from storage path in device. ```APIDOC ## BS2_GetUserDatasFromDir ### Description Gets User ID corresponding UserMask from storage path in device. ### Declaration ```c #include "BS_API.h" int BS2_GetUserDatasFromDir(void* context, const char* szDir, char* uids, uint32_t uidCount, BS2UserBlob* userBlob, BS2_USER_MASK userMask); ``` ### Parameters - **context** (void*) - [In] Context - **szDir** (const char*) - [In] Storage path in device - **uids** (char*) - [In] User ID list trying to get - **uidCount** (uint32_t) - [In] Number of user ID - **userBlob** (BS2UserBlob*) - [Out] Pointer to store the user information - **userMask** (BS2_USER_MASK) - [In] User Mask #### User Mask Values | Value | Description | |-------|-------------| | 0x0000 | User ID | | 0x0001 | User data | | 0x0002 | User setting | | 0x0004 | User name | | 0x0008 | Image | | 0x0010 | PIN | | 0x0020 | Card | | 0x0040 | Fingerprint | | 0x0080 | Face | | 0x0100 | Access group | | 0x0200 | Job code | | 0x0400 | User phrase (personal message) | | 0x0800 | Face (FaceStation F2) | | 0x1000 | User setting (FaceStation F2) | | 0xFFFF | All information | ### Return Value If successfully done, `BS_SDK_SUCCESS` will be returned. If there is an error, the corresponding error code will be returned. ### See Also - BS2_GetUserDatabaseInfoFromDir - BS2_GetUserListFromDir - BS2_GetUserInfosFromDir - BS2_GetUserInfosExFromDir - BS2_GetUserDatasExFromDir ``` -------------------------------- ### BS2_ActivateFloor Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_activatefloor Documentation for the BS2_ActivateFloor function, which configures the priority of when the door gets activated. ```APIDOC ## BS2_ActivateFloor ### Description Configures the priority of when the door gets activated. The activate priority must be higher than the deactivate to activate the lift. ### Declaration ```c #include "BS_API.h" int BS2_ActivateFloor(void* context, uint32_t deviceId, BS2_FLOOR_FLAG flag, BS2_LIFT_ID liftID, uint16_t* floorIndexs, uint8_t floorIndexCount); ``` ### Parameters - **context** (void*) - [In] Context - **deviceId** (uint32_t) - [In] Device ID - **flag** (BS2_FLOOR_FLAG) - [In] Priority of the activate status to add - **liftID** (BS2_LIFT_ID) - [In] Lift ID - **floorIndexs** (uint16_t*) - [In] List of floor indexes - **floorIndexCount** (uint8_t) - [In] Number of floor indexes ### Return Value If successfully done, `BS_SDK_SUCCESS` will be returned. If there is an error, the corresponding error code will be returned. ### See Also - BS2_GetLift - BS2_GetAllLift - BS2_GetLiftStatus - BS2_GetAllLiftStatus - BS2_SetLift - BS2_SetLiftAlarm - BS2_RemoveLift - BS2_RemoveAllLift - BS2_ReleaseFloor - BS2_DeActivateFloor ``` -------------------------------- ### C++ sample: sample_getcustomcardconfig.cpp Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_getcustomcardconfig Complete C++ sample code from sample_getcustomcardconfig.cpp. It uses ConfigControl and DeviceControl to get device capabilities, checks customSmartCardSupported, retrieves the custom card config, and optionally scans a card. ```cpp ConfigControl cc(context); DeviceControl dc(context); BS2DeviceCapabilities capabilies = { 0, }; BS2CustomCardConfig config = { 0, }; BS2_DEVICE_ID id = Utility::getSelectedDeviceID(device); int sdkResult = dc.getDeviceCapabilities(id, capabilies); if (BS_SDK_SUCCESS != sdkResult) return sdkResult; if (!capabilies.customSmartCardSupported) { TRACE("Not supported function."); return BS_SDK_ERROR_NOT_SUPPORTED; } sdkResult = cc.getCustomCardConfig(id, config); if (BS_SDK_SUCCESS == sdkResult) ConfigControl::print(config); else return sdkResult; if (Utility::isYes("Do you want to scan card test?")) { UserControl uc(context); BS2Card cardID; sdkResult = uc.scanCard(id, &cardID); if (BS_SDK_SUCCESS == sdkResult) UserControl::print(cardID); } return sdkResult; ``` -------------------------------- ### BS2_GetAllDeviceIOStatus Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Alog_management_api [+ 2.9.12] Gets the current I/O port status of the device and slave devices. ```APIDOC ## BS2_GetAllDeviceIOStatus ### Description [+ 2.9.12] Gets the current I/O port status of the device and slave devices. ### Method N/A (SDK function) ### Endpoint N/A (SDK function) ### Parameters No parameters documented. ### Request Example No request example documented. ### Response #### Success Response No response fields documented. #### Response Example No response example documented. ``` -------------------------------- ### BS2_Initialize Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_initialize Initializes the SDK context. This function must be called before any device control API. ```APIDOC ## BS2_Initialize ### Description Initializes the context. This should be called before calling the device control API. ### Declaration ```c #include "BS_API.h" int BS2_Initialize(void* context); ``` ### Parameters - **context** (void*) - [In] Context ### Return Value - Returns `BS_SDK_SUCCESS` if successful. - Returns the corresponding error code if there is an error. ``` -------------------------------- ### C++ Sample: BS2_SetVoipConfigExt Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_setvoipconfigext C++ sample code from sample_setvoipconfigext.cpp. It populates a BS2VoipConfigExt structure with VoIP settings, including outbound proxy, registration duration, volume, SIP credentials, and phonebook entries, then calls BS2_SetVoipConfigExt and prints an error message on failure. ```cpp BS2VoipConfigExt config = { 0, }; config.enabled = true; config.useOutboundProxy = false; config.registrationDuration = 300; string ipAddr = "192.168.0.9"; memcpy(config.address, ipAddr.c_str(), ipAddr.size()); config.port = 5060; config.volume.speaker = 50; config.volume.mic = 50; string sipID = "myAccount"; memcpy(config.id, sipID.c_str(), sipID.size()); string sipPW = "myPassword"; memcpy(config.password, sipPW.c_str(), sipPW.size()); string authCode = "1234"; memcpy(config.authorizationCode, authCode.c_str(), authCode.size()); config.exitButton = '0'; // keypad 0 config.showExtensionNumber = true; config.numPhoneBook = 2; string phoneNum = "600"; memcpy(config.phonebook[0].phoneNumber, phoneNum.c_str(), phoneNum.size()); string phoneDesc = "LB James"; memcpy(config.phonebook[0].description, phoneDesc.c_str(), phoneDesc.size()); phoneNum = "601"; memcpy(config.phonebook[1].phoneNumber, phoneNum.c_str(), phoneNum.size()); phoneDesc = "C Kershaw"; memcpy(config.phonebook[1].description, phoneDesc.c_str(), phoneDesc.size()); int sdkResult = BS2_SetVoipConfigExt(context, id, &config); if (BS_SDK_SUCCESS != sdkResult) printf("BS2_SetVoipConfigExt call failed: %d", sdkResult); ``` -------------------------------- ### BS2_GetUserInfosExFromDirWithKey Source: https://kb.supremainc.com/bs2sdk/doku.php?id=en%3Abs2_getuserinfosexfromdirwithkey Gets the user information corresponding to the user identifier from the data extracted by USB. ```APIDOC ## BS2_GetUserInfosExFromDirWithKey ### Description Gets the user information corresponding to the user identifier from the data extracted by USB. ### Declaration ```c #include "BS_API.h" int BS2_GetUserInfosExFromDirWithKey(void* context, const char* szDir, char* uids, uint32_t uidCount, BS2UserBlobEx* userBlob, const BS2EncryptKey* key); ``` ### Parameters - **context** (void*) - [In] Context - **szDir** (const char*) - [In] Data storage path - **uids** (char*) - [In] List of user identifiers to be imported - **uidCount** (uint32_t) - [In] Number of user identifiers - **userBlob** (BS2UserBlobEx*) - [Out] Pointer to store user information - **key** (const BS2EncryptKey*) - [In] Encryption key and the key value specified by BS2_SetDataEncryptKey ### Return Value Returns `BS_SDK_SUCCESS` if performed successfully, or a corresponding error code if an error occurs. ### See Also - BS2_GetUserDatabaseInfoFromDirWithKey - BS2_GetUserListFromDirWithKey - BS2_GetUserInfosFromDirWithKey - BS2_GetUserDatasFromDirWithKey - BS2_GetUserDatasExFromDirWithKey - BS2_GetLogFromDirWithKey - BS2_GetLogBlobFromDirWithKey - BS2_GetFilteredLogFromDirWithKey ``` -------------------------------- ### C++ sample for BS2_GetAvailableOsdpStandardDevice Source: https://kb.supremainc.com/bs2sdk./doku.php?id=en%3Abs2_getavailableosdpstandarddevice C++ sample code demonstrating how to call BS2_GetAvailableOsdpStandardDevice. It initializes a BS2OsdpStandardDeviceAvailable structure, selects a device ID using Utility::selectDeviceID, calls the API, and prints an error message if the call fails. ```cpp BS2OsdpStandardDeviceAvailable osdpDevice = { 0, }; BS2_DEVICE_ID id = Utility::selectDeviceID(deviceList, false, false); int sdkResult = BS2_GetAvailableOsdpStandardDevice(context_, id, &osdpDevice); if (BS_SDK_SUCCESS != sdkResult) printf("BS2_GetAvailableOsdpStandardDevice call failed: %d", sdkResult); return sdkResult; ```