查询实时记录(多点查询)com_sn_query_snapshots_c

Navigation:  功能明细 > 数据接口 > COM接口 > VC接口 >

查询实时记录(多点查询)com_sn_query_snapshots_c

Previous pageReturn to chapter overviewNext page

函数

STDMETHOD(com_sn_query_snapshots_c)(

LONG nRecNum,

SAFEARRAY* nTagIDs,

SAFEARRAY** records,

SAFEARRAY** nErrCodes

);

 

参数

[in] LONG nRecNum, 查询的实时记录的数量,不能超过65535

[in]SAFEARRAY(LONG) nTagIDs, TagID数组

[out]SAFEARRAY(Com_hdRecord)*records,,实时数据数组

[out]SAFEARRAY(LONG)* nErrCodes,错误码数组

 

返回值

查询成功,返回RD_SUCCESS,不是所有的都成功返回EC_HD_API_QUERY_SNAPSHOTS_FAILED。查询失败返回其它错误码,见error_code.h。

 

说明

查询实时记录(多点查询)函数。通过TagID数组查询多个Tag的内存快照中的最新记录。

返回RD_SUCCESS,表示所有的内存快照都查询成功;返回EC_HD_API_QUERY_SNAPSHOTS_FAILED,表明不是所有查询都成功;返回其它错误码表明查询失败,具体的错误码保存在nErrorCode数组中。

 

举例

 

images_copycode!MISSING PHRASE 'COPYCODE'!

HRESULT hr ;

   

     int nNum = 3;

     LONG* plIDBuf = new LONG[nNum];

 

     BSTR szIP = ::SysAllocString( L"127.0.0.1" );

     BSTR szBalIP = ::SysAllocString( L"1.1.1.1" );

     LONG nPort = 5678;

     LONG nBakPort = 1234;

     LONG nTimeOut = 3;

   

     hr = m_pabc->com_nt_connect_c(szIP, nPort, nBakIP, nBakPort, nTimeOut);

     if (hr != S_OK)

     {

          return;

     }

 

     // 组织传入数据

     for(int i = 0; i < nNum; ++i)

     {

          plIDBuf[i] = i+1;

     }

 

     // 将数据通过VARIANT的SAFEARRAY数组传入。其中m_varBuffer为VARIANT类型

     SAFEARRAY * pSA;

     SAFEARRAYBOUND sabRSarray[1];  // A one-dimensional array.

     sabRSarray[0].cElements=nNum;       // Two elements.

     sabRSarray[0].lLbound=0;         //Lower bound of array.

     pSA=SafeArrayCreate(VT_I4,1, sabRSarray);

     if(pSA==NULL)

     {

          return;

     }

 

     LONG i = 0;

     LONG nSum=1;

     SafeArrayPutElement(pSA, &i, &nSum);

     i++;

     nSum=2;

     SafeArrayPutElement(pSA, &i, &nSum);

     i++;

     nSum=1000;

     SafeArrayPutElement(pSA, &i, &nSum);

 

 

     //传出数据的变量

     SAFEARRAY* pSaRecords = NULL;

     SAFEARRAY* pSaErrCodes = NULL;

   

     hr = m_pabc->com_sn_query_snapshots_c( nNum, pSA, &pSaRecords, &pSaErrCodes);

     if (hr != S_OK && hr != 119610)

     {

          return;

     }

 

     //获取传出的record

     Com_hdRecord *pcomrecord = NULL;

     hr = SafeArrayAccessData(pSaRecords, (void HUGEP **)&pcomrecord);

     if(hr != S_OK)

     {

          return;

     }

 

     //释放内部BSTR数据

     LONG LBound;

     LONG UBound;

     SafeArrayGetLBound(pSaRecords, 1, &LBound);

     SafeArrayGetUBound(pSaRecords, 1, &UBound);

 

     for(LONG i = LBound;  i<= UBound; i++)

     {

          ::SysFreeString( pcomrecord[i-LBound].value );

     }

 

     //获取传出的Errorcode

     LONG *pErrBuf = NULL;

     hr = SafeArrayAccessData(pSaErrCodes, (void**)&pErrBuf);

     if(hr != S_OK)

     {

          return;

     }

 

     hr = m_pabc->com_nt_disconnect_c(hServerhandle);

     if (hr != S_OK)

     {

          return;

     }

 

     delete[] plIDBuf;

 

     SafeArrayDestroy(pSA);

     SafeArrayDestroy(pSaRecords);

     SafeArrayDestroy(pSaErrCodes);

     ::SysFreeString( szIP );

::SysFreeString( szBalIP );

 

 

©2015. All Rights Reserved.