Manually Measure Temperature

When you enable the manual thermometry function of device, you can click any position on the interface to show the real temperature.

  • Make sure you have called NET_DVR_Init to initialize the development environment.

  • Make sure you have called NET_DVR_Login_V40 to log in to the device.

Figure 1 Programming Flow of Manually Measuring Temperature

  1. Call NET_DVR_GetSTDAbility with the command of NET_DVR_GET_MANUALTHERM_CAPABILITIES (command No.: 6707), and set condition parameter lpCondBuffer in the structure of NET_DVR_STD_ABILITY to 4-byte channel No. for getting the manual thermometry capability to check whether the device supports manual thermometry.

    The manual thermometry capability is returned in XML_Cap_ManualThermometry by the output parameter lpOutBuffer in the structure of NET_DVR_STD_ABILITY.

  2. Set manual thermometry basic parameters.
    1. Call NET_DVR_GetSTDAbility with the command of NET_DVR_GET_MANUALTHERM_BASIC_CAPABILITIES (command No.: 6715), and set condition parameter lpCondBuffer in the structure of NET_DVR_STD_ABILITY to 4-byte channel No. for getting the basic parameters configuration capability of manual thermometry.

      The basic parameters configuration capability of manual thermometry is returned in XML_Cap_ManualThermBasic by the output parameter lpOutBuffer in the structure of NET_DVR_STD_ABILITY.

    2. NET_DVR_GetSTDConfig with the command of NET_DVR_GET_MANUALTHERM_BASICPARAM (command No.: 6717) and set the condition parameter IpCondBuffer in the structure of NET_DVR_STD_CONFIG to 4-byte channel No. for getting the manual thermometry basic parameters for reference.

      The manual thermometry basic parameters NET_SDK_MANUALTHERM_BASICPARAM are returned by the output parameter lpOutBuffer in the structure of NET_DVR_STD_CONFIG.

    3. Call NET_DVR_SetSTDConfig with the command of NET_DVR_SET_MANUALTHERM_BASICPARAM (command No.: 6716), set the condition parameter IpCondBuffer and input parameter lpInBuffer in the structure of NET_DVR_STD_CONFIG to 4-byte channel No. and NET_SDK_MANUALTHERM_BASICPARAM for setting manual thermometry basic parameters.
  3. Call NET_DVR_SetSTDConfig with the command of NET_DVR_SET_MANUALTHERM (command No.: 6708), set the condition parameter IpCondBuffer and input parameter lpInBuffer in the structure of NET_DVR_STD_CONFIG to 4-byte channel No. and NET_SDK_MANUAL_THERMOMETRY for setting manual thermometry rules, including rule ID, detection type, and so on.
  4. Call NET_DVR_StartRemoteConfig with the command of NET_DVR_GET_MANUALTHERM_INFO (command No.: 6706) and set the input parameters lpInBuffer to NET_DVR_REALTIME_THERMOMETRY_COND.

    The manual thermometry result NET_SDK_MANUAL_THERMOMETRY is returned in callback function fRemoteConfigCallback.

  5. Call NET_DVR_StopRemoteConfig to disconnect the persistent connection to stop remote configuration, and release resources.

Sample Code of Manually Measuring Temperature

#include <stdio.h>
#include <iostream>
#include "Windows.h"
#include "HCNetSDK.h"
using namespace std;

//Macro Definition of temporal resolution
#define GET_YEAR(_time_)      (((_time_)>>26) + 2000) 
#define GET_MONTH(_time_)     (((_time_)>>22) & 15)
#define GET_DAY(_time_)       (((_time_)>>17) & 31)
#define GET_HOUR(_time_)      (((_time_)>>12) & 31) 
#define GET_MINUTE(_time_)    (((_time_)>>6)  & 63)
#define GET_SECOND(_time_)    (((_time_)>>0)  & 63)

int iNum=0;
#define ISAPI_OUT_LEN	3 * 1024 * 1024
#define ISAPI_STATUS_LEN  8*1024

