⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apisnap.c

📁 PI 数据库 C 源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------

  $Archive: /PI/clients/piapi/apisnap/apisnap.c $

-------------------------------------------------------------------------------

Copyright (c) 1995-2000 OSI Software, Inc. All rights reserved. 
Unpublished - rights reserved under the copyright law of the United States.

USE OF A COPYRIGHT NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION 
OR DISCLOSURE.

THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE SECRETS OF 
OSI SOFTWARE, INC.  USE, DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT 
THE PRIOR EXPRESS WRITTEN PERMISSION OF OSI SOFTWARE, INC.

RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the Government is subject to restrictions 
as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and 
Computer Software clause at DFARS 252.227.7013

OSI Software, Inc.
777 Davis Street, Suite 250, San Leandro CA 94577

-------------------------------------------------------------------------------

Description:

   apisnap.c
   Example PI API program      

-------------------------------------------------------------------------------

History:

$Log: /PI/clients/piapi/apisnap/apisnap.c $

27    06-04-27 14:31 Charlie
string termination for input tagname over bounds [10918OSI8]

26    03-01-20 9:36 Charlie
Error for snapshot/archive call was not returned correctly.

25    12/17/01 2:04p Ray
Added casts of integer arguments to 'printf' so that %ld and %d are
used only with 'int' and 'long', respectively. Added temp variables as
necessary for 'sscanf' calls. Introduced '%lu' for output of unsigned
longs. (PLI: 1656OSI8)

24    01/04/18 15:02 Charlie
Snapshot status used instead of archive for archive printout. Only
noticed on non-digitals with an istat set.

23    00/10/25 2:23p Charlie
Added retrieval of display digits for floating point value output.
Formatted print accordingly.

22    8/01/00 4:22p Ray
Changed retrieval of last archive value to use piar_getarcvaluex to get
a recent value, and then use its timestamps to bound the call to
piar_getarcvaluesx. This fixes a problem in UDA mapped points in which
the foreign system can't handle the wide time constraint.

21    8/01/00 1:36a Ray
Replaced C++ comment with C comment.

20    8/01/00 1:34a Ray
Restored original method of finding previous archive value (using
piar_getvaluex) inside ifdef _ARCVALUE. Technique of finding last two
years of data with value count of 2 tends to break UDA mapped points
when foreign systems cannot honor value count before time range.

19    4/26/:0 9:37a Charlie
Added unix variations of identification strings used with the 'what'
command. 

18    4/06/00 7:29p Charlie
Added VSS id strings for file revision.

17    4/06/00 7:27p Charlie
Fixed printout of archive value timestamp. Made more useful routines
for printing values.

16    3/10/00 1:58p Charlie
Changed time output to check returned PI2time for bad value (-1) and
set to zero if bad. Changed format string to use int cast of fraction. 

15    12/17/99 6:18p Charlie
Added PI_Type_PItimestamp and PI2.

14    11/03/99 4:25p Charlie
Use ifdef hpux_main for HP C compiler.  

13    11/03/99 3:46p Charlie
Added new compiler define of _main for HPUX C/C++ _main. 

12    6/18/99 10:32a Piadmin
Eliminate compiler warnings (HPUX didn't like initializing two
variables  on the same line). 

11    6/08/99 3:29p Charlie
Changed archive retrieval to start from the snapshot time and search
backward in time until the next archive value is found.  This allows
the snapshot and last archive values to have the same timestamp.  Added
multiple tagnames on the command line.

10    5/06/99 1:17p Charlie
Added newline after all output.

9     2/01/99 5:27p Charlie
Remove ANSIC compiler warning for strlen compare.

8     1/25/99 9:23a Charlie
Added option to enter point number instead of tagname.  Leading
backslash is used to indicate point number.

7     9/04/98 1:12p Charlie

6     9/04/98 10:54a Charlie
Added printout of flags if set.

5     8/26/98 5:07p Charlie
Format time string subseconds and type casts in mem-functions.

3     8/26/98 3:22p Charlie
Added support for extended pointtypes and digital strings up to 80
chars. Added option to enter server and tagname arguments which will
retrieve one snapshot, then exit.  Updated copyright.

2     4/25/97 8:49a Harry
Check in Jon's changes on SCCS from Feb 5

-------------------------------------------------------------------------------
24-nov-93  jhp  use pitm_delay for delays
04-may-94  jhp  added reconnection loop
09=may-94  jhp  added version print  
13-jun-96  jhp  exit if cannot connect
17-jun-96  jhp  tagpreferred, added piar_value
05-Feb-97  jhp  better data representation on failed getsnap and arcvalue
-----------------------------------------------------------------------------*/ 

#ifdef WIN32
#pragma comment(exestr, "$Workfile: apisnap.c $ $Revision: 27 $")
#elif defined(aix)
#pragma comment(user, "@(#)$Workfile: apisnap.c $ $Revision: 27 $")
#elif defined(hpux)
#pragma VERSIONID "@(#)$Workfile: apisnap.c $ $Revision: 27 $"
#else/* solaris, osf1 */
#pragma ident "@(#)$Workfile: apisnap.c $ $Revision: 27 $"
#endif

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

#include <string.h>

#include "piapix.h"

#define TAG_LEN 80

typedef struct
{
   char tagname[TAG_LEN+1];
   int32 point;
   char descriptor[27];   
   char engunit[32];
   int32 display_prec;
   PIvaluetype pt_typex;
   float64 rval, arcrval;
   int32  ival, arcival;
   void  *bval, *arcbval;
   uint32 bsize, arcbsize;
   int32  istat, arcistat;
   int16  flags, arcflags;
   PITIMESTAMP ts, arcts;
} TAG;

