Create my own input adapter with C#

Hi all,

I have a question about the input data adapter of the openECA platform.

I was trying to construct a new C# CSV adapter and a MySQL adapter for input in openECA. I was expecting that the GSF serial .dll references will provide similar framework we used in openPDC. However, the openPDC framework looks no longer available even though we are using the same GSF framework. I hope the application can be built as a .dll file and it can be reloaded on unloaded. I would like to know how can we do it. The code is attached.

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using GSF.TimeSeries;
using GSF.TimeSeries.Adapters;
using PhasorProtocolAdapters;
using GSF;

//using GSF.Units.EE;
using ReadWriteCSV;

namespace my_csv_adapter
{
/// <summary>
/// Read data from CSV file
/// </summary>
[Description("ReadCsvData : read data from a csv file")]
public class CSVAdapter
{

    #region [ Members ]
    int numberOfFrames = 0;
    int numberOfRows = 0;
    int numberOfColumns = 0;
    string[,] fdrFrequency = new string[2000, 2];
    #endregion

    #region[ Properties ]
    public override string Status
    {
        get
        {
            const int ValuesToShow = 4;

            StringBuilder status = new StringBuilder();

            status.AppendFormat("  Last " + ValuesToShow + " calculated angles:");
            status.AppendLine();
            status.Append(base.Status);

            return status.ToString();
        }
    }
    #endregion
    #region[ Methods ]

    public override void Initialize()
    {
        base.Initialize();
        OnStatusMessage("ReadCSV : Start Initialization");
        /// Read voltage phasor data from CSV file
        using (CsvFileReader reader = new CsvFileReader(@"C:\Program Files\openECA\Server\20070328FDR2FDR7.csv"))
        {
            CsvRow row = new CsvRow();
            while (reader.ReadRow(row))
            {
                foreach (string s in row)
                {
                    numberOfColumns++;
                    if (numberOfColumns >= 7) // remove the timestamp columes
                        fdrFrequency[numberOfRows, numberOfColumns - 7] = s;

                }
                numberOfRows++;
                numberOfColumns = 0;

            }
        }

        /// Reset data indices
        //numberOfRows = 0;
        //numberOfColumns = numberOfColumns - 6; // remove the timestamp columes
        OnStatusMessage("ReadCSV : total number of fdrs: {0}", numberOfColumns);
        OnStatusMessage("ReadCSV : total number of rows: {0}", numberOfRows);
        OnStatusMessage("'ReadCSV' has been successfully initialized.");

    }

    protected override void PublishFrame(IFrame frame, int index)
    {


        /// Increment number of published frames
        numberOfFrames++;
        //OnStatusMessage("SampleDataSimulator : number of frame {0}", numberOfFrames);
        /// Reset frame counter
        if (numberOfFrames > numberOfRows) /// Change this
        {
            numberOfFrames = 0;
            OnStatusMessage("Output CSV data from the beginnning");
        }

        /// Prepare to clone the output measurements.
        IMeasurement[] outputMeasurements = OutputMeasurements;

        /// Create a list of IMeasurement objects
        List<IMeasurement> output = new List<IMeasurement>();

        for (int i = 0; i < 2; i++)
        {
            output.Add(Measurement.Clone(outputMeasurements[i],
                                Convert.ToDouble(fdrFrequency[numberOfFrames, i]),
                                                           frame.Timestamp));
        }
        //OnStatusMessage("output signal:{0}, {1}",output[0].Value,output[1].Value );
        /// Output the next measurement frame
        OnNewMeasurements(output);

    }
    #endregion
}
}

Many thanks!
Chen

The full adapter based framework is still available in the “openECA Server” components. The client side components are very different.

Hi Ritchie,

Thanks a lot! I will keep trying!

Best,
Chen