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)