void CALLBACK GetManualThermInfoCallback(DWORD dwType, void* lpBuffer, DWORD dwBufLen, void* pUserData)
{
    if (dwType == NET_SDK_CALLBACK_TYPE_DATA)
    {
        LPNET_SDK_MANUAL_THERMOMETRY lpManualThermometry = new NET_SDK_MANUAL_THERMOMETRY;
        memcpy(lpManualThermometry, lpBuffer, sizeof(*lpManualThermometry));

        NET_DVR_TIME struAbsTime = {0};
        struAbsTime.dwYear = GET_YEAR(lpManualThermometry->dwAbsTime);
        struAbsTime.dwMonth = GET_MONTH(lpManualThermometry->dwAbsTime);
        struAbsTime.dwDay = GET_DAY(lpManualThermometry->dwAbsTime);
        struAbsTime.dwHour = GET_HOUR(lpManualThermometry->dwAbsTime);
        struAbsTime.dwMinute = GET_MINUTE(lpManualThermometry->dwAbsTime);
        struAbsTime.dwSecond = GET_SECOND(lpManualThermometry->dwAbsTime);

        printf("Manual Temperature Measurement Result: dwChannel[%d]byThermometryUnit[d%]dwAbsTime[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d]\n",
            lpManualThermometry->dwChannel,	lpManualThermometry->byThermometryUnit, struAbsTime.dwYear, 
            struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, struAbsTime.dwSecond);       

        if (lpManualThermometry != NULL)
        {
            delete lpManualThermometry;
            lpManualThermometry = NULL;
        }
    }
    else if (dwType == NET_SDK_CALLBACK_TYPE_STATUS)
    {
        DWORD dwStatus = *(DWORD*)lpBuffer;
        if (dwStatus == NET_SDK_CALLBACK_STATUS_SUCCESS)
        {
            printf("dwStatus:NET_SDK_CALLBACK_STATUS_SUCCESS\n");            
        }
        else if (dwStatus == NET_SDK_CALLBACK_STATUS_FAILED)
        {
            DWORD dwErrCode = *(DWORD*)((char *)lpBuffer + 4);
            printf("NET_DVR_GET_MANUALTHERM_INFO failed, Error code %d\n", dwErrCode);
        }
    }
}

