Skip to content

Pre release Algorithm Development Notes

J. Ritchie Carroll edited this page Jul 12, 2016 · 3 revisions
Writing to the main window takes time and when processing data at 30 times per second or faster, it is better to throttle output messages to keep from overwhelming the UI interface, for example:
namespace FS

open System.Linq
open ECAClientFramework
open FS.Model.GPA

module Algorithm =
    let UpdateSystemSettings() =
        SystemSettings.ConnectionString <- @"server=localhost:6190; interface=0.0.0.0"
        SystemSettings.FramesPerSecond <- 30
        SystemSettings.LagTime <- 3.0
        SystemSettings.LeadTime <- 1.0
    let mutable m_index : uint64 = 0UL
    let Execute(input : AllInput) : AllOutput =
        let output = new AllOutput()

        m_index <- m_index + 1UL

        // Only show a message every 60th item processed
        if m_index % 60UL = 0UL then
            MainWindow.WriteMessage("Processed " + m_index.ToString() + " values: IM*VM=" + (input.VIPair.Current.Magnitude * input.VIPair.Voltage.Magnitude).ToString() + ", Freq Avg=" + input.Frequencies.Values.Average().ToString())

        output

For openECA versions less than v0.1.37, run-time code logic errors will not automatically show up the main screen unless you redirect them there (see example below). Always change to the "Concentrator" tab and look at the "Messages" window for errors that have occurred in your algorithm that have not been trapped.
using System;
using System.Linq;
using ECAClientFramework;
using CS.Model.GPA;

namespace CS
{
    static class Algorithm
    {
        public static void UpdateSystemSettings()
        {
            SystemSettings.ConnectionString = @"server=localhost:6190; interface=0.0.0.0";
            SystemSettings.FramesPerSecond = 30;
            SystemSettings.LagTime = 3;
            SystemSettings.LeadTime = 1;
        }

        public static AllOutput Execute(AllInput input)
        {
            AllOutput output = new AllOutput();

            try
            {
                output.IMVMProduct = input.VIPair.Current.Magnitude * input.VIPair.Voltage.Magnitude;
                output.FreqAverage = input.Frequencies.Values.Average();

                MainWindow.WriteMessage($"IM*VM={output.IMVMProduct}, Freq Avg={output.FreqAverage}");
            }
            catch (Exception ex)
            {
                // Display exceptions to the main window
                MainWindow.WriteError(new InvalidOperationException($"Algorithm exception: {ex.Message}", ex));
            }

            return output;
        }
    }
}

When opening an IronPython project, sometimes the project file may fail to open when the solution is being loaded. To correct the issue, once the solution has loaded simply right-click on the project and select "Reload Project" and the project should now properly open.