Processing The Relay Setting Parameters In Omicron Import Filter

Welcome to my page and welcome to the fifth part of Omicron Import Filter tutorial series. In this tutorial, I will show you how to process the relay setting parameters that to be import in the Xrio converter. In this tutorial, we will focus on the Visual Studio program. We're going to modify the codes in our project called MyImportFilter that we've created in the previous tutorial. 

Download the project in this link MyImportFilter - Process Relay Setting Parameters. Extract and open the project. Once the project is loaded, add New Folder inside the project and set the name to SEStudio1. We need this to make organize our project class filter. SE Studio 1 stands for Schneider Electric Studio 1 which is the software that used in communicating MiCOM relays particularly P12x series. And yes we're going to create a new import filter and user interface form MiCOM P12x series relay. I think this will applied to other MiCOM P series relay.

Add a new Form inside the SEStudio1 folder and set the name to SEStudio1UIForm.vb. In the SEStudio1UIForm, add one textbox, one datagridview and three pushbuttons, set their properties and and arrange them according to the previous tutorial called Creating A User Interface In Omicron Test Universe Import Filter.

Once the controls are set and arranged, double click the OK button then enter code below

DialogResult = Windows.Forms.DialogResult.OK

Go back to SEStudio1UIForm, double click the Cancel button then enter the code below

DialogResult = Windows.Forms.DialogResult.Cancel

Go back to SEStudio1UIForm, double click the Browse or Open button then enter the code below

Using dlgOpen As New Windows.Forms.OpenFileDialog
    With dlgOpen
        .Title = "Open Relay Setting File"
        .Filter = "Text files (*.txt)|*.txt"
        .Multiselect = False
        If .ShowDialog = Windows.Forms.DialogResult.OK Then
            If System.IO.File.Exists(.FileName) Then
                Using TextStreamReader As System.IO.StreamReader = New System.IO.StreamReader(.FileName)
                    TextFileContent = TextStreamReader.ReadToEnd()
                    TextStreamReader.Close()
                End Using
                LoadTheTextFileContent()
            End If
        End If
    End With
End Using

After that, you will get an error but we will fix that by copying the code below then paste it on the top of the codes

Private Document As OMXRioData.IAutoXRioDocument
Private TextFileContent As String

Public Sub DisplayForm(ByVal pDocument As OMXRioData.IAutoXRioDocument)
    Document = pDocument
    ShowDialog()
End Sub

To get rid the error we need to create a sub procedure LoadTheTextFileContent. Just copy the codes below then paste it at the bottom.

Private Sub LoadTheTextFileContent()

End Sub

You'll see that procedure is doing nothing but we will comeback to that. We need to do the FilterBase first.

Now add new class and set the name to SEStudio1FilterBase.vb and SE Studio 1 stands for Schneider Electric Studio 1. Anyway, if you didn't know, we can add multiple Import Filter in just one project. Example, one for MiCOM, one for GE, one for SEL and etc. Once the new class is added, inherits the OMXRioFilter.FilterBase inside the class.

Copy the code below and replace the Throw New NotImplementedException() line inside the ShowParameterDialog(isImport As Boolean) function. This function will create a new instance of SEStudio1UIForm and display it during the import process of the relay settings.

Dim Result As Boolean = False
Using dlg As New SEStudio1UIForm
    With dlg
        dlg.DisplayForm(Document)
        If .DialogResult = Windows.Forms.DialogResult.OK Then
            Result = True
        End If
    End With
End Using
Return Result

