Two custom adapter examples

Hi. Beginner here. I would like to start my learning process by running the Two custom adapter examples described here openPDC/Developers_Two_Custom_Adapter_Examples.md at master · GridProtectionAlliance/openPDC · GitHub

I managed to Install Visual Studio, implement and build the sampledatasimulator.dll and CalculatePerUnitValue.dll. I copied the files to the openPDC installation folder along with ReadWriteCSV.dll
(openPDC/ReadWriteCSV.dll at master · GridProtectionAlliance/openPDC · GitHub)

I tried to add them as custom action adapter but they were not visible. I beleive i am missing something that’s related to the database (I chose to install SQLite for now)

Could you please explain in details the steps required to load the two custom adapters from this example into openPDC to be able to run them?

Thank you so much
Chantal

Hi Chantal,

That documentation appears to be quite old. I hope that you didn’t spend too much time trying to track down copies of TimeSeriesFramework.dll, TVA.Core.dll, and TVA.PhasorProtocols.dll. Assuming that you instead substituted GSF.TimeSeries.dll, GSF.Core.dll, and GSF.PhasorProtocols.dll from your openPDC installation, you’ve done the right thing.

I mention all this because the behavior you describe of your adapters not being visible when adding a custom action adapter typically occurs when the openPDC Manager encounters an exception when loading the adapter types from your assembly. The most common issue that causes this behavior would be mismatched GSF assembly versions. However, in this particular case, I would guess that the most likely cause is probably the fact that you downloaded ReadWriteCSV.dll from the internet.

Modern Windows operating systems will automatically mark files that are downloaded from the internet so they cannot be used in certain ways. In this particular case, the .NET Framework will throw an exception if you attempt to load a marked assembly into an application for security reasons. If you trust the ReadWriteCSV.dll library well enough to allow it to run code on your system, you can go to Properties on that dll file and select the option to “unblocks” the assembly, which will remove the mark of the web and allow you to load it into a .NET Framework application. Note that when you unblock the file, it must be in a location where it can be modified without administrator privileges because the Properties dialog will not request elevation.

Hope that helps.

Thanks,
Stephen

Hi Stephen,

Thank you for your kind response. Unfortunately I didn’t manage to have the custom adapters visible yet.

I did indeed replace the dlls with GSF.TimeSeries.dll, GSF.Core.dll but used PhasorProtocolAdapters.dll for the CalculatedMeasurementBase class that was in the example.

Below is the code for the SampleDataSimulator in the project I created in Visual Code 2022 using .NET 6.0

using GSF.TimeSeries;
using PhasorProtocolAdapters;
using ReadWriteCSV;

namespace SampleDataSimulator2
{
public class SampleDataSimulator2 : CalculatedMeasurementBase
{
int numberOfFrames = 0;
int numberOfRows = 0;
int numberOfColumns = 0;
string[,] voltagePhasorData = new string[100, 6];

    public override void Initialize()
    {
        base.Initialize();

        using (CsvFileReader reader = new CsvFileReader(@"F:\samplePhasorData.csv"))
        {
            CsvRow row = new CsvRow();
            while (reader.ReadRow(row))
            {
                foreach (string s in row)
                {
                    voltagePhasorData[numberOfRows, numberOfColumns] = s;
                    numberOfColumns++;
                }
            }

            numberOfRows = 0;
            numberOfColumns = 0;
            //obsolete
            //OnStatusMessage("'SampleDataSimulator2' has been successfully initialized.");
            //OnStatusMessage("'SampleDataSimulator' will begin to output simulated voltage phasors.");

        }
    }

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

        if (numberOfFrames > 99)
        {
            numberOfFrames = 0;
        }

        /// 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 < 6; i++)
        {
            output.Add(Measurement.Clone(outputMeasurements[i],
               Convert.ToDouble(voltagePhasorData[numberOfFrames, i]),
               frame.Timestamp));
        }

        /// Output the next measurement frame
        OnNewMeasurements(output);
        //throw new NotImplementedException();
    }
}

}

Hi Stephen,

I installed the latest night version of openPDC. Now when I copy my SampleDataSimulator3.dll into the openPDC installation folder, then open openPDC and try to “manage custom action adapter” it crashes…