Sample Programs Overview

Sample programs are provided with the Historian User API to demonstrate how to perform common tasks. The following sample programs are supplied with the User API:

  • CollectorLike.c: Shows an example of a program that writes thousands of samples per second to Historian tags.
  • CollectorLikeSAF.c: Shows an example of callbacks and store and forward in the User API.
  • PlotLike.cpp: Shows an example of a program that retrieves calculated and interpolated data suitable for plotting.
  • ReportLike.cpp: Shows how to retrieve raw data samples from Historian.
  • MigrationLike.c: Shows how to transfer legacy historical data into Historian.
  • QueryModifiers.c: Shows how to retrieve data using query modifiers.
  • Blobdatatype.c: Shows how to create tags of blob (binary object) data type and read and write data.
  • ByTag: Shows how to read and write data for a tag by using its tag ID instead of its tag name.

No guidance is provided on how to convert applications from other products or APIs, including the Historian SDK.

To work with these samples, you must be familiar with Historian features and functionality. Refer to the Historian Electronic Books for product information. This is especially important if you are using security groups with Historian, since the applications that call into the User API are limited by the security access granted at the server level.

Compiling the Samples

Only a release build configuration is provided. A debug configuration is not provided because the release mode configuration produces a program database and has compiler optimizations turned off, so that you can easily step through the sample code in the debugger.

Review the sample program source code for additional details.

Note: The sample programs provided in this help document are for review only. Compilable source code is included in the Historian User API installation directory.

CollectorLike

This sample demonstrates how to read string and numeric tag properties and write groups of data samples to multiple tags. Data is sent to the archiver until a key is pressed. Sample code is provided for writing data of various data types and data qualities. Tips are included for achieving optimal performance. This sample program also demonstrates how to iterate through all archiver tags to find tags that belong to the collector.

PlotLike

This sample program demonstrates how to read numeric tag properties and read evenly spaced sampled or calculated data suitable for plotting. Percent good data quality indicators are described. Any comments retrieved are printed to the program window. Finally, an example is provided for how to write a comment in cases where your trending application allows users to enter comments.

ReportLike

This sample program demonstrates how raw samples are retrieved, one tag per call, by timespan and by number of samples. Comments are retrieved if they exist. The retrieved samples can be used in custom quality calculations or to implement calculation modes not available in Historian. An example of how to calculate a raw maximum is provided. The program has a loop that fetches the current value of a tag until a key is pressed.

MigrationLike

This sample program demonstrates how to migrate data from a legacy system into Historian. Tips are provided for the most efficient sequence to use to send data to minimize archive disk space and migration time. This sample program also demonstrates how to add tags to the Historian server.