== How Live Values Work ==
Live values are special properties without a value that is persisted in the database. Instead, they get their current value frequently from a live value server, including a measurement quality indicator and a read timestamp, among other details. Live values can be used to display trends and current values (e.g., sensor values) from dynamic sources like process control systems (e.g., via OPC-UA).
With the UBIK.Interface.Module.OPCUA plugin, {{UBIK}} will detect that there is a live value server and it will host a live value data service, supplying our "cooling unit" objects with their current "temperature" values.
== Implementing Live Values in {{UBIK}} Studio ==
First of all, download the UBIK.Interface.Module.OPCUA from the ''Augmensys Realease Portal/Plugins'' and copy them into the injections folder from your {{UBIK}} Studio as well as in the injection folder of the Web Service.
First of all, download the UBIK.Interface.Module.OPCUA from the ''Augmensys Realease Portal/Plugins'' and copy them into the injections folder from your {{UBIK}} Studio as well as in the injection folder of the Web Service.<br>
<br>
# Navigate to the [[MetaClass]] ''OPC_SERVER'' via the ''[[Class Browser]]''.<br/> [[File:OPCServer.PNG|330 px|border]]
# Add a new instance (OPC Server) to the [[MetaClass]] by using the [[Bulk Editor]].
== Accessing Live Values in {{UBIK}} Studio ==
Example how a LiveValue can be accessed within WhoBert for debugging purposes for example. Can also be adapted to be used within the database code customizing.
The first part of the code ensures that live value servers are initialized and running before attempting to retrieve live values.
Afterwards Live Value Information can be used as it retrieves and logs information about live values, such as their value, read timestamp, and age.
<source lang="csharp">
using System;
using System.Windows.Forms;
using UBIK.Kernel;
using UBIK.Runtime;
using UBIK.Runtime.Sys;
using UBIK.Compiler;
using System.Linq;
using UBIK.Interface;
using UBIK.Injection;
using System.Collections.Generic;
namespace Studio
{
public class ObjectTest
{
public void TestObject (params BaseClass[] InVariables)
{
Debugger.Output(this, "*** Started");
foreach (BaseClass obj in InVariables)
{
List<IUBIKLiveValueServer> servers = obj.Environment.GetInjectionManager().Plugins<IUBIKLiveValueServer>(TargetApplication.UBIK_WebService);
foreach (IUBIKLiveValueServer server in servers)
{
if (!server.GetStatus().Running)
{
server.InitLiveValueServer(obj.Environment);
server.Startup();
}
UBIK.Interface.LiveValues.ILiveValueInformation value;
//UID from the LiveValue Datapoint
if (server.TryGetLiveValue(new Guid("UID"), out value))
{
if (value.Value != null)
Debugger.Output(this, value.Value.ToString());
if (value.ReadTimeStamp != null)
Debugger.Output(this, value.ReadTimeStamp.ToString());
if (value.Age != null)
Debugger.Output(this, value.Age.ToString());
}
Debugger.Output(this, server.GetStatus().ToString());
}
}
Debugger.Output(this, "*** Finished");
}
}
}
</source>
=== ILiveValueInformation ===
The method TryGetLiveValue delivers LiveValueInformation objects:
<source lang="csharp">
namespace UBIK.Interface.LiveValues
{
public interface ILiveValueInformation
{
/// <summary>
/// Gets the value.
/// </summary>
/// <value>
/// The value.
/// </value>
object Value { get; }
/// <summary>
/// Gets the quality.
/// </summary>
/// <value>
/// The quality.
/// </value>
QualityTypes Quality { get; }
/// <summary>
/// Gets the quality description.
/// </summary>
/// <value>
/// The quality description.
/// </value>
string QualityDescription { get; }
/// <summary>
/// Gets the read time stamp.
/// </summary>
/// <value>
/// The read time stamp.
/// </value>
DateTime? ReadTimeStamp { get; }
/// <summary>
/// Gets the age.
/// </summary>
/// <value>
/// The age.
/// </value>
int? Age { get; }
}
}
</source>
Information can be also extended using:
<source lang="csharp">
namespace UBIK.Interface.LiveValues
{
public interface ILiveValueInformationV264 : ILiveValueInformation
{
/// <summary>
/// Attributes provides a possibility to add (any) information to a live value.
/// This gives us the possibility to hand over any back end server specific information to the client.
/// </summary>
/// <value>
/// The attributes.
/// </value>
UBIK.Service.DTO.V264.LiveValueAttribute[] Attributes { get; }
}
}
</source>
== See also ==
* [[Live_Values]]
* [[Plugins]]
* [[HowTo:Add a MetaProperty to a MetaClass]]
[[Category:How-To|Live Values]]