Organize Tools folder and add the Dynamic Model Generator

v1.6
Maxson Ramon dos Anjos Medeiros 3 months ago
parent 7c74db0b34
commit 27cd8db5fe

@ -0,0 +1,59 @@
using IEC61850.SCL;
using IEC61850.SCL.DataModel;
using System;
using System.IO;
using System.Linq;
using System.Xml;
namespace DynamicModel
{
public class DynamicModel
{
public DynamicModel(string fileName, FileStream stream,
string iedName, string accessPointName)
{
try
{
SclDocument sclParser = new SclDocument(fileName);
SclIED ied = null;
if (iedName == null)
ied = sclParser.IEDs.First();
else
ied = sclParser.IEDs.Find(x => x.Name == iedName);
if (ied == null)
{
throw new Exception("IED model not found in SCL file! Exit.");
}
SclAccessPoint accessPoint = null;
if (accessPointName == null)
accessPoint = ied.AccessPoints.First();
else
accessPoint = ied.AccessPoints.Find(x => x.Name == accessPointName);
if (accessPoint == null)
{
throw new Exception("AccessPoint not found in SCL file! Exit.");
}
IEDDataModel iedModel = sclParser.GetDataModel(ied.Name, accessPoint.Name);
using (StreamWriter writer = new StreamWriter(stream))
{
DynamicModelGenerator dynamicModelGenerator = new DynamicModelGenerator(sclParser, writer, iedModel, accessPoint);
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
}
}

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\SCLParser\SCLParser.csproj" />
<ProjectReference Include="..\SCLParser\SCLParser.csproj" />
</ItemGroup>
</Project>

@ -1,37 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelGenerator", "ModelGenerator\ModelGenerator.csproj", "{FB5457AA-CE89-48BB-8F1F-2540DF894492}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelGeneratorExample", "ModelGeneratorExample\ModelGeneratorExample.csproj", "{A80ED62D-CCA9-4D8E-B04D-9BEA5CD7DF78}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SCLParser", "..\..\SCLParser\SCLParser.csproj", "{88069284-150D-4BAE-8C7B-140298C5C011}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FB5457AA-CE89-48BB-8F1F-2540DF894492}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB5457AA-CE89-48BB-8F1F-2540DF894492}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB5457AA-CE89-48BB-8F1F-2540DF894492}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB5457AA-CE89-48BB-8F1F-2540DF894492}.Release|Any CPU.Build.0 = Release|Any CPU
{A80ED62D-CCA9-4D8E-B04D-9BEA5CD7DF78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A80ED62D-CCA9-4D8E-B04D-9BEA5CD7DF78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A80ED62D-CCA9-4D8E-B04D-9BEA5CD7DF78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A80ED62D-CCA9-4D8E-B04D-9BEA5CD7DF78}.Release|Any CPU.Build.0 = Release|Any CPU
{88069284-150D-4BAE-8C7B-140298C5C011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88069284-150D-4BAE-8C7B-140298C5C011}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88069284-150D-4BAE-8C7B-140298C5C011}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88069284-150D-4BAE-8C7B-140298C5C011}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D5970CE-F389-4BCE-934E-F1E597AFEE22}
EndGlobalSection
EndGlobal

@ -1,102 +0,0 @@
/*
* Copyright 2013-2025 Michael Zillgith, MZ Automation GmbH
*
* This file is part of MZ Automation IEC 61850 SDK
*
* All rights reserved.
*/
using ModelGenerator;
namespace modeGenerator_example
{
/// <summary>
/// This example shows how to handle a large number of information objects
/// </summary>
class MainClass
{
public static void Main(string[] args)
{
string icdFile = "ICDFiles//simpleIO_ltrk_tests.icd";
string outputFileName = "static_model";
string accessPointName = null;
string iedName = null;
string modelPrefix = "iedModel";
bool initializeOnce = false;
Console.WriteLine("Usage: genmodel <ICD file> [-ied <ied-name>] [-ap <access-point-name>] [-out <output-name>] [-modelprefix <model-prefix>]");
if (args.Count() > 0)
{
icdFile = args[0];
for (int i = 1; i < args.Count(); i++)
{
if (args[i] == ("-ap"))
{
accessPointName = args[i + 1];
Console.WriteLine("Select access point " + accessPointName);
i++;
}
else if (args[i] == ("-ied"))
{
iedName = args[i + 1];
Console.WriteLine("Select IED " + iedName);
i++;
}
else if (args[i] == ("-out"))
{
outputFileName = args[i + 1];
Console.WriteLine("Select Output File " + outputFileName);
i++;
}
else if (args[i] == ("-modelprefix"))
{
modelPrefix = args[i + 1];
Console.WriteLine("Select Model Prefix " + modelPrefix);
i++;
}
else if (args[i] == ("-initializeonce"))
{
initializeOnce = true;
Console.WriteLine("Select Initialize Once");
}
else
{
Console.WriteLine("Unknown option: \"" + args[i] + "\"");
}
}
}
// Creating file streams
FileStream cOutStream = new FileStream(outputFileName + ".c", FileMode.Create, FileAccess.Write);
FileStream hOutStream = new FileStream(outputFileName + ".h", FileMode.Create, FileAccess.Write);
Console.WriteLine("Select ICD File " + icdFile);
try
{
new StaticModelGenerator(icdFile, icdFile, cOutStream, hOutStream, outputFileName, iedName, accessPointName, modelPrefix, initializeOnce);
}
catch (Exception e)
{
Console.WriteLine("ERROR: " + e.ToString());
}
}
}
}

