SPC报警点

Navigation:  C++ > SPC管理接口 >

SPC报警点

Previous pageReturn to chapter overviewNext page

spc3_add_tag

spc3_add_tags

spc3_modify_tag_prop

spc3_modify_tags_prop

spc3_query_tag_prop

spc3_query_tags_cond

spc3_query_specify_page_tags_cond

 

SPC alarm tag

 

///*

 

#include "hdKingAPI.h"

#include "error_code.h"

#include "data_types.h"

#include "hd3Struct.h"

#include <stdio.h>

#include <string.h>

 

int main()

{

 int32 nRet = RD_SUCCESS;

 HD3Connection conn;

 HD3PtTagProp normalTag;

 HD3StatsTagProp statsTag;

 HD3SpcTagProp spcAlarmTagSave;

 HD3SpcTagProp spcAlarmTagQuery;

 HD3FilterItem pQueryTagPropItem[2];

 HD3HANDLE hIter = NULL;

 int32 nTagNum = 0;

 int32 nErrCode = 0;

 char (*szTagNames)[HD3_LEN_TAG_NAME] = NULL;

 uint32 nTagID = 0;

 

 //connect

 strcpy(conn.szAddress, "127.0.0.1");

 conn.nPort = 5673;

 conn.nTimeout = 3;

 nRet = nt3_connect(&conn);

 if (nRet != RD_SUCCESS)

 {

         printf("connect to server failed, error code[%d]!\n", nRet);

         return -1;

 }

 

 //login

 nRet = sc3_login("admin", "admin");

 if (nRet != RD_SUCCESS)

 {

         printf("login failed, error code[%d]!\n", nRet);

         return -1;

 }

 printf("login successful!\n");

 

 //add one normal tag as stats tag source tag

 strcpy(normalTag.szTagName, "szNormalTag");

 normalTag.nTagType = HD3_TAG_TYPE_INT32;

 HD3Mask mask;

 mask.nCommMask = HD3M_COMM_PROP_TAG_NAME | HD3M_COMM_PROP_TAG_TYPE;

 mask.nExtMask = 0;

 nRet = pt3_add_tag(&normalTag, &mask, "", &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("add tag[%s] failed, error code [%d]!\n", normalTag.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add tag[%s] successful!\n", normalTag.szTagName);

 

 //add statistics tag

 strcpy(statsTag.szTagName, "szStatsTag");

 strcpy(statsTag.szSourceTagName, normalTag.szTagName);

 statsTag.nScanPeriod = 60;

 statsTag.nStatsType = HD3_STATS_TYPE_ARITH_MEAN;

 statsTag.nSampleMode = HD3_STATS_SAMPLE_MODE_INTERVAL;

 statsTag.nSampleInterval = 3600;

 statsTag.nSampleStartDate = 1;

 statsTag.nSampleType = HD3_STATS_SAMPLE_TYPE_RAW;

 statsTag.nCalcPeriod = 0;

 

 HD3Mask smask;

 smask.nCommMask = HD3M_COMM_PROP_TAG_NAME;

 smask.nExtMask = HD3M_ST_EXT_PROP_SOURCE_TAG_NAME | HD3M_ST_EXT_PROP_SCAN_PERIOD

         | HD3M_ST_EXT_PROP_STATS_TYPE | HD3M_ST_EXT_PROP_SAMPLE_MODE

         | HD3M_ST_EXT_PROP_SAMPLE_INTERVAL | HD3M_ST_EXT_PROP_SAMPLE_START_DATE

         | HD3M_ST_EXT_PROP_SAMPLE_TYPE | HD3M_ST_EXT_PROP_CALC_PERIOD;

 

 nRet = st3_add_tag(&statsTag, &smask, "", &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("add stat tag[%s] failed, error code [%d]!\n", statsTag.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add tags[%s] successful!\n", statsTag.szTagName);

 

 //add one normal tag as spc tag ucl tag

 strcpy(normalTag.szTagName, "szUCLTag");

 normalTag.nTagType = HD3_TAG_TYPE_FLOAT32;

 nRet = pt3_add_tag(&normalTag, &mask, "", &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("add tag[%s] failed, error code [%d]!\n", normalTag.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add tag[%s] successful!\n", normalTag.szTagName);

 

 //add one normal tag as spc tag cl tag

 strcpy(normalTag.szTagName, "szCLTag");

 normalTag.nTagType = HD3_TAG_TYPE_FLOAT32;

 nRet = pt3_add_tag(&normalTag, &mask, "", &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("add tag[%s] failed, error code [%d]!\n", normalTag.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add tag[%s] successful!\n", normalTag.szTagName);

 

 //add one normal tag as spc tag lcl tag

 strcpy(normalTag.szTagName, "szLCLTag");

 normalTag.nTagType = HD3_TAG_TYPE_FLOAT32;

 nRet = pt3_add_tag(&normalTag, &mask, "", &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("add tag[%s] failed, error code [%d]!\n", normalTag.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add tag[%s] successful!\n", normalTag.szTagName);

 

 //add spc alarm tag

 memset(&spcAlarmTagSave, 0, sizeof(spcAlarmTagSave));

 strcpy(spcAlarmTagSave.szTagName, "szSPCAlarmTag_1");

 strcpy(spcAlarmTagSave.szSourceTagName, "szStatsTag");

 spcAlarmTagSave.nCtrlChartType = HD3_SPC_CTRL_CHART_TYPE_XBAR;

 strcpy(spcAlarmTagSave.szUCLTagName, "szUCLTag");

 strcpy(spcAlarmTagSave.szCLTagName, "szCLTag");

 strcpy(spcAlarmTagSave.szLCLTagName, "szLCLTag");

 spcAlarmTagSave.dUCLDefaultValue = 200;

 spcAlarmTagSave.dCLDefaultVaule = 100;

 spcAlarmTagSave.dLCLDefaultValue = 50;        

 

 HD3Mask spcmask;

 spcmask.nCommMask = HD3M_COMM_PROP_TAG_NAME;

 spcmask.nExtMask = HD3M_SPC_EXT_PROP_CTRL_CHART_TYPE | HD3M_SPC_EXT_PROP_SOURCE_TAG_NAME

         | HD3M_SPC_EXT_PROP_RULE;

 nRet = spc3_add_tag(&spcAlarmTagSave, &spcmask, "", &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("add spc tag[%s] failed, error code [%d]!\n", spcAlarmTagSave.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add spc tag[%s] successful!\n", spcAlarmTagSave.szTagName);

 

 memset(&spcAlarmTagSave, 0, sizeof(spcAlarmTagSave));

 strcpy(spcAlarmTagSave.szTagName, "szSPCAlarmTag_2");

 strcpy(spcAlarmTagSave.szSourceTagName, "szStatsTag");

 spcAlarmTagSave.nCtrlChartType = HD3_SPC_CTRL_CHART_TYPE_XBAR;

 strcpy(spcAlarmTagSave.szUCLTagName, "szUCLTag");

 strcpy(spcAlarmTagSave.szCLTagName, "szCLTag");

 strcpy(spcAlarmTagSave.szLCLTagName, "szLCLTag");

 spcAlarmTagSave.dUCLDefaultValue = 200;

 spcAlarmTagSave.dCLDefaultVaule = 100;

 spcAlarmTagSave.dLCLDefaultValue = 50;        

 

 nRet = spc3_add_tags(1, &spcAlarmTagSave, &spcmask, "", &nTagID, &nErrCode);

 if (nRet != RD_SUCCESS)

 {

         printf("add spc tag[%s] failed, error code [%d]!\n", spcAlarmTagSave.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("add spc tag[%s] successful!\n", spcAlarmTagSave.szTagName);

 

 //query spc tags by condition

 pQueryTagPropItem[0].nItemID = HD3_TAG_COL_COMM_PROP_TAG_NAME;

 pQueryTagPropItem[0].nRelation = HD3_RELATION_LIKE;

 strcpy(pQueryTagPropItem[0].szValue, "*");

 

 pQueryTagPropItem[1].nItemID = HD3_TAG_COL_COMM_PROP_TAG_TYPE;

 pQueryTagPropItem[1].nRelation = HD3_RELATION_EQUAL;

 sprintf(pQueryTagPropItem[1].szValue, "%d", HD3_TAG_TYPE_DIGITAL);

 

 HD3FilterItemSet fs;

 fs.nSize = 2;

 fs.pItem = &pQueryTagPropItem[0];

 

 nRet = tag3_query_tags_cond(HD3M_TAG_CLASS_SPC, &fs, HD3M_COMM_PROP_TAG_NAME, &hIter);

 if (nRet != RD_SUCCESS)

 {

         printf("query spc tags by condition failed, error code [%d]!\n", nRet);

         nt3_disconnect();

         return -1;

 }

 

 while (true)

 {

         nRet = ut3_get_item_step(hIter, &spcAlarmTagQuery);

         if (RD_SUCCESS == nRet)

         {

                 nTagNum ++;

                 printf("query spc tag successful, tag name is %s!\n", spcAlarmTagQuery.szTagName);

         }

         else if (EC_HD_API_QUERY_END == nRet)

         {

                 printf("query spc tag complete!\n");

                 break;

         }

         else

         {

                 printf("query spc tag failed, error code [%d]!\n", nRet);

                 break;

         }

 }

 printf("you have queried %d spc alarm tags totally!\n", nTagNum);

 

 ut3_free_handle(hIter);

 

 //query tag number by condition

 nTagNum = 0;

 nRet = tag3_query_tag_num_cond(HD3_TAG_CLASS_SPC, &fs, &nTagNum);

 if (nRet != RD_SUCCESS)

 {

         printf("spc_query_tag_num_cond failed, error code [%d]!\n", nRet);

         nt3_disconnect();

         return -1;

 }

 printf("spc_query_tag_num_cond successful, tag number is %d!\n", nTagNum);

 

 HD3PageQueryTagParam pp;

 pp.itemSet = fs;

 pp.mask.nCommMask = HD3M_COMM_PROP_TAG_NAME;

 pp.nStartID = 0;

 pp.nCapacity = 20;

 

 //query page tag by condition

 nRet = spc3_query_specify_page_tags_cond(&pp, &hIter);

 if (nRet != RD_SUCCESS)

 {

         printf("spc_query_specify_page_tags_cond failed, error code [%d]!\n", nRet);

         nt3_disconnect();

         return -1;

 }

 nTagNum = 0;

 while (true)

 {

         nRet = ut3_get_item_step(hIter, &spcAlarmTagQuery);

         if (RD_SUCCESS == nRet)

         {

                 nTagNum ++;

                 printf("query spc tag successful, tag name is %s!\n", spcAlarmTagQuery.szTagName);

         }

         else if (EC_HD_API_QUERY_END == nRet)

         {

                 printf("query spc tag complete!\n");

                 break;

         }

         else

         {

                 printf("query spc tag failed, error code [%d]!\n", nRet);

                 break;

         }

 }

 printf("you have queried %d spc tags totally!\n", nTagNum);

 

 ut3_free_handle(hIter);

 

 

 //query tag id

 nRet = tag3_query_id_by_name(spcAlarmTagSave.szTagName, &nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("query spc alarm tag id failed,  alarm spc name[%s], error code[%d]!\n", spcAlarmTagSave.szTagName, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("spc alarm tag[%s] query tag id successful,  alarm tag id[%d]!\n",  spcAlarmTagSave.szTagName, nTagID);

 

 //modify tag desc

 strcpy(spcAlarmTagSave.szDescriptor, "spc tag descriptor is modified");

 spcAlarmTagSave.bRule1 = true;

 spcAlarmTagSave.nRule1M = 10;

 HD3Mask spcnmask;

 spcnmask.nExtMask = HD3M_SPC_EXT_PROP_RULE;

 spcnmask.nCommMask = HD3M_COMM_PROP_DESCRIPTOR;

 nRet = spc3_modify_tag_prop(nTagID, &spcAlarmTagSave, &spcnmask);

 if (nRet != RD_SUCCESS)

 {

         printf("modify spc tag failed, tag id[%d], error code[%d]!\n", nTagID, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("modify spc tag successful, tag id[%d]!\n", nTagID);

 

 //modify tag desc

 strcpy(spcAlarmTagSave.szDescriptor, "spc tag descriptor is modified");

 spcAlarmTagSave.bRule1 = true;

 spcAlarmTagSave.nRule1M = 10;

 mask.nExtMask = HD3M_SPC_EXT_PROP_RULE;

 mask.nCommMask = HD3M_COMM_PROP_DESCRIPTOR;

 nRet = spc3_modify_tags_prop(1, &nTagID, &spcAlarmTagSave, &spcnmask, &nErrCode);

 if (nRet != RD_SUCCESS)

 {

         printf("modify spc tag failed, tag id[%d], error code[%d]!\n", nTagID, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("modify spc tag successful, tag id[%d]!\n", nTagID);

 

 //query tag prop

 nRet = spc3_query_tag_prop(nTagID, &spcAlarmTagQuery);

 if (nRet != RD_SUCCESS)

 {

         printf("query spc tag prop failed, tag id[%d], error code[%d]!\n", nTagID, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("query spc tag prop successful, tag id[%d], tag name[%s], tag description[%s]!\n",

         spcAlarmTagQuery.nTagID, spcAlarmTagQuery.szTagName, spcAlarmTagQuery.szDescriptor);

 

 //delete spc tag

 nRet = tag3_delete_tag(nTagID);

 if (nRet != RD_SUCCESS)

 {

         printf("delete spc alarm tag failed, tag id[%d], error code[%d]!\n", nTagID, nRet);

         nt3_disconnect();

         return -1;

 }

 printf("delete spc alarm tag successful, tag id[%d]!\n", nTagID);

 

 nt3_disconnect();

 

 return 0;

}

 

//*/

 

//*/