void main()
{
    DWORD dwChannel = 2;  //Thermal imaging channel

    char *m_pOutBuf = new char[ISAPI_OUT_LEN];
    memset(m_pOutBuf, 0, ISAPI_OUT_LEN);

    char *m_pStatusBuf = new char[ISAPI_STATUS_LEN];
    memset(m_pStatusBuf, 0, ISAPI_STATUS_LEN);

    //---------------------------------------
    //Initialize
    NET_DVR_Init();

    //Set connected time and reconnected time
    NET_DVR_SetConnectTime(2000, 1);
    NET_DVR_SetReconnect(10000, true);

    //---------------------------------------
    //Register device (it is not required when listening alarm)
    LONG lUserID;
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30("10.8.10.199 ", 8000, "admin", "abcd1234", &struDeviceInfo);
    if (lUserID < 0)
    {
        printf("Login error, %d\n", NET_DVR_GetLastError());
        NET_DVR_Cleanup(); 
        return;
    }

    //Capability sets of manual temperature measurement
    NET_DVR_STD_ABILITY struStdAbility = {0};
    struStdAbility.lpCondBuffer = &dwChannel;
    struStdAbility.dwCondSize = sizeof(DWORD);

    struStdAbility.lpOutBuffer    = m_pOutBuf;
    struStdAbility.dwOutSize      = ISAPI_OUT_LEN;
    struStdAbility.lpStatusBuffer = m_pStatusBuf;
    struStdAbility.dwStatusSize   = ISAPI_STATUS_LEN;

    if(!NET_DVR_GetSTDAbility(lUserID,NET_DVR_GET_MANUALTHERM_CAPABILITIES,&struStdAbility))
    {
        printf("NET_DVR_GET_MANUALTHERM_CAPABILITIES failed, error code: %d\n", NET_DVR_GetLastError());
    }
    else
    {
        printf("NET_DVR_GET_MANUALTHERM_CAPABILITIES is successful!");
    }

    //Configure basic parameter of manual temperature measurement
    NET_DVR_STD_CONFIG struStdConfig = {0};
    struStdConfig.lpCondBuffer = &dwChannel;
    struStdConfig.dwCondSize = sizeof(dwChannel);
    struStdConfig.lpInBuffer = NULL;
    struStdConfig.dwInSize = 0;

    NET_SDK_MANUALTHERM_BASICPARAM struManualThermBasicParam = {0};
    struStdConfig.lpOutBuffer = (LPVOID)&struManualThermBasicParam;
    struStdConfig.dwOutSize = sizeof(struManualThermBasicParam);

    struStdConfig.lpStatusBuffer = m_pStatusBuf;
    struStdConfig.dwStatusSize = ISAPI_STATUS_LEN;

    DWORD dwReturned=0;
    if(!NET_DVR_GetSTDConfig(lUserID,NET_DVR_GET_MANUALTHERM_BASICPARAM,&struStdConfig))
    {
        printf("NET_DVR_GET_MANUALTHERM_BASICPARAM failed, error code: %d\n", NET_DVR_GetLastError());
    }
    else
    {
        printf("NET_DVR_GET_MANUALTHERM_BASICPARAM is successful!");
    }

    struManualThermBasicParam.wDistance = 20; //Distance (m), ranging from 0 to 10000
    struStdConfig.lpInBuffer = (LPVOID)&struManualThermBasicParam;
    struStdConfig.dwInSize = sizeof(struManualThermBasicParam);
	
    if(!NET_DVR_SetSTDConfig(lUserID,NET_DVR_SET_MANUALTHERM_BASICPARAM,&struStdConfig))
    {
        printf("NET_DVR_SET_MANUALTHERM_BASICPARAM failed, error code: %d\n", NET_DVR_GetLastError());
    }
    else
    {
        printf("NET_DVR_SET_MANUALTHERM_BASICPARAM is successful!");
    }

    //Configure rule for manual temperature measurement
    NET_SDK_MANUAL_THERMOMETRY struManualTherm = {0};
    struManualTherm.dwSize = sizeof(struManualTherm);
    struManualTherm.dwChannel = dwChannel;
    struManualTherm.byThermometryUnit = 0; //Temperature unit: 0-Centigrade,1-Fahrenheit, 2-Kelvin
    struManualTherm.struRuleInfo.byRuleID = 1;
    struManualTherm.struRuleInfo.byEnable=1;
    strcpy(struManualTherm.struRuleInfo.szRuleName, "TestName");
    struManualTherm.struRuleInfo.byRuleCalibType = 0;
    struManualTherm.struRuleInfo.struPointTherm.struPoint.fX = 0.5; //Normalized value, ranging from 0.001 to 1.
    struManualTherm.struRuleInfo.struPointTherm.struPoint.fY = 0.5; //Normalized value, ranging from 0.001 to 1.

    struStdConfig.lpCondBuffer = &dwChannel;
    struStdConfig.dwCondSize = sizeof(dwChannel);
    struStdConfig.lpInBuffer = (LPVOID)&struManualTherm;;
    struStdConfig.dwInSize = sizeof(struManualTherm);

    if(!NET_DVR_SetSTDConfig(lUserID,NET_DVR_SET_MANUALTHERM,&struStdConfig))
    {
        printf("NET_DVR_SET_MANUALTHERM failed, error code: %d\n", NET_DVR_GetLastError());
    }
    else
    {
        printf("NET_DVR_SET_MANUALTHERM is successful!");
    }

    //Enable manual temperature measurement
    NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = {0};
    struThermCond.dwSize = sizeof(struThermCond);
    struThermCond.byRuleID = 1;       //Rule ID, 0-Get all rules, the rule ID starts from 1.
    struThermCond.dwChan = dwChannel; //Start from 1, 0xffffffff- Get all channels

    LONG ManualHandle = NET_DVR_StartRemoteConfig(lUserID, NET_DVR_GET_MANUALTHERM_INFO, &struThermCond, sizeof(struThermCond), GetManualThermInfoCallback, NULL);
    if (ManualHandle >= 0)
    {
        printf("NET_DVR_GET_MANUALTHERM_INFO failed, error code: %d\n", NET_DVR_GetLastError());
    }
    else
    {
        printf("NET_DVR_GET_MANUALTHERM_INFO is successful!");
    }

    Sleep(5000);  //Wait for receiving manual measurement result

    //Close the handle created by long connection configuration API, and release resource.
    if(!NET_DVR_StopRemoteConfig(ManualHandle))
    {
        printf("NET_DVR_StopRemoteConfig failed, error code: %d\n", NET_DVR_GetLastError());
    }

    //User logout, if the user is not login, skip this step.
    NET_DVR_Logout(lUserID);

    //Release SDK resource
    NET_DVR_Cleanup();

    if (m_pOutBuf != NULL)
    {
        delete []m_pOutBuf;
        m_pOutBuf = NULL;
    }

    if (m_pStatusBuf != NULL)
    {
        delete []m_pStatusBuf;
        m_pStatusBuf = NULL;
    }

    return;
}

Call NET_DVR_Logout and NET_DVR_Cleanup to log out and release the resources.