Collector Initialization Callbacks
The following are the callbacks used for a collector when it is initialized:
ihCollectorToolkitPreInitialize
ihCollectorToolkitInitialize
ihCollectorToolkitInitializeCompleted
When a collector is shutting down, ihCollectorToolkitShutdown
method is called and the collector performs all the necessary steps before it is completely shut down.
Example
The following sample program helps you understand the ihCollectorToolkitPreInitialize
function.
Historian expects Custom Collector Pre-Initialization information from the user. For example, custom collector can browse tags, collector type and so on.
/// </summary>
/// <param name="PreCfg">Collector Pre - Configuration information structure</param>
/// <param name="Cfg">Collector Configuration information structure</param>
void RandomValueSimulator::ihCollectorToolkitPreInitialize(ihInterfaceTKPreCfgInfo *PreCfg, ihInterfaceTKCfgInfo *Cfg)
{
// Initializes General1-5 values, here General1,2 were initialized with 1000, 60.
Cfg->CustomProp1 = TKStrdup(_T("1000"));
Cfg->CustomProp2 = TKStrdup(_T("60"));
// Historian follows representation of the collectors in the form of ComputerName_CollectorName, Tags in the form of ComputerName.TagName.
// In the following section custom collector is trying to get the computer name.
CString ComputerName, IP;
TKGetHostNameAndIP(ComputerName, IP);
if (ComputerName.GetLength() >; 0)
{
ComputerName.Append(_T("."));
wcscpy_s(Cfg->;DefaultTagPrefix, ComputerName.GetBuffer());
}
RandPreCfg = *PreCfg;
RandPreCfg.CanSendOPCQuality = TRUE; // to send OPC Quality
RandPreCfg.InterfaceType = ihTKCustom; // interface type
RandPreCfg.MultipleInstancesAllowed = FALSE;
RandPreCfg.MinimumInterval = RandMinimumInterval;
RandPreCfg.MaxTagsPerRead = MaxTagsPerGroup;
RandPreCfg.CanReadASync = TRUE;// to read tags Asynchronously
RandPreCfg.CanBrowseSource = TRUE;// you can browse the collector
RandPreCfg.CanSourceTimestamp = TRUE;// collector sends data containing source time stamp or server time stamp
RandPreCfg.ForceInputScaling = FALSE;
RandPreCfg.NeedMsgPump = FALSE;
RandPreCfg.ForcedScaleLO = 0.0; // Low engineering unit
RandPreCfg.ForcedScaleHI = (float) RAND_MAX;// High engineering unit
RandPreCfg.DoesReloadMode = FALSE;
RandPreCfg.DoesLagTimes = FALSE;
RandPreCfg.CanBrowseHierarchical = TRUE;
*PreCfg = RandPreCfg;
}
For the ihCollectorToolkitInitialize
function:
Collector Initialization
/// </summary>
/// <param name="Cfg">Collector Configuration information</param>
/// <param name="PreCfg">Collector Pre-Configuration Information</param>
/// <param name="ErrorMsg">Error Message while initializing</param>
/// <param name="ErrorMsgSize">Size of Error Message</param>
/// <param name="RegKeyName">modification required registry keys, if any </param>
/// <param name="Callbacks">Callbacks of all the asynchronous methods</param>
/// <param name="DoDebug">debug param</param>
/// <returns>status of the method call</returns>
int RandomValueSimulator::ihCollectorToolkitInitialize(ihInterfaceTKCfgInfo *Cfg,
ihInterfaceTKPreCfgInfo *PreCfg, wchar_t *ErrorMsg, int ErrorMsgSize, wchar_t *RegKeyName, ihCollectorToolkitCallback *Callbacks, int DoDebug)
{
// updates configuration information to collector
ihCollectorToolkitPropertyUpdate(Cfg);
TKFree(TagPrefix);
// Historian follows representation of Tags in the form of ComputerName.TagName.
TagPrefix = TKStrdup(Cfg->DefaultTagPrefix);
Cfg->DoOnFly = 1;
// Initializes error msg to ""(NULL)
ErrorMsg = TKStrdup(_T(""));
srand((unsigned) time(NULL));
RandCfg = *Cfg;
g_Callbacks = Callbacks;
return(TRUE);
}