This project has moved and is read-only. For the latest updates, please go here.

C# Template:

private const string FilterExpression = "FILTER ActiveMeasurements WHERE "; // TODO: Complete filter expression.
private const string Server = "localhost:6165";                             // TODO: Enter valid hostname for openPDC server.

private void ProcessMeasurements(ICollection<IMeasurement> measurements)
{
    // TODO: Process measurements!
}

private void DisplayStatusMessage(string message)
{
}

private void ProcessException(Exception ex)
{
}

private void SubscribeToServer()
{
    // Advanced subscription settings.
    SubscriptionInfo info = new UnsynchronizedSubscriptionInfo(false)
    {
        FilterExpression = FilterExpression,

        UseCompactMeasurementFormat = true,
        IncludeTime = true,
        UseMillisecondResolution = false,
                
        Throttled = false,
        ProcessingInterval = -1,
        LagTime = 10.0D,
        LeadTime = 5.0D,

        UdpDataChannel = false,
        DataChannelLocalPort = 9500,
        UseLocalClockAsRealTime = false,
                
        StartTime = null,
        StopTime = null,
        WaitHandleNames = null,
        WaitHandleTimeout = 0,
        ExtraConnectionStringParameters = null
    };

    m_dataSubscriber.Subscribe(info);
}

private void ProcessMetadata(DataSet metadata)
{
}

private void RestartSubscriber()
{
    m_dataSubscriber.Stop();
    m_dataSubscriber.Dispose();
    StartSubscriber();
}

// Creates and starts the subscriber.
public void StartSubscriber()
{
    m_dataSubscriber = new DataSubscriber();
    m_dataSubscriber.ConnectionString = string.Format("server={0}", Server);
    m_dataSubscriber.ConnectionEstablished += (sender, args) => SubscribeToServer();
    m_dataSubscriber.NewMeasurements += (sender, args) => ProcessMeasurements(args.Argument);
    m_dataSubscriber.StatusMessage += (sender, args) => DisplayStatusMessage(args.Argument);
    m_dataSubscriber.ProcessException += (sender, args) => ProcessException(args.Argument);
    m_dataSubscriber.MetaDataReceived += (sender, args) => ProcessMetadata(args.Argument);
    m_dataSubscriber.ConnectionTerminated += (sender, args) => RestartSubscriber();
    m_dataSubscriber.Initialize();
    m_dataSubscriber.Start();
}

// Terminates the subscription.
public void StopSubscriber()
{
    m_dataSubscriber.Stop();
    m_dataSubscriber.Dispose();
}

private DataSubscriber m_dataSubscriber;

Last edited Aug 21, 2012 at 4:52 AM by staphen, version 2

Comments

No comments yet.