@ -1,17 +0,0 @@
This tool can be accessed from both the command line of visual studio.
To run the tool from the command line a command of the following format has to be generated:
genmodel <ICD file> -ied <ied-name> -ap <access-point-name> -out <output-name> -modelprefix <model-prefix>
The values in <> have to be replaced with the values corresponding to an arbitrary ICD file.
To run this command completely the command should look like this:
ModelGeneratorExample.exe/(dotnet ModelGeneratorExample.dll) genmodel <ICD file> -ied <ied-name> -ap <access-point-name> -out <output-name> -modelprefix <model-prefix>
Example:
ModelGeneratorExample.exe ICDFiles/simpleIO_smv.icd -ied simpleIO -ap accessPoint1 -out static_model -modelprefix iedModel
or
dotnet ModelGeneratorExample.dll ICDFiles/simpleIO_smv.icd -ied simpleIO -ap accessPoint1 -out static_model -modelprefix iedModel

@ -0,0 +1,17 @@
This tool can be accessed from both the command line of visual studio.
To run the tool from the command line a command of the following format has to be generated:
<generator option> <ICD file> -ied <ied-name> -ap <access-point-name> -out <output-name> -modelprefix <model-prefix>
The values in <> have to be replaced with the values corresponding to an arbitrary ICD file.
To run this command completely the command should look like this:
Tools.exe/(dotnet Tools.dll) <generator option> <ICD file> -ied <ied-name> -ap <access-point-name> -out <output-name> -modelprefix <model-prefix>
Example:
Tools.exe 1 ICDFiles/genericIO.icd -ied simpleIO -ap accessPoint1 -out static_model -modelprefix iedModel
or
dotnet Tools.dll 1 ICDFiles/genericIO.icd -ied simpleIO -ap accessPoint1 -out static_model -modelprefix iedModel

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SCLParser\SCLParser.csproj" />
</ItemGroup>
</Project>