Comment out the Throw New NotImplementedException() line in the rest of the functions and procedures by inserting apostrophe sign ( ' ) in the beginning of the code.

Public Overrides Sub SetParameter(isImport As Boolean, paramName As String, paramValue As String)
    'Throw New NotImplementedException()
End Sub

Public Overrides Function ExecuteImport() As Boolean
    'Throw New NotImplementedException()
End Function

Public Overrides Function IsExportSupported() As Boolean
    'Throw New NotImplementedException()
End Function

Public Overrides Function ExecuteExport() As Boolean
    'Throw New NotImplementedException()
End Function

Public Overrides Function GetParameter(isImport As Boolean, paramName As String) As String
    'Throw New NotImplementedException()
End Function

Add a new folder and name it Class Modules and add a new class under this folder and name it to Parameter.vb, this class will be used by the other FilterBase to store the relay setting parameter in a list form and we're going to select each item by ID. Copy the codes below then paste it to the Parameter.vb class.

Imports System.ComponentModel

Public Class Parameter
    Private _Parameter As String
    Private _Value As String
    Private _Name As String
    Private _OldValue As String
    Private _Unit As String
    Private _Comment As String
    Private _ID As Integer
    Private _Group As Integer
    Private _LowerLimit As String
    Private _UpperLimit As String

    Public Sub New()

    End Sub

    Public Sub New(ByVal iParameter As String, ByVal iValue As String)
        _Parameter = iParameter
        _Value = iValue
    End Sub

    Public Sub New(ByVal iParameter As String, ByVal iValue As String, ByVal Unit As String, ByVal Name As String)
        _Parameter = iParameter
        _Value = iValue
        _Name = Name
        _Unit = Unit
    End Sub

    Public Sub New(ByVal iParameter As String, ByVal iValue As String, ByVal Unit As String)
        _Parameter = iParameter
        _Value = iValue
        _Unit = Unit
    End Sub

    Public Overloads Function ToString() As String
        Return _Parameter & ", " & _Value
    End Function

    Public Property Name As String
        Get
            Return _Name
        End Get
        Set(value As String)
            _Name = value
        End Set
    End Property

    <DisplayName("Foreign ID")>
    Public Property Parameter As String
        Get
            Return _Parameter
        End Get
        Set(value As String)
            _Parameter = value
        End Set
    End Property

    <DisplayName("Old Value")>
    Public Property OldValue As String
        Get
            Return _OldValue
        End Get
        Set(value As String)
            _OldValue = value
        End Set
    End Property

    <DisplayName("New Value")>
    Public Property Value As String
        Get
            Return _Value
        End Get
        Set(value As String)
            _Value = value
        End Set
    End Property

    <DisplayName("Unit")>
    Public Property Unit As String
        Get
            Return _Unit
        End Get
        Set(value As String)
            _Unit = value
        End Set
    End Property

    <DisplayName("Description")>
    Public Property Comment As String
        Get
            Return _Comment
        End Get
        Set(value As String)
            _Comment = value
        End Set
    End Property

    Public Property ID As Integer
        Get
            Return _ID
        End Get
        Set(value As Integer)
            _ID = value
        End Set
    End Property

    Public Property Group As Integer
        Get
            Return _Group
        End Get
        Set(value As Integer)
            _Group = value
        End Set
    End Property

    Public Property LowerLimit As String
        Get
            Return _LowerLimit
        End Get
        Set(value As String)
            _LowerLimit = value
        End Set
    End Property

    Public Property UpperLimit As String
        Get
            Return _UpperLimit
        End Get
        Set(value As String)
            _UpperLimit = value
        End Set
    End Property
End Class

Now, add new class in the SEStudio1 folder and name it with SEStudio1Import.vb. All the data from setting file will be process in this class. Copy the code below and paste it it to import section.

Imports System.IO
Imports OMXRioData

Next,  we need to declare some names, functions and procedures to be used in this class module. Copy the codes below and paste them inside the SEStudio1Import.vb.

    Private _Document As OMXRioData.IAutoXRioDocument 'Storage of XRIO document
    Private RelayParameters As String = "CUSTOM.RELAY_PARAMETERS" 'Path directory of the relay paraters node at the XRIO
    Private ParentNodeName As String = "RELAY_PARAMETERS" 'The node name of the last node from the path directory of the relay parameters
    Private ImportedSetting As List(Of Parameter) 'Storage of the imported parameter in list

    Public Event AddEvent(ByVal Message As String) 'For displaying messages whithout freezing the UI

    Public HasError As Boolean = False
    Public ErrorMessages As List(Of ErrorMessage) 'Storage of the error detected

    Public Sub New(ByVal xDocument As IAutoXRioDocument)
        _Document = xDocument
    End Sub

    Public ReadOnly Property Document As IAutoXRioDocument 'Storage of XRIO document
        Get
            Return _Document
        End Get
    End Property

    'Get the name of the current node
    Private Function GetNodeName(ByVal Node As IAutoXRioBlock) As String
        If Node.Id = ParentNodeName Then
            Return ""
        Else
            Return GetNodeName(Node.ParentElementNode).Trim & "/" & Node.Name.Trim
        End If
    End Function

    Private Sub SetErrorMessages(mName As String, errMessage As String)
        If ErrorMessages Is Nothing Then
            ErrorMessages = New List(Of ErrorMessage)
        End If

        Dim Item As New ErrorMessage With {
            .Title = mName,
            .Message = errMessage
        }
        ErrorMessages.Add(Item)
    End Sub

    Public Sub AddCustomEvent(Message As String) 'This will be access outside this class to raise a message event
        RaiseEvent AddEvent(Message)
    End Sub

Next, we need to create function that responsible for opening and reading and parsing the setting file to load into the a list of parameters. Copy and paste the codes below to SEStudio1Import.vb.

    Public Function OpenFileAndImport(ByVal Filename As String) As Boolean
        Dim Result As Boolean = False
        Try
            ImportedSetting = New List(Of Parameter)
            Dim NewSettings As List(Of Parameter) = ReadMicomFile(Filename)
            If NewSettings IsNot Nothing Then
                ImportTheSettingV2(NewSettings)
                Result = True
            End If
        Catch ex As Exception
            MsgBox("The import filter might not be compatible to current test plan/routines.", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Unexpected Error")
        End Try
        Return Result
    End Function

    Public Function ReadMicomFile(ByVal Filename As String) As List(Of Parameter)
        Dim Result As New List(Of Parameter)
        Dim BypassString As New List(Of String)
        Dim Grouped As New List(Of GroupToImport)

        Dim FileType As String = String.Empty
        Dim FormatVersion As String = String.Empty
        Dim RelayType As String = String.Empty
        Dim ModelNumber As String = String.Empty
        Dim Firmware As String = String.Empty
        Dim SerialNumber As String = String.Empty

        Dim IncludeReadOnly As Boolean
        Dim IncludeHidden As Boolean

        Using sr As New StreamReader(Filename)
            Do While Not sr.EndOfStream
                Dim Line As String = sr.ReadLine
                If Line.Contains("%") Then
                    Dim SplittedLine As String() = Line.Split(":")
                    If Line.Contains("FileType") Then
                        FileType = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("FormatVersion") Then
                        FormatVersion = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("RelayType") Then
                        RelayType = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("ModelNumber") Then
                        ModelNumber = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("Firmware") Then
                        Firmware = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("SerialNumber") Then
                        SerialNumber = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("IncludeReadOnly") Then
                        IncludeReadOnly = SplittedLine(UBound(SplittedLine)).Trim
                    ElseIf Line.Contains("IncludeHidden") Then
                        IncludeHidden = SplittedLine(UBound(SplittedLine)).Trim
                    Else
                        GoTo OptionElse
                    End If
                Else
OptionElse:
                    Dim SplittedLine As String() = Line.Split("|")
                    If SplittedLine.Count = 7 Then
                        '0 ID
                        '1 Block/Parent Node
                        '2 Parameter name
                        '3 Current Value
                        '4 Range Low
                        '5 Range Hi
                        '6 Step
                        If Not IsNotIncluded(SplittedLine(1).Trim) Then
                            Dim nParam As New Parameter
                            With nParam
                                .Parameter = SplittedLine(0).Trim
                                .Name = SplittedLine(2).Trim
                                .LowerLimit = SplittedLine(4).Trim
                                .UpperLimit = SplittedLine(5).Trim
                                Dim ValueSplit As String() = SplittedLine(3).Trim.Split(" ")
                                If ValueSplit.Count = 2 Then
                                    If IsNumeric(ValueSplit(0).Trim) And Not IsNumeric(ValueSplit(1).Trim) Then
                                        .Value = ValueSplit(0).Trim
                                        .Unit = ValueSplit(1).Trim
                                    Else
                                        .Value = SplittedLine(3).Trim
                                    End If
                                Else
                                    If SplittedLine(3).Trim.Contains("%") And ValueSplit.Count = 3 Then
                                        .Value = ValueSplit(0).Trim '/ 100
                                        .Unit = ValueSplit(2).Trim
                                        .LowerLimit = Val(SplittedLine(4).Trim) '/ 100
                                        .UpperLimit = Val(SplittedLine(5).Trim) '/ 100
                                    Else
                                        .Value = SplittedLine(3).Trim
                                    End If
                                End If
                            End With
                            Result.Add(nParam)
                        End If
                    End If
                End If
            Loop
        End Using
        Return Result
    End Function

    Private Function IsNotIncluded(Name As String) As Boolean
        Dim exparams As New List(Of String)
        With exparams
            .Add("RECORD CONTROL")
            .Add("DISTURB RECORDER")
            .Add("MEASURE'T SETUP")
            .Add("COMMISSION TESTS")
            .Add("CB MONITOR SETUP")
            .Add("OPTO CONFIG")
            .Add("CTRL I/P CONFIG")
            .Add("FUNCTION KEYS")
            .Add("ETHERNET NCIT")
            .Add("CTRL I/P LABELS")
            .Add("INPUT LABELS")
            .Add("OUTPUT LABELS")
            .Add("Event Control")
            .Add("Disturbance Records")
            .Add("Contacts")
            .Add("OUTPUT RELAYS")
            .Add("INPUTS")
            .Add("DVICE Module")
        End With
        Return MultiContains(Name, exparams.ToArray)
    End Function

    Public Function MultiContains(str As String, ParamArray values() As String) As Boolean
        Return values.Any(Function(val) str.Contains(val))
    End Function
    Public Function GetImportedSetting() As List(Of Parameter)
        Return ImportedSetting
    End Function
    

You don't need to change anything in ReadMicomFile function, That's pretty much it. The only thing can be change there is the IsNotIncluded function. You can add or remove some keywords inside the exparams list. If you want to include for example "OUTPUT RELAYS", just remove that line so that all the lines in the setting files that have "OUTPUT RELAYS" words will be included in the list of parameters to be imported in the XRIO document.

Where not done yet, because you will realize that the codes will give you an error from OpenFileAndImport function. We need to create another functions that responsible for reading the XRIO Document and apply the necessary setting value.

Copy and paste the codes below to SEStudio1Import.vb class and do not modify them especially the set procedures. That's the heart of the import filter I made. You can use that for all the relays if you want to. The only thing you need to change is the opening, reading and parsing file settings.

#Region "Importing setting region" 'Settings processor
    Private Function ImportTheSettingV2(ByVal File As List(Of Parameter))
        Try
            Dim Block As IAutoXRioBlock = Document.GetBlockFromIDs(RelayParameters)
            If Block.Parameters.Count > 0 Then
                For Each Param As OMXRioData.AutoParameter In Block.Parameters
                    If Not String.IsNullOrEmpty(Param.ForeignId) Then
                        Dim Parameter As Parameter = File.Find(Function(x) x.Parameter.Trim.ToUpper = Param.ForeignId.Trim.ToUpper)
                        If Parameter IsNot Nothing Then
                            SetTheNewSetting(Param, Parameter)
                            File.Remove(Parameter)
                        End If
                    End If
                Next
            End If
            If Block.Blocks.Count > 0 Then
                ReadAllBlocksAndSetParametersV2(Block, File)
            End If
            Return True
        Catch ex As Exception
            Throw New Exception("Error found in ImportTheSettingV2 function.", ex.InnerException)
            Return False
        End Try
    End Function

    Private Sub ReadAllBlocksAndSetParametersV2(ByVal Block As OMXRioData.IAutoXRioBlock, File As List(Of Parameter))
        For Each Item As OMXRioData.IAutoXRioBlock In Block.Blocks
            If Item.Parameters.Count > 0 Then
                For Each Param As OMXRioData.AutoParameter In Item.Parameters
                    If Not String.IsNullOrEmpty(Param.ForeignId) Then
                        Dim Parameter As Parameter = File.Find(Function(x) x.Parameter.Trim.ToUpper = Param.ForeignId.Trim.ToUpper)
                        If Parameter IsNot Nothing Then
                            SetTheNewSetting(Param, Parameter)
                            File.Remove(Parameter)
                        End If
                    End If
                Next
            End If
            If Item.Blocks.Count > 0 Then
                ReadAllBlocksAndSetParametersV2(Item, File)
            End If
        Next
    End Sub

    Private Sub SetTheNewSetting(ByVal ItemParameter As OMXRioData.IAutoXRioParameter, ByVal Item As Parameter)
        RaiseEvent AddEvent("Please wait: Importing " & Item.Value & " " & Item.Unit & " to " & GetNodeName(ItemParameter.ParentElementNode).TrimStart("/") & "/" & ItemParameter.Name & ".")
        If ItemParameter.DataType = OMXRioData.ParamDataType.String Then
            SetTheStringSetting(ItemParameter, Item)
        ElseIf ItemParameter.DataType = OMXRioData.ParamDataType.Integer Then
            SetTheIntegerSetting(ItemParameter, Item)
        ElseIf ItemParameter.DataType = OMXRioData.ParamDataType.Real Then
            SetTheDoubleSetting(ItemParameter, Item)
        ElseIf ItemParameter.DataType = OMXRioData.ParamDataType.Enumeration Then
            SetTheEnumSetting(ItemParameter, Item)
        ElseIf ItemParameter.DataType = OMXRioData.ParamDataType.Boolean Then
            SetTheBooleanSetting(ItemParameter, Item)
        End If
    End Sub

    Private Sub SetTheBooleanSetting(ByVal ItemParameter As IAutoXRioParameter, ByVal Item As Parameter)
        Try
            Dim ErrorMessage As String = String.Empty
            Item.Name = GetNodeName(ItemParameter.ParentElementNode).TrimStart("/").Trim & "/" & ItemParameter.Name.Trim
            Item.OldValue = ItemParameter.DisplayString
            If ItemParameter.SetDisplayValue(Item.Value, ErrorMessage) Then
                Item.Comment = "Changed parameter value from " & Item.OldValue & " to " & Item.Value
                ImportedSetting.Add(Item)
            Else
                Document.Errors.AddError(ErrorType.Warning, ErrorGroup.Filter, 0, 0, 0, Document.GetUserPathFromParam(ItemParameter), Document.GetIDsPathFromParam(ItemParameter), "Imported value could not be set.")
            End If
        Catch ex As Exception
            HasError = True
            SetErrorMessages("Could not set " & ItemParameter.ParentElementNode.Name & " " & ItemParameter.Name & " to " & Item.Value & ".", ex.Message)
        End Try

    End Sub

    Private Sub SetTheEnumSetting(ByVal ItemParameter As IAutoXRioParameter, ByVal Item As Parameter)
        Try
            Dim ErrorMessage As String = String.Empty
            Item.Name = GetNodeName(ItemParameter.ParentElementNode).TrimStart("/").Trim & "/" & ItemParameter.Name.Trim
            Item.OldValue = ItemParameter.DisplayString
            If ItemParameter.SetDisplayValue(Item.Value, ErrorMessage) Then
                Item.Comment = "Changed ItemParameter value from " & Item.OldValue & " to " & Item.Value
                ImportedSetting.Add(Item)
            ElseIf IsNumeric(Item.Value) Then
                If ItemParameter.SetDisplayValue(ItemParameter.ParameterEnum.EnumValues.Item(Int(Item.Value) + 1).DisplayName, ErrorMessage) Then
                    Item.Comment = "Changed ItemParameter value from " & Item.OldValue & " to " & Item.Value
                    ImportedSetting.Add(Item)
                Else
                    Document.Errors.AddError(ErrorType.Warning, ErrorGroup.Filter, 0, 0, 0, Document.GetUserPathFromParam(ItemParameter), Document.GetIDsPathFromParam(ItemParameter), "Imported value could not be set.")
                End If
            ElseIf Not IsNumeric(Item.Value) Then

                If ItemParameter.SetDisplayValue(ItemParameter.ParameterEnum.EnumValues.Item(ConvertONOFF(Item.Value) + 1).DisplayName, ErrorMessage) Then
                    Item.Comment = "Changed ItemParameter value from " & Item.OldValue & " to " & Item.Value
                    ImportedSetting.Add(Item)
                End If
            Else
                Document.Errors.AddError(ErrorType.Warning, ErrorGroup.Filter, 0, 0, 0, Document.GetUserPathFromParam(ItemParameter), Document.GetIDsPathFromParam(ItemParameter), "Imported value could not be set.")
            End If
        Catch ex As Exception
            HasError = True
            SetErrorMessages("Could not set " & ItemParameter.ParentElementNode.Name & " " & ItemParameter.Name & " to " & Item.Value & ".", ex.Message)
        End Try
    End Sub

    Private Function ConvertONOFF(ByVal Status As String) As Integer
        If Status = "ON" Then
            Return 1
        ElseIf Status = "OFF" Then
            Return 0
        Else
            Return -1
        End If
    End Function

    Private Sub SetTheStringSetting(ByVal ItemParameter As IAutoXRioParameter, ByVal Item As Parameter)
        Try
            Dim ErrorMessage As String = String.Empty
            Item.Name = GetNodeName(ItemParameter.ParentElementNode).TrimStart("/").Trim & "/" & ItemParameter.Name.Trim
            Item.OldValue = ItemParameter.DisplayString
            If Not String.IsNullOrEmpty(Item.Unit) Then
                Item.Value = Item.Value & " " & Item.Unit
                Item.Unit = String.Empty
            End If
            If ItemParameter.SetDisplayValue(Item.Value, ErrorMessage) Then
                Item.Comment = "Changed parameter value from " & Item.OldValue & " to " & Item.Value
                ImportedSetting.Add(Item)
            Else
                Document.Errors.AddError(ErrorType.Warning, ErrorGroup.Filter, 0, 0, 0, Document.GetUserPathFromParam(ItemParameter), Document.GetIDsPathFromParam(ItemParameter), "Imported value could not be set.")
            End If
        Catch ex As Exception
            HasError = True
            SetErrorMessages("Could not set " & ItemParameter.ParentElementNode.Name & " " & ItemParameter.Name & " to " & Item.Value & ".", ex.Message)
        End Try
    End Sub

    Private Sub SetTheIntegerSetting(ByVal ItemParameter As IAutoXRioParameter, ByVal Item As Parameter)
        Try
            Dim ErrorMessage As String = String.Empty
            Item.Name = GetNodeName(ItemParameter.ParentElementNode).TrimStart("/").Trim & "/" & ItemParameter.Name.Trim
            Item.OldValue = ItemParameter.DisplayString
            If ItemParameter.SetDisplayValue(Item.Value, ErrorMessage) Then
                Item.Comment = "Changed parameter value from " & Item.OldValue & " to " & Item.Value
                ImportedSetting.Add(Item)
            Else
                Document.Errors.AddError(ErrorType.Warning, ErrorGroup.Filter, 0, 0, 0, Document.GetUserPathFromParam(ItemParameter), Document.GetIDsPathFromParam(ItemParameter), "Imported value could not be set.")
            End If
        Catch ex As Exception
            HasError = True
            SetErrorMessages("Could not set " & ItemParameter.ParentElementNode.Name & " " & ItemParameter.Name & " to " & Item.Value & ".", ex.Message)
        End Try
    End Sub

    Private Sub SetTheDoubleSetting(ByVal ItemParameter As IAutoXRioParameter, ByVal Item As Parameter)
        Try
            Dim ErrorMessage As String = String.Empty
            Item.Name = GetNodeName(ItemParameter.ParentElementNode).TrimStart("/").Trim & "/" & ItemParameter.Name.Trim
            Item.OldValue = ItemParameter.DisplayString

            If Not ItemParameter.ParameterDouble.IsValidInternalMaxValue(Item.Value, Nothing) Or Not ItemParameter.ParameterDouble.IsValidInternalMinValue(Item.Value, Nothing) Then

            End If

            ItemParameter.ParameterDouble.InternalMin = Val(Item.LowerLimit.Trim)
            ItemParameter.ParameterDouble.InternalMax = Val(Item.UpperLimit.Trim)

            Dim _v As String() = Item.Value.Split(" ")
            If Not IsNumeric(_v(0)) Then
                Item.Value = ConvertWordToNumber(_v(0))
                Item.Unit = _v(1)
            End If
            If ItemParameter.SetDisplayValue(Item.Value, ErrorMessage) Then
                If Not String.IsNullOrEmpty(Item.Unit) Then
                    If Item.Unit.Contains("m") And Left(Item.Unit.Trim, 1) = "m" And Item.Unit.Trim <> "min" And Item.Unit.Trim <> "mn" Then
                        ItemParameter.ParameterDouble.Unit = Item.Unit.Replace("m", "")
                        ItemParameter.ParameterDouble.MultiplierSymbol = "m"
                    ElseIf Item.Unit.Contains("k") And Left(Item.Unit.Trim, 1) = "k" Then
                        ItemParameter.ParameterDouble.Unit = Item.Unit.Replace("k", "")
                        ItemParameter.ParameterDouble.MultiplierSymbol = "k"
                    ElseIf Item.Unit.Contains("u") And Left(Item.Unit.Trim, 1) = "u" Then
                        ItemParameter.ParameterDouble.Unit = Item.Unit.Replace("u", "")
                        ItemParameter.ParameterDouble.MultiplierSymbol = "u"
                    ElseIf Item.Unit.Contains("M") And Left(Item.Unit.Trim, 1) = "M" Then
                        ItemParameter.ParameterDouble.Unit = Item.Unit.Replace("M", "")
                        ItemParameter.ParameterDouble.MultiplierSymbol = "M"
                    ElseIf Item.Unit.Contains("G") And Left(Item.Unit.Trim, 1) = "G" Then
                        ItemParameter.ParameterDouble.Unit = Item.Unit.Replace("G", "")
                        ItemParameter.ParameterDouble.MultiplierSymbol = "G"
                    End If
                End If
                Item.Value = Strings.FormatNumber(Val(Item.Value), ItemParameter.ParameterDouble.DecimalPlaces)
                Item.Comment = "Changed parameter value from " & Item.OldValue & " to " & Item.Value
                ImportedSetting.Add(Item)
            Else
                Document.Errors.AddError(ErrorType.Warning, ErrorGroup.Filter, 0, 0, 0, Document.GetUserPathFromParam(ItemParameter), Document.GetIDsPathFromParam(ItemParameter), "Imported value could not be set.")
            End If
        Catch ex As Exception
            HasError = True
            SetErrorMessages("Could not set " & ItemParameter.ParentElementNode.Name & " " & ItemParameter.Name & " to " & Item.Value & ".", ex.Message)
        End Try
    End Sub

    Private Function ConvertWordToNumber(Data As String) As String
        If Data = "Blocked" Then
            Return "+inf"
        Else
            Return Val(Data)
        End If
    End Function
#End Region

Now back to SEStudio1FilterBase.bv class, copy the codes below and replace the content of this class module.

Imports OMXRioData

Public Class SEStudio1FilterBase
    Inherits OMXRioFilter.FilterBase
    Private RELAY_PARAMETERS_BLOCK As String = "CUSTOM.RELAY_PARAMETERS"
    Private AUTHOR_PARAMETER As String = "CUSTOM.AUTHOR.IMPORT_FILTER_AUTHOR"

    Public Overrides Sub SetParameter(isImport As Boolean, paramName As String, paramValue As String)
        'Do nothing
    End Sub

    Public Overrides Function ExecuteExport() As Boolean
        Return False
    End Function

    Public Overrides Function ExecuteImport() As Boolean
        Return True
    End Function

    Public Overrides Function GetParameter(isImport As Boolean, paramName As String) As String
        Return String.Empty
    End Function

    Public Overrides Function IsExportSupported() As Boolean
        Return False
    End Function


    Public Overrides Function ShowParameterDialog(isImport As Boolean) As Boolean
        Dim Result As Boolean = False
        If isImport Then
            If IsDocumentValid() Then
                Dim _UpdateForm As New SEStudio1UIForm
                With _UpdateForm
                    .DisplayForm(Document)
                End With
                _UpdateForm = Nothing
                Result = True
            Else
                MsgBox("The current test plan/routine is not compatible for this import filter. Some validation parameters are missing.", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Incompatible Test Plan/Routine")
            End If
        End If
        Return Result
    End Function

    Private Function IsDocumentValid() As Boolean
        Dim Result As Boolean = False
        Dim Block As IAutoXRioBlock = Document.GetBlockFromIDs(RELAY_PARAMETERS_BLOCK)
        Dim AuthorParam As IAutoXRioParameter = Document.GetParamFromIDs(AUTHOR_PARAMETER)
        If Block IsNot Nothing And AuthorParam IsNot Nothing Then
            If Not String.IsNullOrEmpty(AuthorParam.DisplayString) And AuthorParam.DisplayString = "Author Name" Then
                Result = True
            End If
        End If
        Block = Nothing
        AuthorParam = Nothing
        Return Result
    End Function
End Class

Now, create new class module under the SEStudio1 folder and name it SEStudio1RelayInfo.vb. Then, copy and paste the codes below to SEStudio1RelayInfo.vb class module.
    Private _FileType As String
    Private _FormatVersion As String
    Private _RelayType As String
    Private _ModelNumber As String
    Private _SerialNumber As String

    Public Sub New()

    End Sub

    Public Sub New(ByVal FileType As String, ByVal FormatVersion As String, ByVal RelayType As String, ByVal ModelNumber As String, ByVal SerialNumber As String)
        _FileType = FileType
        _FormatVersion = FormatVersion
        _RelayType = RelayType
        _ModelNumber = ModelNumber
        _SerialNumber = SerialNumber
    End Sub

    Public Property FileType As String
        Get
            Return _FileType
        End Get
        Set(value As String)
            _FileType = value
        End Set
    End Property

    Public Property FormatVersion As String
        Get
            Return _FormatVersion
        End Get
        Set(value As String)
            _FormatVersion = value
        End Set
    End Property

    Public Property RelayType As String
        Get
            Return _RelayType
        End Get
        Set(value As String)
            _RelayType = value
        End Set
    End Property

    Public Property ModelNumber As String
        Get
            Return _ModelNumber
        End Get
        Set(value As String)
            _ModelNumber = value
        End Set
    End Property

    Public Property SerialNumber As String
        Get
            Return _SerialNumber
        End Get
        Set(value As String)
            _SerialNumber = value
        End Set
    End Property

Add a new form under the SEStudio1 folder and name it to SEStudio1DialogInfo.vb and add 11 labels and 2 buttons then arrange them as shown in the image below.



Form SEStudio1DialogInfo properties:
  • FormBorderStyle - FixedSingle
  • MaximizeBox - False
  • MinimizeBox - False
  • StartPosision - CenterScreen
  • Text -Relay Information
  1. Label properties File Type:
    • Name - LabelFileType
    • AutoSize - False
    • BorderStyle - FixedSingle
    • Text - %FileType







Comments