Mapping of the runtime function
This documentation describes how to read data from the Analytics format using the Analytics Data Exchange API.
License
A license for the "TwinCAT 3 Analytics Runtime" or "TwinCAT 3 Analytics Runtime Base" is required to read data from the TwinCAT Analytics format. The Data Exchange API can be tested with a 7-day license.
Create and configure a data source:
Factory = SourceFactory()
Builder = Factory.FromLiveStream(Broker, 1883)
Builder = Factory.FromFile(FilePath)
The different builders provide different methods for configuration. Symbols can be added using the "WithSymbol", "WithName" or "WithRegex" methods:
TestValue = UInt64("Variables.nGrowSteady")
Builder.WithSymbol(TestValue)
Builder.WithName("TestValues.nGrowSteady")
Builder.WithRegex("Variables.f", 0, RegexSymbolFilter.IncludeChilds)
Once the builder is fully configured, a new sink is created using the Build method. The data query starts by calling the Read method. A Callback method is passed as a parameter. If the sample does not contain any symbols, all data has already been read out. If the Callback method returns a value other than 0, the reading is aborted.
def Callback(sample : ISample) -> int:
if sample.Symbols() is not None:
print(f'Stamp = {sample.Timestamp()}, {sample.Symbols()[0].SymbolName()} = {sample.Symbols()[0].Value}')
Values.append(sample.Symbols()[0].Value)
Stamps.append(DateTimeToFileTime(sample.Timestamp()))
if len(Stamps) >= SampleCount:
return False
return True
Source.Read(Callback)
Sample:
The complete sample can be found here: SampleRuntime.zip