Using the Programming Interface

As described in the Technical Introduction a stream can be started and stopped from PLC code using Structured Text. For that, the streams of a data logger, themselves being TcCom-objects provide an interface called ITcAnalyticsStream comprising two methods, StartAnalyticsStream() and StopAnalyticsStream(). Follow the following steps to use the interface, the code samples may be useful, too:

Declare a variable of the type ITcAnalyticsStream and another one of the type OTCID for the object ID of the correspondent stream. For diagnostic purposes, an HRESULT variable is advisable.

HR : HRESULT := S_OK;
{attribute 'tcinitsymbol'}
oidPlcStream1 : OTCID;
ipPlcStream1 : ITcAnalyticsStream;

Next, add the attribute ‘tcinitsymbol’ above the OTCID variable. This way, it doesn’t need to be initialized statically in the source code, instead it be initialized at configuration time by double clicking the PLC instance node in the project tree and selecting the relevant stream in the combo box as illustrated in the following picture.

Using the Programming Interface 1:

After that, get an interface pointer using following the TcCom-object server method and the interface’s IID.

IF ipPlcStream1 = 0 AND oidPlcStream1 <> 0 THEN
    HR := FW_ObjMgr_GetObjectInstance(oidPlcStream1, IID_ITcAnalyticsStream, ADR(ipPlcStream1));
END_IF

Now you can use the interface pointer to call interface’s methods. As shown in the following example:

IF ipPlcStream1 <> 0 THEN
    IF bStartPlcStream1 THEN
        ipPlcStream1.StartAnalyticsStream();
        bStartPlcStream1 := FALSE;
    END_IF
    IF bStopPlcStream1 THEN
        ipPlcStream1.StopAnalyticsStream();
        bStopPlcStream1 := FALSE;
    END_IF
END_IF

The stream is started in the same cycle StartAnalyticsStream() is called and will include the logged variable values. The stream is stopped in the same cycle StopAnalyticsStream() is called but will not include the variable values of this cycle.

In the Samples section of this documentation you can find a sample program that includes the here presented code snippets.