static int dosnap ( char * );
static int32 lastdayofmonth ( int32 month );
static void print_taginfo ( TAG *tag );

#define MAXTRYS 20
#ifndef TRUE
#define TRUE -1
#endif
#ifndef FALSE
#define FALSE 0
#endif

int main ( int argc, char **argv )
{
   int32 result = 1;
   int  i, trys = 0;
   int32 connection = FALSE;
   char name[32], address[32];
   char version[32];
   char tname[TAG_LEN+1];
   
   /* The line below for the HPUX C compiler when linking with C++.  */
#ifdef hpux_main
   _main();
#endif

   if ( !piut_getapiversion ( version, sizeof(version) ) )
   {
      printf ( "\nPI-API version %s", version );
   }
   
   while ( TRUE )
   {
      if ( argc > 1 )
      {  /*  attempt connection to passed node name */
         piut_setprocname ( "snap" );
         printf ( "\n Attempting connection to %s", argv[1] );
         while ( result && trys < MAXTRYS )
         {
            trys++;
            result = piut_setservernode ( argv[1] );
            if ( result )
            {
               printf ( "\n Error %ld, connecting to %s", (long)result, argv[1] );
               return result;
            }
            else
            {
               connection = TRUE;
            }
         }
      }
      else  /*  attempt connection to default homenode */
      {   
         printf ( "\n Attempting connection to Default homenode" );
         while ( result && trys < MAXTRYS )
         {
            trys++;
            result = piut_connect ( "snap" );
            if ( result )
            {
               printf ( "\n Error %ld, connecting to Default homenode", (long)result );
               return result;
            }
            else      
            {             
               if ( piut_netserverinfo ( name, 32, address, 
                  32, &connection ) )
               {
                  printf ( "\nConnected to DEFAULT pihome node" );
                  connection = TRUE;
               }
               else
               {
                  printf ( "\nConnected to %s (%s)", name, address );
               }
            }
         }  
      }
      if ( !connection )
      {
         printf ( "\nError %ld connecting to PI Server node", result );
         exit (1);
      }
      if (argc > 2)
      {
         /* Cycle through all tags after the host name. */
         for (i=2; i<argc; i++)
         {
            strncpy(tname, argv[i], TAG_LEN);
            tname[TAG_LEN] = '\0';
            if ( dosnap( tname ) )
            {
               trys = 0;
               result = 1;
               connection = FALSE;
               printf ( "\nConnection lost attempting reconnection" );
               break;
            }
         }
         break;
      } else {
         tname[0] = '\0';
         if ( dosnap ( tname ) )
         {
            trys = 0;
            result = 1;
            connection = FALSE;
            printf ( "\nConnection lost attempting reconnection" );
         }
         else    
            break;
      }
   }
   piut_disconnect();
   return 0;
}

#define BUFSIZE  1024
static int dosnap ( char *tname )
{
   int32 result, reterr, pt_count;
   int len, once_len;
   float64 *pSnapDval, *pArcDval;
   int32   *pSnapIval, *pArcIval;
   void    *pSnapBval = NULL;
   void    *pArcBval = NULL;
   uint32  tmp_bsize;
   TAG tag;
   tag.bsize = 0;
   tag.arcbsize = 0;
   tag.bval = NULL;
   tag.arcbval = NULL;
   
   strcpy(tag.tagname, tname);
   once_len = strlen( tag.tagname );
   len = once_len;
   while ( TRUE )
   {
      if ( len > 0 )   
      {
         if (tag.tagname[0] == '\\')
         {
            tag.point = atoi( &tag.tagname[1] );
            result = 0;
         }
         else
            result = pipt_findpoint (tag.tagname, &tag.point );
         switch ( result )
         {
         default:
            printf ( "\npipt_findpoint error %ld, tag %s", 
               result, tag.tagname );
            piut_disconnect();
            return -1;
         case -5:
         case -2:
            printf ( "\nTag %s does not exist", tag.tagname );
            break;               
         case 0:
            result = pipt_tagpreferred ( tag.point, tag.tagname, TAG_LEN+1 );
            if ( result )
            {
               printf ( "\npipt_tag %ld", result );
            }
            result = pipt_descriptor ( tag.point, tag.descriptor, 27 );
            if ( result )
            {
               printf ( "\npipt_descriptor %ld", result );
               tag.descriptor[0] = '\0';
            }
            result = pipt_engunitstring ( tag.point, tag.engunit, 32 );
            if ( result )
            {
               printf ( "\npipt_engunitstring %ld", result );
               tag.engunit[0] = '\0';
            }
            result = pipt_pointtypex ( tag.point, &tag.pt_typex );
            if ( result )
            {
               printf ( "\npipt_pointtypex %ld", result );
               tag.pt_typex = PI_Type_bad;
            }
            result = pipt_displaydigits(tag.point, &tag.display_prec);
            if ( result )
            {
               printf ( "\npipt_displaydigits %ld", result );
               tag.display_prec = -5;
            }
            tag.rval = (float) 0.0;
            switch (tag.pt_typex ) {
            case PI_Type_PIstring:
            case PI_Type_blob:
            case PI_Type_PItimestamp:
               pSnapDval = pArcDval = NULL;
               pSnapIval = pArcIval = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -