Jump to: navigation, search

Changes


HowTo:Implementing Live Values

3,616 bytes added, 4 July
# Save the changes with {{key press|Ctrl|S}} or the save command.
 
== 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 ==
* [[Plugins]]