OTX-Runtime for DotNet  
Assembly Implementation

A DotNet Assembly implementation is a DotNet class which public elements can be bound to a certain OTX signature, see Mappable OTX Activities. Inside this class an arbitrary complexity can be implemented.

Note: The Assembly Implementation is the default implementation of IMeasureImplementation (see DefaultMeasureImplementation), IExternalServiceProviderImplementation (see DefaultExternalServiceProviderImplementation), IContextVariableImplementation (see ContextVariableImplementation) and IStateVariableImplementation (see StateVariableImplementation) delivered with the OTX runtime API.

The Assembly implementation supports the following OTX data types:

  • All simple data types (Boolean, Integer, Float, String)
  • ByteField
  • BlackBox
  • List which contains one of the listed data type in an arbitrary depth
  • Map which contains the listed data types in an arbitrary depth
  • Structure which contains the listed data types in an arbitrary depth
  • Enumeration
  • ResourceLocation

Mappable OTX Activities

The following OTX Signatures can be mapped to related objects inside a DotNet Assembly.

Signature Can be mapped to Activity to process in OTX
Measure.DeviceSignature Public method of a public class Measure.ExecuteDeviceService
ExternalServiceProvider.ConstructorSignature Public constructor of a public class ExternalServiceProvider.CreateProvider
ExternalServiceProvider.PopertyDeclaration Public property of a public class ExternalServiceProvider.SetProperty, GetProperty
ExternalServiceProvider.ServiceSignature Public method of a public class ExternalServiceProvider.ExecuteService
ExternalServiceProvider.EventSignature Public event of a public class ExternalServiceProvider.ServiceProviderEventSource

Assembly Code Example

The example shows the C# code of an assembly implementation. The full code is inside this Sample OTX-Mapping PTX with including Visual Studio Project, see folder Apps/OtxMappingSample.

Sample OTX-Mapping PTX

Another OTF Sample Solution for OTX-Mapping with Player (source code see folder \EmotiveSampleSolution\OtxMappingSample\OTX-Mapping)

Note: The assembly (APP) must be copied into ExternalAppPath.

To see the complete example click here to fold.

// C# complete example for an assembly implementation
// ==================================================
using System.Collections.Generic;
using System;
using System.Threading;
using System.Windows.Forms;
using System.ComponentModel;
namespace OtxMappingSample
{
public class Device1
{
#region fields
public delegate void DeviceEventHandler(string DeviceServiceName, string DeviceServiceOutParameterName, object DeviceServiceOutParameterValue);
public static event DeviceEventHandler DeviceEvent;
#endregion
#region ctors
public Device1()
{
}
#endregion
#region methods
public bool Service1(string message, string title)
{
return MessageBox.Show(message, title, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK;
}
public void Service2(MyStructure myStructure)
{
string message = "StringElement1 = " + myStructure.StringElement.ToString() +
"\nIntegerElement = " + myStructure.IntegerElement.ToString() +
"\nByteFieldElement = " + myStructure.ByteFieldElement.ToString() +
"\nListElement = " + myStructure.ListElement.ToString() +
"\nMapElement = " + myStructure.MapElement.ToString();
MessageBox.Show(message, "Structure Support", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
[Description("The simple data type DateTime can be mapped to OTX BlackBox data type")]
public string GetTimeNow()
{
return DateTime.Now.ToString();
}
[Description("The simple data type can be mapped to OTX BlackBox data type")]
public void DisplayString(string time)
{
if (time != null)
{
MessageBox.Show(time.ToString());
}
else
{
MessageBox.Show("Time is null");
}
}
public void FireDeviceEvent(string message, string title)
{
RaiseDeviceEvent(message, title, null);
}
public Dictionary<int, Dictionary<long, double>> FetchValues(int numberOfMeasurements, int numberOfValues, int sleep = 0)
{
Dictionary<int, Dictionary<long, double>> values = new Dictionary<int, Dictionary<long, double>>();
for (int i = 0; i < numberOfMeasurements; i++)
{
Dictionary<long, double> value = new Dictionary<long, double>();
long timestamp = Convert.ToInt64((new TimeSpan(DateTime.Now.Ticks)).TotalMilliseconds);
for (int j = 0; j < numberOfValues; j++)
{
value.Add(timestamp + j, Math.Sin((timestamp + j) / 1000));
}
values.Add(i, value);
}
Thread.Sleep(sleep);
return values;
}
private void RaiseDeviceEvent(string DeviceServiceName, string DeviceServiceOutParameterName, object DeviceServiceOutParameterValue)
{
if (DeviceEvent != null)
{
DeviceEvent(DeviceServiceName, DeviceServiceOutParameterName, DeviceServiceOutParameterValue);
}
}
#endregion
#region enums
public enum MainColors
{
Red,
Green,
Blue
}
#endregion
#region classes
[OtxStructure]
public class MyStructure
{
private string stringElement = "Hello World";
private int integerElement = 12;
private byte[] byteFieldElement = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
private List<int> listElement = new List<int> { 1, 2, 34 };
private Dictionary<string, string> mapElement = new Dictionary<string, string>() { { "1", "a" }, { "2", "b" } };
private MainColors enumElement = MainColors.Green;
[OtxStructureElement]
public string StringElement
{
get { return stringElement; }
set { stringElement = value; }
}
[OtxStructureElement]
public int IntegerElement
{
get { return integerElement; }
set { integerElement = value; }
}
[OtxStructureElement]
public byte[] ByteFieldElement
{
get { return byteFieldElement; }
set { byteFieldElement = value; }
}
[OtxStructureElement]
public List<int> ListElement
{
get { return listElement; }
set { listElement = value; }
}
[OtxStructureElement]
public Dictionary<string, string> MapElement
{
get { return mapElement; }
set { mapElement = value; }
}
[OtxStructureElement]
public MainColors EnumElement
{
get { return enumElement; }
set { enumElement = value; }
}
}
#endregion
#region attributes
[AttributeUsage(AttributeTargets.Method)]
internal class OtxCloseScreen : Attribute
{
}
[AttributeUsage(AttributeTargets.Method)]
internal class OtxHighlightScreen : Attribute
{
}
[AttributeUsage(AttributeTargets.Method)]
internal class OtxOpenScreen : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenIsOpen : Attribute
{
}
[AttributeUsage(AttributeTargets.Class)]
internal class OtxScreenSignature : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureInOutParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureInParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureOutParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureTermParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Event)]
internal class OtxScreenSignatureParameterValueChangedEvent : Attribute
{
}
[AttributeUsage(AttributeTargets.Class)]
internal class OtxStructure : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxStructureElement : Attribute
{
}
#endregion
}
}
@ None
The connection state will be ignored (default)

// C# short example for an assembly implementation
// ===============================================
namespace OtxMappingSample
{
public class Device1
{
// This method can be mapped
public bool Service1(string message, string title)
{
return MessageBox.Show(message, title, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK;
}
}
}