@ -11,7 +11,7 @@ using IEC61850.SCL.DataModel;
using System;
using System.Collections.Generic;
namespace ModelGenerator.C_Structures
namespace StaticModelGenerator.C_Structures
{
/** FCs (Functional constraints) according to IEC 61850-7-2 */
public enum eFunctionalConstraint

@ -8,7 +8,7 @@
using IEC61850.SCL;
using IEC61850.SCL.DataModel;
using ModelGenerator.C_Structures;
using StaticModelGenerator.C_Structures;
using System;
using System.Collections.Generic;
using System.IO;
@ -17,7 +17,7 @@ using System.Net;
using System.Runtime.InteropServices.ComTypes;
using DataSet = IEC61850.SCL.DataModel.DataSet;
namespace ModelGenerator
namespace StaticModelGenerator
{
public class StaticModelGenerator

@ -0,0 +1,132 @@
/*
* Copyright 2013-2025 Michael Zillgith, MZ Automation GmbH
*
* This file is part of MZ Automation IEC 61850 SDK
*
* All rights reserved.
*/
using StaticModelGenerator;
namespace modeGenerator_example
{
/// <summary>
/// This example shows how to handle a large number of information objects
/// </summary>
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Usage: Static Model (1) \n Dynamic Model (2) \n <generator option> <ICD file> [-ied <ied-name>] [-ap <access-point-name>] [-out <output-name>] [-modelprefix <model-prefix>]");
if (args.Length == 0)
{
Console.WriteLine("Parse the arguments \n" +
"Usage: Static Model (1) \n Dynamic Model (2) \n <generator option> <ICD file> [-ied <ied-name>] [-ap <access-point-name>] [-out <output-name>] [-modelprefix <model-prefix>]");
}
else
{
string accessPointName = null;
string iedName = null;
string icdFile = "ICDFiles//simpleIO_ltrk_tests.icd";
string outputFileName = "static_model";
string modelPrefix = "iedModel";
bool initializeOnce = false;
icdFile = args[1];
for (int i = 2; i < args.Count(); i++)
{
if (args[i] == ("-ap"))
{
accessPointName = args[i + 1];
Console.WriteLine("Select access point " + accessPointName);
i++;
}
else if (args[i] == ("-ied"))
{
iedName = args[i + 1];
Console.WriteLine("Select IED " + iedName);
i++;
}
else if (args[i] == ("-out"))
{
outputFileName = args[i + 1];
Console.WriteLine("Select Output File " + outputFileName);
i++;
}
else if (args[i] == ("-modelprefix"))
{
modelPrefix = args[i + 1];
Console.WriteLine("Select Model Prefix " + modelPrefix);
i++;
}
else if (args[i] == ("-initializeonce"))
{
initializeOnce = true;
Console.WriteLine("Select Initialize Once");
}
else
{
Console.WriteLine("Unknown option: \"" + args[i] + "\"");
}
}
if (args[0] == "1")
{
Console.WriteLine("Generate Static Model");
FileStream cOutStream = new FileStream(outputFileName + ".c", FileMode.Create, FileAccess.Write);
FileStream hOutStream = new FileStream(outputFileName + ".h", FileMode.Create, FileAccess.Write);
try
{
new StaticModelGenerator.StaticModelGenerator(icdFile, icdFile, cOutStream, hOutStream, outputFileName, iedName, accessPointName, modelPrefix, initializeOnce);
}
catch (Exception e)
{
Console.WriteLine("ERROR: " + e.ToString());
}
}
else if (args[0] == "2")
{
Console.WriteLine("Generate Dynamic Model");
try
{
FileStream stream = new FileStream(outputFileName + ".cfg", FileMode.Create, FileAccess.Write);
new DynamicModel.DynamicModel(icdFile, stream, iedName, accessPointName);
}
catch (Exception e)
{
Console.WriteLine("ERROR: " + e.ToString());
}
}
else
{
Console.WriteLine("Wrong option, parse 1 or 2 \n" +
"Usage: Static Model (1) \n Dynamic Model (2) \n <generator option> <ICD file> [-ied <ied-name>] [-ap <access-point-name>] [-out <output-name>] [-modelprefix <model-prefix>]");
}
}
}
}
}

@ -70,7 +70,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ModelGenerator\ModelGenerator.csproj" />
<ProjectReference Include="..\DynamicModelGenerator\DynamicModelGenerator.csproj" />
<ProjectReference Include="..\StaticModelGenerator\StaticModelGenerator.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamicModelGenerator", "DynamicModelGenerator\DynamicModelGenerator.csproj", "{3269555F-ECB9-4304-936A-8FC6153AB5BD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SCLParser", "SCLParser\SCLParser.csproj", "{AF771AA2-C3EB-4F0A-884A-6B79C9977BE2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StaticModelGenerator", "StaticModelGenerator\StaticModelGenerator.csproj", "{992389DE-80E6-422B-8536-6D39E864118B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools", "Tools\Tools.csproj", "{8103E20D-0EE9-443B-B7B4-6641D4EF85C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3269555F-ECB9-4304-936A-8FC6153AB5BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3269555F-ECB9-4304-936A-8FC6153AB5BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3269555F-ECB9-4304-936A-8FC6153AB5BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3269555F-ECB9-4304-936A-8FC6153AB5BD}.Release|Any CPU.Build.0 = Release|Any CPU
{AF771AA2-C3EB-4F0A-884A-6B79C9977BE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF771AA2-C3EB-4F0A-884A-6B79C9977BE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF771AA2-C3EB-4F0A-884A-6B79C9977BE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF771AA2-C3EB-4F0A-884A-6B79C9977BE2}.Release|Any CPU.Build.0 = Release|Any CPU
{992389DE-80E6-422B-8536-6D39E864118B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{992389DE-80E6-422B-8536-6D39E864118B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{992389DE-80E6-422B-8536-6D39E864118B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{992389DE-80E6-422B-8536-6D39E864118B}.Release|Any CPU.Build.0 = Release|Any CPU
{8103E20D-0EE9-443B-B7B4-6641D4EF85C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8103E20D-0EE9-443B-B7B4-6641D4EF85C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8103E20D-0EE9-443B-B7B4-6641D4EF85C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8103E20D-0EE9-443B-B7B4-6641D4EF85C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D5970CE-F389-4BCE-934E-F1E597AFEE22}
EndGlobalSection
EndGlobal
Loading…
Cancel
Save