data region

Upload: rajeshjunk

Post on 03-Jun-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 data Region

    1/101

    Dim sr As StreamReader Dim xstream As FileStream

    ''' ''' Function:AssignSCFdata '''This fucntion copies the dataDescriptor sigrec values to scfdata sigrec

    '''

    ''' ''' Public Function AssignSCFdata() Try ReDim scfdata.sigrec(dataDescriptor.sigrec.Length - 1) 'fail-safe If scfdata.sigrec Is Nothing Then Exit Function End If 'fail-safe ReDim scfdata.sigrec(dataDescriptor.sigrec.Length - 1) 'Assign the dataDescriptor values to scfdata

    Array.Copy(dataDescriptor.sigrec, scfdata.sigrec, dataDescriptor.sigrec.Length) Catch ex As Exception sw.WriteLine(Now.ToString + ": Assignscfdata Exception:" + ex.Message) End Try End Function ''' ''' Function:AssignDatadescriptor ''' This fucntion copies the sigrec structure values to dataDescriptor sigrec ''' '''

    ''' Public Function AssignDatadescriptor() Try ReDim dataDescriptor.sigrec(scfdata.sigrec.Length - 1) 'fail-safe If scfdata.sigrec Is Nothing Then Exit Function End If

    ReDim dataDescriptor.sigrec(scfdata.sigrec.Length - 1) 'Assign the scfdata values to dataDescriptor Array.Copy(scfdata.sigrec, dataDescriptor.sigrec, dataDescriptor.sig

    rec.Length) Catch ex As Exception sw.WriteLine(Now.ToString + ": Assignscfdata Exception:" + ex.Message) End Try End Function ''' ''' Function:StoreOriginal ''' This fucntion is called when user clicks on "Edit Signal Attribute(Tags)" menu item. ''' when user clicks on that menu item all fields of that window are enabled. '''

    ''' ''' Public Function StoreOriginal()

  • 8/11/2019 data Region

    2/101

    Try 'stores the all original values should be enabled GroupInputSignalsDialog.CancelButton.Enabled = True GroupInputSignalsDialog.VoltsAmpsGroupPanel.Enabled = True GroupInputSignalsDialog.IVPairGroupPanel.Enabled = True GroupInputSignalsDialog.PhaseGroupPanel.Enabled = True GroupInputSignalsDialog.GroupNumGroupPanel.Enabled = True

    GroupInputSignalsDialog.ACDCGroupPanel.Enabled = True GroupInputSignalsDialog.NoChangesBtn.Enabled = True GroupInputSignalsDialog.ChangeAttributesBtn.Enabled = True GroupInputSignalsDialog.StatusTxtbox.Text = "" Catch ex As Exception sw.WriteLine(Now.ToString + ": StroreOriginal Exception" + ex.Message) End Try End Function ''' ''' Function:OpenFile ''' This is the main for opening a configuration file.

    ''' It does the below showed work. ''' 1.If user clicks on cancel button open dialog then it gives an appropriate message for understanding. ''' 2.It gives "Please Choose SCF" message when user opens a file other thanthe scf. ''' 3.And also checks related tcf of opened scf is existed or not. ''' ''' ''' Public Function CondataOpenFile() Try CondataMainfrmLoad() ScfStr = scfFileName

    ''checking if opened file is scf or not If Not File.Exists(ScfStr) Then Return False End If CheckAndReadScf() Catch ex As Exception sw.WriteLine(Now.ToString + " OpenFile: : " + ex.Message) End Try End Function ''' ''' Function:CheckAndReadScf ''' check the scf and tcf files are existed then update the structures otherwise gives a message "file not exist" ''' ''' ''' Public Function CheckAndReadScf() Try

    'Fill all the strutres by Opened scf and it checks weither opened file is corrupted or not? If Not File.Exists(ScfStr) Then OutputsListView.Columns(0).Text = "Outputs" InputsListView.Columns(0).Text = "Inputs" 'CondataStructuresINtiallization()

    Exit Function End If 'Changing the Opened scf file Extension to Tcf

  • 8/11/2019 data Region

    3/101

    Dim tcfName As String = System.IO.Path.ChangeExtension(ScfStr, ".tcf") 'Checks if Opened folder has Tcf file is existed or not? If System.IO.File.Exists(tcfName) Then 'If tcf file found then update the tcf structures by using the existed tcf file

    'If Not TCFReaderModule.ReadTcf(tcfName) Then

    ' 'If existed tcf file corrupted then gives a messgae and clear all inputs

    ' TCFFlag = False ' IntializeAll() ' 'CondataStructuresINtiallization() ' Exit Function 'Else 'If existed tcf file is not corrupted then update the tcf flags TCFFlag = True TcfFilename = tcfName 'End If Else

    'if not tcf found it displays a messageDevComponents.DotNetBar.MessageBoxEx.Show("Trigger ConfigurationFile (TCF) not successfully opened.", "Condata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 'Me.Text = "ConData- Configure Continuous Data Output" ScfStr = "" SCFFlag = False IntializeAll() 'CondataStructuresINtiallization() InputsListView.Columns(0).Text = "Inputs" Exit Function End If

    'If Not (CondataScfReaderModule.ReadScf(ScfStr)) Then ' 'If Opened file corrupted the it gives message ' MsgBox(Now.ToString + " Error in reading SCF: Please try again." + ScfStr) ' SCFFlag = False 'Else ' 'If Opened file not corrupted then Update the SCF Flag scfFileName = ScfStr SCFFlag = True 'End If

    'diplay the scf name on the mainform 'Me.Text = "ConData-" + Path.GetFileName(scfFileName) 'Intiallize all flags and listview names,progress bar values IntializeAll()

    ShowAllSignalsCheckBox.Checked = False 'Checks if any glable is same name with another channel index then closing the file otherwise populates the Inputs and Calculates the Percentages OnFileOpen() Catch ex As Exception sw.WriteLine(Now.ToString + " CheckAndReadScf: " + ex.Message) End Try End Function

    ''' ''' Function:IntializeAll ''' This function initializes all values while opening a file.

  • 8/11/2019 data Region

    4/101

    ''' ''' ''' Public Function IntializeAll() Try InputsListView.Columns(0).Text = "Inputs" OutputsListView.Columns(0).Text = "Outputs"

    InputsListView.Items.Clear() OutputsListView.Items.Clear() InputListViewSelectedItems.Clear() OutputListViewSelectedItems.Clear() OPwidthpercentLbl.Text = "0.0%" OPWidthProgressbar.Value = 0 ProcTimepercentLbl.Text = "0.0%" ProcTimeProgressBar.Value = 0 ProcmemperA.Text = "0.0%" ProcMemAProgressBar.Value = 0 ProcmemperB.Text = "0.0%" ProcBProgressBar.Value = 0

    DeleteSelectionBtn.Enabled = False 'removing the calculation listview selection when we open a scfIf CalculationsListView.SelectedItems.Count > 0 Then

    CalculationsListView.SelectedItems(0).Selected = False pFunction = "" End If IpOpTextBox1.Text = "" ' ModeGroupPanel.Enabled = False Catch ex As Exception sw.WriteLine(Now.ToString + ": IntializeAll exception" + ex.Message) End Try End Function

    ''' ''' Function:CondataMainfrmLoad ''' load the calculation of and progress bar information and all buttons ofcondata ''' ''' ''' Public Function CondataMainfrmLoad() Try CalculationsListView.Items.Clear() 'update the calculation listview values CondataUpdateCalList() 'Intiallize the nBaudRate,m_nBaudRate ,nInRate, m_nLineFreq, nMaxInList, m_nOutputRate UpdateValues() 'intiallize the Quad structure values QuadUpdation() 'Intiallize the values AdvancedSettingsDialog.UseDefaults() Dim lv As ListViewItem 'display the calculation list view For i = 0 To 12 If CBool(CalllistFlag(i)) = True Then lv = New ListViewItem lv.Text = CalList(i)

    If lv.Text = "Digital" Then lv.ImageKey = ("IDI_33_TWO_SQUARE")

  • 8/11/2019 data Region

    5/101

    Else lv.ImageKey = ("IDI_24_ROUND_C") End If 'update CalculationsListView CalculationsListView.BeginUpdate() CalculationsListView.Items.Add(lv) CalculationsListView.EndUpdate()

    End If Next 'Me.Text = "ConData- Configure Continuous Data Output" Catch ex As Exception sw.WriteLine(Now.ToString + ": CondataMainfrmLoad Exception" + ex.Message) End Try End Function ''' ''' Function:UpdateCalList ''' Updates the calculation listview '''

    ''' ''' Public Function CondataUpdateCalList() Try ReDim CalList(13) 'update the calculation listview values CalList(0) = "" CalllistFlag(0) = "False" CalList(1) = "BASE" CalllistFlag(1) = "False" CalList(2) = "Digital" CalllistFlag(2) = "True" CalList(3) = "Direct Current"

    CalllistFlag(3) = "True" CalList(4) = "Single Ph.Frequency" ' CalllistFlag(4) = "True" CalList(5) = "Phasor" CalllistFlag(5) = "True" CalList(6) = "Single Phase Power" ' CalllistFlag(6) = "True" CalList(7) = "Single Ph.Power Eq." CalllistFlag(7) = "True" CalList(8) = "Magnitude" CalllistFlag(8) = "True" CalList(9) = "Positive Sequence" CalllistFlag(9) = "True" CalList(10) = "Three Ph. Frequency" CalllistFlag(10) = "True" CalList(11) = "Three Phase Power" CalllistFlag(11) = "True" CalList(12) = "Three Ph. Magnitude" CalllistFlag(12) = "True" Catch ex As Exception sw.WriteLine(Now.ToString + ": UpdateCallist Exception" + ex.Message) End Try End Function '''

    ''' Function:OnFileOpen ''' This function checks the same graph label is existed for two or more channels.

  • 8/11/2019 data Region

    6/101

    ''' If existed then gives a message to the user. ''' If params.txt file is existed for opened file then it populates the output list. ''' ''' ''' Public Function OnFileOpen()

    Try 'check only scf If SCFFlag Then ' each signal has a unique Graph Label.

    Dim cChan As UShort = GetNumberChannels() Dim iChan As UShort Dim iChan2 As UShort Dim bDuplicate As Boolean = False

    'check for duplicates that means opened file contains same graphlabel for 2 or more channels For iChan = 0 To cChan - 2

    For iChan2 = CUShort(iChan + 1) To cChan - 1 'comparing graph labels If GetChannelGraphLabel(iChan) = GetChannelGraphLabel(iChan2) Then bDuplicate = True Exit For End If Next iChan2 If bDuplicate Then Exit For End If Next iChan

    'if opened file has duplicates If bDuplicate Then ' Show an error box and clear the "ready" flag for the SCF

    ' to show that it really isn't ready after all.'AfxMessageBox(IDS_DUPLICATE_GRAPH_LABEL)DevComponents.DotNetBar.MessageBoxEx.Show("The SCF which was

    opened contains two or more channels with the same Graph Label, so it cannot beprocessed correctly.", "Condata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) SCFFlag = False End If End If 'check scf,tcf are opened If SCFFlag AndAlso TCFFlag Then Dim strWork As String = scfFileName Dim czDrive(_MAX_DRIVE) As SByte Dim czDir(_MAX_DIR) As SByte Dim czFName(_MAX_FNAME) As SByte Dim czExt(_MAX_EXT) As SByte Dim czTempPath(MAX_PATH + 1) As SByte 'store the scf name Dim strSCF_wExt As String = Path.GetFileName(scfFileName) nMaxCycles = 10000000 Dim breader As BinaryReader Dim xstream As FileStream

    'opening the tcf in read mode xstream = New FileStream(TcfFilename, FileMode.Open, FileAccess.Read)

  • 8/11/2019 data Region

    7/101

    breader = New BinaryReader(xstream) ReDim buf(xstream.Length) 'store the tcf data to buf buf = breader.ReadBytes(xstream.Length) breader.Close() 'calculate Hardware_Divisor,Software_Divisor using tcf Hardware_Divisor = buf(&H1E)

    Software_Divisor = FindSoftwareDivisor(TcfFilename) Dim s As Short = &H49C Dim breader1 As BinaryReader Dim xstream1 As FileStream xstream1 = New FileStream(TcfFilename, FileMode.Open, FileAccess.Read) breader1 = New BinaryReader(xstream1) breader1.BaseStream.Seek(breader1.BaseStream.Position + s, SeekOrigin.Begin) 'calculate B40_Speed using tcf B40_Speed = breader1.ReadUInt32 B40_Speed = B40_Speed >> 8

    breader1.Close() 'calculate the Scan_Rate_From_Tcf by using B40_Speed,Hardware_Divisor,Software_Divisor If Hardware_Divisor = 0 And Software_Divisor = 0 Then Scan_Rate_From_Tcf = 0 Else Scan_Rate_From_Tcf = ((1.0 * B40_Speed / Hardware_Divisor /Software_Divisor) + 0.5) End If

    'calculate the Scan_Rate_From_Scf by using using scf rate Scan_Rate_From_Scf = dataDescriptor.o_data.rate Dim Scan_Rate_Difference As Integer

    'calculate the Scan_Rate_Difference by using Scan_Rate_From_Tcf,Scan_Rate_From_Scf Scan_Rate_Difference = Scan_Rate_From_Tcf - Scan_Rate_From_Scf bWasModified = False If Labs(Scan_Rate_Difference) < 2 Then 'populate the output listview using _param file ReadExistingParameters(scfFileName) PromoteMagnitudes() Else 'if scf,tcf has some problem DevComponents.DotNetBar.MessageBoxEx.Show("The Trigger Configuration File (TCF) and System Configuration File " + vbCrLf + "(SCF) are set todifferent scan rates. Please close this program and use" + vbCrLf + " your trigger-editing software to correct the SCF and/or TCF.", "Condata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) SCFFlag = False TCFFlag = False End If Else 'based on the flags it displays the messages If (SCFFlag) Then DevComponents.DotNetBar.MessageBoxEx.Show("Trigger Configuration File (TCF) not successfully opened.", "Condata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 'Me.Text = "ConData- Configure Continuous Data Output"

    ScfStr = "" SCFFlag = False IntializeAll()

  • 8/11/2019 data Region

    8/101

    'CondataStructuresINtiallization()

    ElseIf (TCFFlag) Then DevComponents.DotNetBar.MessageBoxEx.Show("System Configuration File (SCF) not successfully opened.", "Condata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 'Me.Text = "ConData- Configure Continuous Data Output"

    ScfStr = "" SCFFlag = False IntializeAll() 'CondataStructuresINtiallization()

    Else DevComponents.DotNetBar.MessageBoxEx.Show("Neither the Trigger Configuration File (TCF) nor the System Configuration File (SCF) was successfully opened.", "Condata", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 'Me.Text = "ConData- Configure Continuous Data Output" ScfStr = "" SCFFlag = False

    IntializeAll() 'CondataStructuresINtiallization()

    End If 'close the main form by using the bWasModified flag

    End If NoRecFlag = False 'update the input listview,outputlistview,progress bars,inputlistview column text,outputlistview column text UpdateControls(0) 'update the progress bar,listview column text Statistics(True)

    Return Nothing Catch ex As Exception sw.WriteLine(Now.ToString + ": OnFileOpen Exception" + ex.Message) End Try End Function ''' ''' Function:ReadExistingParameters ''' This function updates the output list by reading the params.txt file. ''' While updating the output list it also checks the user defined names areexisted or not. If user defined names are existed then gives a message to the user. ''' For updating output list this function collects all information relatedto channels,

    ''' like glabel (short name),ident (Long Name), calculation name etc., ''' ''' ''' ''' Public Function ReadExistingParameters(ByVal scfname As String) Try Dim strParamPath As String 'check if _param file is exist

    strParamPath = Path.GetDirectoryName(scfFileName) + "\" + Path.GetFileNameWithoutExtension(scfFileName) + PARAMS_SUFFIX + ".txt" If File.Exists(strParamPath) Then

    'if _param is exits then opening that text file xstream = New FileStream(strParamPath, FileMode.Open, FileAccess.Read)

  • 8/11/2019 data Region

    9/101

    sr = New StreamReader(xstream) If sr.BaseStream.Position = sr.BaseStream.Length Then Exit Function End If Dim bDone As Boolean = False While (Not (bDone)) 'reading textfile line by line

    Dim strLine = sr.ReadLine() If sr.EndOfStream Then 'if text file reading the text upto end of that file then use the flag to exit the while loop bDone = True End If If Not (LineIn(strLine)) Then ' If this class could not reparse the line, let any other

    ' interested objects look at it. At this time the only

    ' other such object is Ad_Dlg of class CAdvancedD

    lg. AdvancedSettingsDialog.AdLineIn(strLine) End If End While 'close the _param file sr.Close() xstream.Close() Dim nAlternateNamesPresent As Integer = 0 'calculate the "Three Ph. Frequency" index in the calculation listview Dim iFrequency3 As UInteger = Element("Three Ph. Frequency") 'calculate the "Three Phase Power" index in the calculation listview

    Dim iPower3 As UInteger = Element("Three Phase Power") For i As Integer = 0 To MAXSIG - 1 If Not ((AlternateName(i) Is Nothing) Or (AlternateName(i) ="")) Then Dim strTestAlt As String = "" Dim outputstring As String = OutputsListView.Items(i).Text 'get the funciton name using AlternateName Dim funnname As String = getFunctionName(outputstring) 'get the channel name using AlternateName Dim chnl As String = GetInputName(outputstring) 'get the channel number in scf structure using Channel Name Dim nChannel As Integer = GetChannel(chnl) Dim s As String = funnname 'Getting the internal name by using the function name and Internal_V flag Dim strinternal As String = FN2(Internal_V, s) 'Getting the passed name by using the function name andpassedname flag Dim strpassedname As String = FN2(passedname, s)

    'if calculation is Single Ph.Frequency If strpassedname = "1Frq" Then strpassedname = "Single Ph.Frequency"

    'if calculation is Single Phase Power ElseIf strpassedname = "1Pwr" Then strpassedname = "Single Phase Power"

  • 8/11/2019 data Region

    10/101

    'if calculation is Magnitude ElseIf strpassedname = "1Mag" Then strpassedname = "Magnitude" 'if calculation is Direct Current ElseIf strpassedname = "Dir" Then strpassedname = "Direct Current" 'if calculation is Phasor

    ElseIf strpassedname = "Phsr" Then strpassedname = "Phasor" 'if calculation is Single Ph.Power Eq. ElseIf strpassedname = "1Pwr3Eq" Then strpassedname = "Single Ph.Power Eq." 'if calculation is Single Frequency ElseIf strpassedname = "3Frq" Then strpassedname = "Three Ph. Frequency" 'if calculation is Three Ph. Magnitude ElseIf strpassedname = "3Mag" Then strpassedname = "Three Ph. Magnitude" 'if calculation is Positive Sequence

    ElseIf strpassedname = "PosSeq" Then strpassedname = "Positive Sequence" 'if calculation is Three Phase Power ElseIf strpassedname = "3Pwr" Then strpassedname = "Three Phase Power" End If 'Getting the passed name by using the "Three Ph. Magnitude" and passedname flag Dim str3 As String = FN1(passedname, "Three Ph. Magnitude") 'set the flag true or false based on the channel and function name Dim bPromote As Boolean = IsInList(iFrequency3, nChannel

    ) Or IsInList(iPower3, nChannel) If (strinternal = "SQUARED" And bPromote = True) Then 'prepare the outputlistview string based the funcntion name and channel name strTestAlt = str3 + " on " + DemandChannelLongname(nChannel) + "(" + DemandChannelGraphLabel(nChannel) + ")" Else 'prepare the outputlistview string based the funcntion name and channel name strTestAlt = strpassedname + " on " + DemandChannelLongname(nChannel) + "(" + DemandChannelGraphLabel(nChannel) + ")" 'System.Text.RegularExpressions.Regex.Replace(DemandChannelGraphLabel(nChannel), "\W", " ").Trim End If If AlternateName(i).Equals(strTestAlt) Then

    Else 'increase the count when changing of alternate names,strTestAlt nAlternateNamesPresent = nAlternateNamesPresent + 1 End If End If Next 'if nAlternateNamesPresent value increaes then is gives a message

    If CBool(nAlternateNamesPresent) Then DevComponents.DotNetBar.MessageBoxEx.Show("One or more outputs for this configuration have been given user-defined names.", "Condata", Messa

  • 8/11/2019 data Region

    11/101

    geBoxButtons.OK, MessageBoxIcon.Exclamation) End If 'set the defaults values in the AdvancedSettingsDialog AdvancedSettingsDialog.UseDefaults() Else For k As Integer = 0 To AlternateName.Length - 1 AlternateName(k) = ""

    Next 'if _param is not existing then it return nothing Return Nothing End If Catch ex As Exception sw.WriteLine(Now.ToString + ": ReadExistingParameters Exception" + ex.Message) End Try End Function ''' ''' Function:PromoteMagnitudes ''' Check the params txt file opearations.

    ''' ''' ''' Public Function PromoteMagnitudes() Try

    Dim iMagnitude1, iMagnitude3, iPositive As UInteger

    iMagnitude1 = Element("Magnitude") iMagnitude3 = Element("Three Ph. Magnitude") iPositive = Element("Positive Sequence") Dim n As Integer = OutputsListView.Items.Count

    Dim nInput As UShort Dim nItemData As UInteger Dim nFunction As UInteger Dim i, iFix, iSearch, nAlternates As Integer Dim nTest As UInteger For i = 0 To straAlternate.Count - 1 uintaAlternate(i) = "" Next uintaAlternate = straAlternate 'For i = 0 To AlternateName.Length - 1 ' uintaAlternate(i) = AlternateName(i) 'Next For i = 0 To straAlternate.Count - 1 uintaAlternate(i) = AlternateName(i) Next i = n - 1 While (i >= 0) ' nItemData = NItemArray(i) nInput = GetChannel(GetInputName(OutputsListView.Items(i).Text)) nFunction = Element(getFunctionName(OutputsListView.Items(i).Text))

    ' LTS(CString("Item=") + str(i) + ", " +

    ' "Input(" + str(nInput) + ")=" +

    ' a_scf.DemandChannelGraphLabel(nInput) + ", " +' "Function(" + str(nFunction) + ")=" +

  • 8/11/2019 data Region

    12/101

    ' CFunction::Element(nFunction)->GetAbbreviation());

    If (nFunction = iMagnitude3 Or (nFunction = iMagnitude1 AndAlsoIsInputThreePhase(nInput))) Then

    ' LTS("Item " + str(i) + " is a magnitude on " +

    ' str(nInput) + ", which has a three-phase on it.");

    nFunction = iMagnitude3 ' Dim nOldItemData As UInteger = NItemArray(i) 'Dim nNewItemData As UInteger = (nFunction

  • 8/11/2019 data Region

    13/101

    sage) End Try End Function ''' ''' Function:IsInputThreePhase ''' Check out given input channels calculation is three pahse or not '''

    ''' ''' ''' Public Function IsInputThreePhase(ByVal Input As UShort) As Boolean Try

    Dim n As Integer = OutputsListView.Items.Count Dim ResultValue As Boolean = False Dim internalval As String Dim i As Integer For i = 0 To n - 1

    Dim nInput As Integer = GetInputName(OutputsListView.Items(i).Text) Dim nFunction As String = getFunctionName(OutputsListView.Items(i).Text)

    If (nInput = Input) Then internalval = FN1(Is_ThreePh, nFunction) If (nFunction And (n = "true")) Then ResultValue = True End If End If Next

    Return ResultValue

    Catch ex As Exception

    End Try End Function

    ''' ''' Function:Element ''' It returns the index for calculation. ''' ''' ''' ''' Public Function Element(ByVal InternalName As String) As Integer Try 'return the calllist array index when compare the calculationlistview string and calllist array string

    Dim n As Integer = CalList.Length Dim i As Integer For i = 0 To n - 1 strInternalName = CalList(i)

    'fail safe -White Box Testing Start

    If InternalName = "" Then Exit Function End If

  • 8/11/2019 data Region

    14/101

    'fail safe -White Box Testing End

    'fail safe -White Box Testing Start If strInternalName Is Nothing Then Exit Function End If 'fail safe -White Box Testing End

    If strInternalName.Equals(InternalName) Then Return i End If Next Catch ex As Exception sw.WriteLine(Now.ToString + ": Element Exception" + ex.Message) End Try End Function ''' ''' Function: It returns the calculation name with passed index. '''

    ''' ''' ''' Public Function Element(ByVal Index1 As UInteger) As String Try 'Giving the index value then it returns the calllist string Dim n As Integer = CalList.Length 'failsafe If Index1 < 0 Then Exit Function End If 'failsafe

    'fail safe -White Box Testing Start If CalList(Index1) Is Nothing Then Exit Function End If 'fail safe -White Box Testing End

    If (Index1 >= n Or Not (CalList(Index1).Length >= 0)) Then ' return &cfDummy;

    Else Return CalList(Index1).Trim("") End If Catch ex As Exception sw.WriteLine(Now.ToString + ": Element Exception" + ex.Message) End Try End Function ''' ''' Function:ByInternalName ''' It returns calculation index ''' ''' ''' ''' Public Function ByInternalName(ByVal InternalName As String) As Integer Try

    'return the calllist array index when compare the internalname string and calllist array string

    Dim n As Integer = CalList.Length

  • 8/11/2019 data Region

    15/101

    Dim i As Integer For i = 0 To n - 1

    'fail safe -White Box testing Start If CalList(i) Is Nothing Then Exit Function End If

    'fail safe -White Box testing End

    strInternalName = CalList(i) If strInternalName.Equals(InternalName) Then Return i End If Next Catch ex As Exception sw.WriteLine(Now.ToString + ": ByInternalName Exception" + ex.Message) End Try End Function

    ''' ''' Function:FindSoftwareDivisor ''' If tcf is exist then update the buffer and work ''' ''' ''' ''' Public Function FindSoftwareDivisor(ByVal tcfname As String) As Integer Try 'calculte the software divisor value by using TCF

    Dim breader As BinaryReader Dim xstream As FileStream

    'fail safe -White Box Testing Start If tcfname = "" Then Exit Function End If 'fail safe -White Box Testing End

    xstream = New FileStream(tcfname, FileMode.Open, FileAccess.Read) breader = New BinaryReader(xstream) ReDim buf(xstream.Length) buf = breader.ReadBytes(xstream.Length) breader.Close() If buf(&H18) Then Dim i, the_slow, work As Integer work = buf(&H18) work = Not (work) And &HFF the_slow = 0 For i = 0 To 7 the_slow = 1 Next Return the_slow End If

    Return 0 Catch ex As Exception sw.WriteLine(Now.ToString + ": FindSoftwareDivisor Exception" + ex.M

  • 8/11/2019 data Region

    16/101

    essage) End Try End Function ''' ''' Function:Labs ''' This function returns positive value. '''

    ''' ''' ''' Public Function Labs(ByVal d As Integer) As Integer Try 'it replays -ve values to +ve values

    If d < 0 Then d = d * (-1) Return d ElseIf d >= 0 Then Return d End If

    Catch ex As Exception sw.WriteLine(Now.ToString + ": Labs Exception" + ex.Message) End Try End Function ''' ''' Function:DemandChannelGraphLabel ''' First this function checks passed channel is a individual digital channel or analog channel. ''' Based on the channel type it returns glabel. ''' If glabel is empty then returns ident. ''' ''' '''

    ''' Public Function DemandChannelGraphLabel(ByVal Channel As UShort) As String Try Dim CReturn As String = "" 'if channel number is digital then it returns digital channel name

    If (CBool(Channel And IND_DIG)) Then Return DemandDigitalGraphLabel(Channel) Else 'checking if the channel is with in limit or not

    'ONINVALIDCHANNEL(CReturn, Channel) If (Channel < 0 Or Channel >= MAXSIG) Then Return Nothing End If

    'fail safe -WhiteBox Testing Start If dataDescriptor.sigrec Is Nothing Then Exit Function End If 'fail safe -WhiteBox Testing End

    'return the glable value in the scf structure CReturn = dataDescriptor.sigrec(Channel).glable Dim s As String = CReturn.Trim("") CReturn = s CReturn.TrimStart()

    CReturn.TrimEnd() 'if glable string is empty then it returns ident value in the scf structure

  • 8/11/2019 data Region

    17/101

    If (CReturn = "") Then CReturn = dataDescriptor.sigrec(Channel).ident CReturn = CReturn.Trim("") CReturn.TrimStart() CReturn.TrimEnd() 'if ident is empty string the return channel number If (CReturn = ".") Then

    Return Channel.ToString ' return CString("[#") + str((long)Channel) + ".]";

    Else Return CReturn End If Else Return CReturn End If End If Catch ex As Exception sw.WriteLine(Now.ToString + ": DemandChannelGraphLabel exception" +

    ex.Message) End Try End Function ''' ''' Function:DemandDigitalGraphLabel ''' This function returns glabel or ident. ''' If the passed channel's glabel is empty then it returns ident. ''' ''' ''' ''' Public Function DemandDigitalGraphLabel(ByVal DigitalChannel As UShort) As String

    Try 'returns digital channel glabel string

    Dim str As String

    'fail safe -White Box testing Start If dataDescriptor.digitalchannel Is Nothing Then Exit Function End If 'fail safe -White Box testing End

    str = dataDescriptor.digitalchannel(DigitalChannel).glabel 'if digital channel glabelstring is empty then return digital channel ident If str = " " Then str = dataDescriptor.digitalchannel(DigitalChannel).ident End If str = str.Trim("") Return str Catch ex As Exception sw.WriteLine(Now.ToString + ": DemandDigitalGraphLabel exception" +ex.Message) End Try End Function

    ''' ''' Function:FN2 ''' This function returns text for hint textbaox, description for output lis

  • 8/11/2019 data Region

    18/101

    t 2nd column, calculation name and internal name ''' It returns above information based on calculation index and calculationname. ''' ''' ''' '''

    ''' Public Function FN2(ByVal Func As UInteger, ByVal pParameters As String) AsString Try 'takes the function type,calculation listview name as input and retruns a string Dim Creturn As String = ""

    'fail safe -White Box Testing Start If pParameters Is Nothing Then Exit Function End If

    'fail safe -White Box Testing End

    If pParameters.Length > 0 Then 'if calculation listview string as "Digital" and giving the fucntion type to Digstring() then it returns string If (pParameters.Equals("Digital")) Then Creturn = DigString(Func)

    If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Single Ph.Frequency" andgiving the fucntion type to SinglePhString() then it returns string ElseIf (pParameters.Equals("Single Ph.Frequency") Or pParameters.Equals("1Frq")) Then Creturn = SinglePhString(Func)

    If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Single Phase Power" andgiving the fucntion type to SinglePhPowerString() then it returns string ElseIf (pParameters.Equals("Single Phase Power") Or pParameters.Equals("1Pwr")) Then Creturn = SinglePhPowerString(Func)

    If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Magnitude" and giving the fucntion type to MagString() then it returns string ElseIf (pParameters.Equals("Magnitude") Or pParameters.Equals("1

    Mag")) Then Creturn = MagString(Func)

  • 8/11/2019 data Region

    19/101

    If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Direct Current" and giving the fucntion type to DirectCurrentString() then it returns string

    ElseIf (pParameters.Equals("Direct Current") Or pParameters.Equals("Dir")) Then Creturn = DirectCurrentString(Func)

    If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Phasor" and giving the fucntion type to PhasorString() then it returns string ElseIf (pParameters.Equals("Phasor") Or pParameters.Equals("Phsr

    ")) Then

    Creturn = PhasorString(Func) If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Single Ph.Power Eq." andgiving the fucntion type to SinglePhPowerEqString() then it returns string ElseIf (pParameters.Equals("Single Ph.Power Eq.") Or pParameters.Equals("1Pwr3Eq")) Then

    Creturn = SinglePhPowerEqString(Func) If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Three Ph. Frequency" andgiving the fucntion type to ThreePhFrequencyString() then it returns string ElseIf (pParameters.Equals("Three Ph. Frequency") Or pParameters.Equals("3Frq")) Then

    Creturn = ThreePhFrequencyString(Func) If Creturn = "" Then Creturn = "0" End If Return Creturn

    'if calculation listview string as "Three Ph. Magnitude" andgiving the fucntion type to ThreePhaseMagnitudeString() then it returns string ElseIf (pParameters.Equals("Three Ph. Magnitude") Or pParameters.Equals("3Mag")) Then

    Creturn = ThreePhaseMagnitudeString(Func) If Creturn = "" Then Creturn = "0"

    End If Return Creturn

  • 8/11/2019 data Region

    20/101

    'if calculation listview string as "Positive Sequence" and giving the fucntion type to PositiveString() then it returns string ElseIf (pParameters.Equals("Positive Sequence") Or pParameters.Equals("PosSeq")) Then

    Creturn = PositiveString(Func) If Creturn = "" Then

    Creturn = "0" End If Return Creturn

    'if calculation listview string as "Three Phase Power" and giving the fucntion type to ThreePhasePowerString() then it returns string ElseIf (pParameters.Equals("Three Phase Power") Or pParameters.Equals("3Pwr")) Then

    Creturn = ThreePhasePowerString(Func) If Creturn = "" Then Creturn = "0"

    End If Return Creturn

    'if calculation listview string as "" and giving the fucntion type to "" then it returns "" Else If Creturn = "" Then Creturn = "0" End If Return Creturn End If End If Return Creturn

    Catch ex As Exception sw.WriteLine(Now.ToString + ": FN2 Exception" + ex.Message) End Try End Function ''' ''' Function:FN1 ''' This function returns text for hint textbaox, description for output list 2nd column, calculation name and internal name ''' It returns above information based on calculation index and calculationname.

    ''' ''' ''' ''' ''' Public Function FN1(ByVal Func As UInteger, ByVal pParameters As String) AsString Try 'takes the function type,calculation listview name as input and retruns a string Dim Creturn As String = "" If pParameters.Length > 0 Then 'returns string for "Digital" If (pParameters = "Digital") Then Creturn = DigString(Func)

    Return Creturn

    'returns string for "Single Ph.Frequency"

  • 8/11/2019 data Region

    21/101

    ElseIf (pParameters = "Single Ph.Frequency") Then Creturn = SinglePhString(Func) Return Creturn

    'returns string for "Single Phase Power" ElseIf (pParameters = "Single Phase Power") Then Creturn = SinglePhPowerString(Func)

    Return Creturn

    'returns string for "Magnitude" ElseIf (pParameters = "Magnitude") Then Creturn = MagString(Func) Return Creturn

    'if calculation listview string as "Direct Current" and giving the fucntion type to DirectCurrentString() then it returns string ElseIf pParameters = "Direct Current" Then Creturn = DirectCurrentString(Func) Return Creturn

    'returns string for "Phasor" ElseIf pParameters = "Phasor" Then Creturn = PhasorString(Func) Return Creturn

    'returns string for "Single Ph.Power Eq." ElseIf pParameters = "Single Ph.Power Eq." Then Creturn = SinglePhPowerEqString(Func) Return Creturn

    'returns string for "Three Ph. Frequency" ElseIf pParameters = "Three Ph. Frequency" Then

    Creturn = ThreePhFrequencyString(Func) Return Creturn

    'returns string for "Three Ph. Magnitude" ElseIf pParameters = "Three Ph. Magnitude" Then Creturn = ThreePhaseMagnitudeString(Func) Return Creturn

    'returns string for "Positive Sequence" ElseIf pParameters = "Positive Sequence" Then Creturn = PositiveString(Func) Return Creturn

    'returns string for "Three Phase Power" ElseIf pParameters = "Three Phase Power" Then Creturn = ThreePhasePowerString(Func) Return Creturn

    Else Return Creturn End If End If Return Creturn Catch ex As Exception

    sw.WriteLine(Now.ToString + ": FN1 Exception" + ex.Message) End Try End Function

  • 8/11/2019 data Region

    22/101

    ''' ''' Function:PositiveString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for Positive calculation. ''' '''

    ''' ''' Public Function PositiveString(ByVal func As UInteger) As String Try If func = actulname Then Return "Positive Sequence" End If 'based on the function type returns the string

    'if fucntion type Test_Input then it returns empty string If func = Test_Input Then Return ""

    'if fucntion type Find_Hints then it returns string ElseIf func = Find_Hints Then Return ("Select one sinusoidal (non-DC) Phase A analog voltage or current input for this function.The function searches for the other two phases, then performs a positive sequence calculation." + vbCrLf + vbCrLf + "Output result of positive sequence computation:" + vbCrLf + "1) Real component." + vbCrLf + "2) Imaginary component." + vbCrLf + vbCrLf + " All three matching phases (all voltage or all current) from the same line or must be available and configured using the to perform this calculation.")

    'if fucntion type Short_Name then it returns "" ElseIf func = Short_Name Then Return ""

    'if fucntion type Is_ThreePh then it returns true ElseIf func = Is_ThreePh Then Return "True"

    'if fucntion type Two_Output then it returns string ElseIf func = Two_Output Then Return "Outputs are: 1.real , 2.imaginary"

    'if fucntion type Need_Phasr then it returns "3" ElseIf func = Need_Phasr Then Return "3"

    'if fucntion type Find_Usage then it returns update Quad structure ElseIf func = Find_Usage Then Quad1.Quad(4L, 2L, 48L, 2L) Current = Quad1 Return "(Quad, Quad(4L, 2L, 48L, 2L))"

    'if fucntion type passedname then it returns string ElseIf func = passedname Then Return "PosSeq"

    'if fucntion type Internal_V then it returns string

    ElseIf (func = Internal_V) Then Return "POSITIVE"

  • 8/11/2019 data Region

    23/101

    'if fucntion type "" then it returns "" Else Return "" End If Catch ex As Exception sw.WriteLine(Now.ToString + ": PositiveString Exception" + ex.Message)

    End Try End Function ''' ''' Function:ThreePhasePowerString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Three Phase Power" calculation. ''' ''' ''' ''' Public Function ThreePhasePowerString(ByVal func As UInteger) As String

    Try If func = actulname Then Return "Three Phase Power" End If 'if fucntion type "" then it returns "" If func = Test_Input Then Return ""

    'if fucntion type Short_Name then it returns "" ElseIf func = Short_Name Then Return ""

    'if fucntion type Is_ThreePh then it returns true

    ElseIf func = Is_ThreePh Then Return "True"

    'if fucntion type Two_Output then it returns string ElseIf func = Two_Output Then Return "Outputs are 1.real , 2.reactive"

    'if fucntion type Need_Phasr then it returns 6 ElseIf func = Need_Phasr Then Return "6"

    'if fucntion type Find_Usage then update the Quad structure ElseIf func = Find_Usage Then Quad1.Quad(10L, 12L, 180L, 2L) Current = Quad1 Return "(Quad, Quad(10L, 12L, 180L, 2L)"

    'if fucntion type Find_Hints then it returns string ElseIf func = Find_Hints Then Return "Select one sinusoidal (non-DC) Phase A analog current input for this function. The function searches for all the matching voltage and current phases, then performs a three-phase power calculation." + vbCrLf + vbCrLf+ "Output:" + vbCrLf + " 1) Real power." + vbCrLf + " 2) Reactive power." + vbCrLf + vbCrLf + "All six matching voltage and current phases (Va, Vb, Vc, Ia, Ib, Ic) must be available and configured using the ""Edit->Signal Attributes"" dia

    log above to perform this calculation."

    'if fucntion type passedname then it returns "3Pwr"

  • 8/11/2019 data Region

    24/101

    ElseIf func = passedname Then Return "3Pwr"

    'if fucntion type Internal_V then it returns "POWER" ElseIf (func = Internal_V) Then Return "POWER"

    'if fucntion type "" then it returns "" Else Return "" End If

    Catch ex As Exception sw.WriteLine(Now.ToString + ": ThreePhasePowerString Exception" + ex.Message) End Try End Function ''' ''' Function:ThreePhaseMagnitudeString

    ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Three Ph. Magnitude" calculation. ''' ''' ''' ''' Public Function ThreePhaseMagnitudeString(ByVal fun As UInteger) As String Try If fun = actulname Then Return "Three Ph. Magnitude" End If 'if fucntion type Is_ThreePh then it returns ""

    If fun = Is_ThreePh Then Return "True"

    'if fucntion type Find_Usage then it update the Quad structure ElseIf fun = Find_Usage Then Quad1.Quad(4L, 2L, 44L, 1L) Current = Quad1 Return " Quad(4L, 2L, 44L, 1L)"

    'if fucntion type Need_Phasr then it returns 3 ElseIf fun = Need_Phasr Then Return "3"

    'if fucntion type Find_Hints then it returns string ElseIf fun = Find_Hints Then Return "Select one sinusoidal (non-DC) Phase A analog input forthis function. The function searches for the other two matching phases, then performs a three-phase magnitude calculation." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "Result of three-phase magnitude calculation." + vbCrLf + vbCrLf + " nAllthree matching phases (all voltage or all current) from the same line or \Group\must be available and configured using the Edit->Signal Attributesdialog aboveto perform this calculation."

    'if fucntion type Test_Input then it returns "" ElseIf fun = Test_Input Then

    Return ""

    'if fucntion type Short_Name then it returns ""

  • 8/11/2019 data Region

    25/101

    ElseIf fun = Short_Name Then Return ""

    'if fucntion type passedname then it returns "3Mag" ElseIf fun = passedname Then Return "3Mag"

    'if fucntion type Internal_V then it returns "SQUARE3" ElseIf (fun = Internal_V) Then Return "SQUARE3"

    'if fucntion type "" then it returns "" Else Return "" End If Catch ex As Exception sw.WriteLine(Now.ToString + ": ThreePhaseMagnitudeString Exception"+ ex.Message) End Try

    End Function ''' ''' Function:DirectCurrentString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Direct Current" calculation. ''' ''' ''' ''' Public Function DirectCurrentString(ByVal fun As UInteger) As String Try 'if fucntion type Need_Direc then it returns "1"

    If fun = actulname Then Return "Direct Current" End If If fun = Need_Direc Then Return "1"

    'if fucntion type Find_Usage then it update the Quad structure ElseIf fun = Find_Usage Then Quad1.Quad(6L, 8L, 15L, 1L) Current = Quad1 Return "Quad(6L, 8L, 15L, 1L)"

    'if fucntion type Find_Hints then it returns string ElseIf fun = Find_Hints Then Return "Select one DC (direct current) analog voltage or currentfor this function." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "Slightly filteredbut otherwise unchanged value of the input."

    'if fucntion type Short_Name then it returns "" ElseIf fun = Short_Name Then Return ""

    'if fucntion type Test_Input"" then it returns "" ElseIf fun = Test_Input Then Return ""

    'if fucntion type passedname then it returns "Dir" ElseIf fun = passedname Then

  • 8/11/2019 data Region

    26/101

    Return "Dir"

    'if fucntion type Internal_V then it returns "DIRECT" ElseIf (fun = Internal_V) Then Return "DIRECT"

    'if fucntion type "" then it returns ""

    Else Return "" End If Catch ex As Exception sw.WriteLine(Now.ToString + ": DirectCurrentString Exception" + ex.Message) End Try End Function ''' ''' Function:PhasorString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc.,

    ''' information for "Phasor" calculation. ''' ''' ''' ''' Public Function PhasorString(ByVal fun As UInteger) As String Try If fun = actulname Then Return "Phasor" End If 'if fucntion type Two_Output then it returns string If fun = Two_Output Then

    Return "Outputs are: 1.real , 2.imaginary"

    'if fucntion type Need_Phasr then it returns 1 ElseIf fun = Need_Phasr Then Return "1"

    'if fucntion type "" then it returns "" ElseIf fun = Find_Usage Then Quad1.Quad(2L, 0L, 15L, 2L) Current = Quad1 Return "Quad(2L, 0L, 15L, 2L)"

    'if fucntion type Find_Hints then it returns string ElseIf fun = Find_Hints Then Return "Select one sinusoidal (non-DC) analog input for this function." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "1) Real component of the phasor." + vbCrLf + "2) Imaginary component of the phasor."

    'if fucntion type Test_Input then it returns "" ElseIf fun = Test_Input Then Return "" '"Test_Input"

    'if fucntion type passedname then it returns "Phsr" ElseIf fun = passedname Then Return "Phsr"

    'if fucntion type Internal_V then it returns "PHASOR" ElseIf (fun = Internal_V) Then

  • 8/11/2019 data Region

    27/101

    Return "PHASOR"

    'if fucntion type "" then it returns "" Else Return "" End If

    Catch ex As Exception sw.WriteLine(Now.ToString + ": PhasorString Exception" + ex.Message) End Try End Function ''' ''' Function:SinglePhPowerEqString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Single Ph. Power" calculation. ''' ''' '''

    ''' Public Function SinglePhPowerEqString(ByVal fun As UInteger) As String Try

    If fun = actulname Then Return "Single Ph.Power Eq." End If If fun = Two_Output Then Return "Outputs are: 1.real , 2.reactive" ElseIf fun = Need_Phasr Then Return "2" ElseIf fun = Find_Usage Then Quad1.Quad(7L, 8L, 113L, 2L)

    Current = Quad1 Return "Quad(7L, 8L, 113L, 2L)" ElseIf fun = Find_Hints Then Return "Select one sinusoidal (non-DC) analog current input forthis function. The function searches for a matching voltage input, then performs a single-phase power calculation, then multiplies by 3 to estimate total power for a three-phase line." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "1) Real power." + vbCrLf + "2) Reactive power." + vbCrLf + vbCrLf + "Both current and matching voltage must be available and configured using the Edit->Signal Attributes\dialog above to perform this calculation." ElseIf fun = Short_Name Then Return "" ElseIf fun = Test_Input Then Return "" '"Test_Input" ElseIf fun = passedname Then Return "1Pwr3Eq" ElseIf (fun = Internal_V) Then Return "POWERE" Else Return FN2(fun, "Phasor") End If Catch ex As Exception sw.WriteLine(Now.ToString + ": SinglePhPowerEqString Exception" + ex.Message) End Try

    End Function ''' ''' Function:DigString

  • 8/11/2019 data Region

    28/101

    ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Digital" calculation. ''' ''' ''' '''

    Public Function DigString(ByVal func As UInteger) As String Try If func = actulname Then Return "Digital" End If If (func = Two_Output) Then Return "Outputs are: 1.value , 2.multiple changes" ElseIf (func = Need_Digit) Then Return "1" ElseIf (func = Find_Usage) Then Quad1.Quad(2L, 0L, 13L, 2L) Current = Quad1

    Return "Quad, Quad(2L, 0L, 13L, 2L)" ElseIf (func = Find_Hints) Then Return "Select one Digital input for this function." + vbCrLf +vbCrLf + "Output:" + vbCrLf + "1) Value of the data at the end of the storage interval." + vbCrLf + "2) Indication of which bits changed more than once duringthe storage interval." ElseIf (func = Short_Name) Then Return "" ElseIf (func = passedname) Then Return "Digital" ElseIf (func = Internal_V) Then Return "DIGITAL" Else

    Return "" '"base" End If Catch ex As Exception sw.WriteLine(Now.ToString + ": DigString Exception" + ex.Message) End Try End Function ''' ''' Function:SinglePhString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Single Ph. Frequency" calculation. ''' ''' ''' ''' Public Function SinglePhString(ByVal func As UInteger) As String Try If func = actulname Then Return "Single Ph.Frequency" End If If func = Deadband_V Then Return "true" ElseIf func = Need_Phasr Then Return "1" ElseIf func = Find_Usage Then

    Quad1.Quad(6L, 8L, 152L, 1L) Current = Quad1 Return ("(Quad, Quad(6L, 8L, 152L, 1L))")

  • 8/11/2019 data Region

    29/101

    ElseIf func = Find_Hints Then Return "Select one sinusoidal (non-DC) analog voltage input forthis function." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "Result of single-phase frequency computation." ElseIf func = Short_Name Then Return "" ElseIf func = Test_Input Then

    Return "" '"test_input" ElseIf func = passedname Then Return "1Frq" ElseIf (func = Internal_V) Then Return "FREQ1" Else Return "" '"Base" End If Catch ex As Exception sw.WriteLine(Now.ToString + ": SinglePhString Exception" + ex.Message) End Try

    End Function ''' ''' Function:SinglePhPowerString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Single Phase Power" calculation. ''' ''' ''' ''' Public Function SinglePhPowerString(ByVal func As UInteger) As String Try If func = actulname Then

    Return "Single Phase Power" End If If func = Two_Output Then Return "Outputs are: 1.real , 2.reactive" ElseIf func = Need_Phasr Then Return "2" ElseIf func = Find_Usage Then Quad1.Quad(7L, 8L, 113L, 2L) Current = Quad1 Return "(Quad, Quad(7L, 8L, 113L, 2L))" ElseIf func = Find_Hints Then Return "Select one sinusoidal (non-DC) analog current input forthis function.The function searches for a matching voltage input, then performsa single-phase power calculation." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "1)Real power." + vbCrLf + "2) Reactive power." + vbCrLf + vbCrLf + "Both current and matching voltage must be available and configured using the Edit->Signal Attributes\ dialog above to perform this calculation." ElseIf (func = Short_Name) Then Return "" ElseIf func = Test_Input Then Return "" '"Test_Input" ElseIf func = passedname Then Return "1Pwr" ElseIf (func = Internal_V) Then Return "POWER1"

    Else Return FN2(func, "Phasor")

  • 8/11/2019 data Region

    30/101

    ' Return "Phasor"

    End If Catch ex As Exception sw.WriteLine(Now.ToString + ": SinglePhPowerString Exception" + ex.Message) End Try

    End Function ''' ''' Function:MagString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Magnitude" calculation. ''' ''' ''' ''' Public Function MagString(ByVal func As UInteger) As String Try

    If func = actulname Then Return "Magnitude" End If If func = Need_Phasr Then Return "1" ElseIf func = Find_Usage Then Quad1.Quad(2L, 0L, 11L, 1L) Current = Quad1 Return "(Quad, Quad(2L, 0L, 11L, 1L))" ElseIf func = Find_Hints Then Return ("Select one sinusoidal (non-DC) analog input for this function." + vbCrLf + vbCrLf + "Output:" + vbCrLf + "Value equal to the square ofthe amplitude.")

    ElseIf func = Short_Name Then Return "" ElseIf func = Two_Output Then Return "" '"Two_outs" ElseIf func = passedname Then Return "1Mag" ElseIf (func = Internal_V) Then Return "SQUARED" Else Return "" '"Base" End If Catch ex As Exception sw.WriteLine(Now.ToString + ": MagString Exception" + ex.Message) End Try End Function ''' ''' Function:ThreePhFrequencyString ''' This function returns text for hint textbox,Output list 2nd column description and internal name etc., ''' information for "Three Ph. frequency" calculation. ''' ''' ''' ''' Public Function ThreePhFrequencyString(ByVal fun As UInteger) As String

    Try If fun = actulname Then Return "Three Ph. Frequency"

  • 8/11/2019 data Region

    31/101

    End If If fun = Short_Name Then Return "" ElseIf Find_Hints = Is_ThreePh Then Return "True" ElseIf fun = Deadband_V Then Return "True"

    ElseIf fun = Need_Phasr Then Return "3" ElseIf fun = Find_Usage Then Quad1.Quad(7L, 10L, 185L, 1L) Current = Quad1 Return "Quad(7L, 10L, 185L, 1L)" ElseIf fun = Find_Hints Then Return "Select one sinusoidal (non-DC) Phase A analog voltage input for this function.The function searches for the matching voltage phases, then performs a three-phase frequency calculation on those three inputs" + vbCrLf+ vbCrLf + "Output:" + vbCrLf + "Result of three-phase frequency computation." +vbCrLf + vbCrLf + "All three matching voltage phases must be available and conf

    igured using the Edit->Signal Attributes dialog above to perform this calculation." ElseIf fun = Test_Input Then Return "" ' "Test_Input" ElseIf fun = passedname Then Return "3Frq" ElseIf (fun = Internal_V) Then Return "FREQ" Else Return "" 'BASE End If Catch ex As Exception sw.WriteLine(Now.ToString + ": ThreePhFrequencyString Exception" + e

    x.Message) End Try End Function ''' ''' Function:FindInList ''' This function returns output index for each and every output of output listview. ''' ''' ''' ''' ''' Public Function FindInList(ByVal Funct As UInteger, ByVal Signal As UShort)As Integer Try Dim Mask As UInteger = &HFFFFFFL Dim Find As UInteger = ((Funct

  • 8/11/2019 data Region

    32/101

    ElseIf funname = "1Pwr" Then funname = "Single Phase Power" ElseIf funname = "1Mag" Then funname = "Magnitude" ElseIf funname = "Dir" Then funname = "Direct Current" ElseIf funname = "Phsr" Then

    funname = "Phasor" ElseIf funname = "1Pwr3Eq" Then funname = "Single Ph.Power Eq." ElseIf funname = "3Frq" Then funname = "Three Ph. Frequency" ElseIf funname = "3Mag" Then funname = "Three Ph. Magnitude" ElseIf funname = "PosSeq" Then funname = "Positive Sequence" ElseIf funname = "3Pwr" Then funname = "Three Phase Power" End If

    Dim funindex As Integer = Element(funname)

    If ((((funindex

  • 8/11/2019 data Region

    33/101

    ''' This function calculates the system capacity percentages and displays them. ''' And also gives warning messages if any percentages are exceeds over limit. ''' Maximum percentage is 124. If that limnit exceeds it populates warning messages. ''' This function updates the output listview column text based on no.of sig

    nals. ''' ''' ''' ''' Public Function Statistics(ByVal WarnIfOver As Boolean) As Boolean Try Dim bReturn As Boolean = False Dim strShow As String 'calculate the maximum output listview count CalculateMaxInList() Dim strHeading As String

    ' Find used outputs. Dim nTotalSelected As UInteger nTotalSelected = 0 'calculate output listview items,subitems count For i As Integer = 0 To OutputsListView.Items.Count - 1 nTotalSelected = nTotalSelected + OutputsListView.Items(i).SubItems.Count Next

    ' Set the Selected List headings according to number of selections

    ' allowed and used, or a simplified heading if no Scf is open.

    If (nTotalSelected > nMaxInList) Then

    strHeading = ("Outputs (") + (nTotalSelected.ToString) + " exceeds " + (nMaxInList.ToString) + ")" OutputsListView.Columns(0).Text = strHeading bReturn = True

    ElseIf (nTotalSelected + 1 > nMaxInList) Then 'update the output listview column text

    strHeading = ("Outputs (") + (nTotalSelected.ToString) + " - Full)" OutputsListView.Columns(0).Text = strHeading

    ElseIf (CBool(nTotalSelected)) Then ' At least one selection was made.

    strHeading = ("Outputs (") + (nTotalSelected.ToString) + " -Limit of " + (nMaxInList.ToString) + ")" OutputsListView.Columns(0).Text = strHeading ElseIf (SCFFlag) Then ' There is a known number of signals possible, so show that.

    strHeading = ("Outputs (Limit of ") + (nMaxInList.ToString) +")"

    OutputsListView.Columns(0).Text = strHeading

    Else

  • 8/11/2019 data Region

    34/101

    ' No signals possible with no valid SCF so don't give number.

    strHeading = "Outputs" OutputsListView.Columns(0).Text = strHeading End If

    ' Have the Usage Dialog itself calculate usage percentages and

    ' display them, optionally displaying a warning if over any limit.

    Refreshh(WarnIfOver)

    Return bReturn

    Catch ex As Exception sw.WriteLine(Now.ToString + ": Statistics Exception" + ex.Message) End Try End Function

    ''' ''' Function:CalculateMaxInList ''' calculates the output list view maximum count. ''' ''' ''' Public Function CalculateMaxInList() As Integer Try 'calculate outputlistview maximum count nBaudRate = m_nBaudRate nMaxInList = Math.Floor((nBaudRate * 0.9) / (m_nOutputRate * 20.0)) If (nMaxInList > 128) Then ' Enforce 128 signal limit from SCF and CCF.

    nMaxInList = 128 End If nMaxInList -= 4 ' Reserve 4 signals for non-user data.

    Return nMaxInList

    Catch ex As Exception sw.WriteLine(Now.ToString + ": CalculateMaxInList Exception" + ex.Message) End Try End Function ''' ''' Function:Refreshh ''' This function calculates the percentages for system capacity guages while adding the outputs. ''' It also populates the warning messages based on limit. ''' ''' ''' ''' Public Function Refreshh(ByVal bWarnIfOver As Boolean) As Char() Try

    ' Note that at this point the counts of different signal

    ' types needing preprocessing have not yet been calculated.If SCFFlag = False And TCFFlag = False Then

    Return Nothing

  • 8/11/2019 data Region

    35/101

    End If PreprocessingCalculated = False

    Dim czWarning(MAX_LINE_LENGTH * 4 + 1) As Char

    Dim strWarning As String = "" Dim strLoad As String

    'checks maxlist and nmaxcycles ,m_nOutputRate If ((Not (pOutputList Is Nothing)) AndAlso nMaxInList AndAlso nMaxCycles AndAlso nInRate AndAlso m_nOutputRate) Then ' Only do usage calculations if the pointers to the objects

    ' needed for those calculations are valid.

    ProgressbarGroupPanel.Enabled = True ' Calculate output record usage. Application.DoEvents() m_dOutputsPercent = FindOutputsPercent() OPWidthProgressbar.Value = m_dOutputsPercent * 100

    OPwidthpercentLbl.Text = (m_dOutputsPercent * 100).ToString("0.0") + "%" If (m_dOutputsPercent * 100) > 90 Then OPwidthlbl.ForeColor = Color.Red OPwidthpercentLbl.ForeColor = Color.Red Else OPwidthlbl.ForeColor = Color.Black OPwidthpercentLbl.ForeColor = Color.Black End If ' Calculate Dsp Cycle use. Application.DoEvents() m_dDspTimePercent = FindDspTimePercent() ProcTimeProgressBar.Value = (m_dDspTimePercent * 100)

    ProcTimepercentLbl.Text = (m_dDspTimePercent * 100).ToString("0.0") + "%" If (m_dDspTimePercent * 100) > 90 Then ProcTimepercentLbl.ForeColor = Color.Red ProcessorTimeLbl.ForeColor = Color.Red Else ProcTimepercentLbl.ForeColor = Color.Black ProcessorTimeLbl.ForeColor = Color.Black End If ' Calculate Memory A use. Application.DoEvents() m_dMemoryAPercent = FindMemoryAPercent() ProcMemAProgressBar.Value = m_dMemoryAPercent * 100 ProcmemperA.Text = (m_dMemoryAPercent * 100).ToString("0.0") + "%" If ((m_dMemoryAPercent * 100) > 90) Then procmemA.ForeColor = Color.Red ProcmemperA.ForeColor = Color.Red Else procmemA.ForeColor = Color.Black ProcmemperA.ForeColor = Color.Black End If ' Calculate Memory B use. Application.DoEvents() m_dMemoryBPercent = FindMemoryBPercent()

    ProcBProgressBar.Value = FindMemoryBPercent() * 100 ProcmemperB.Text = (FindMemoryBPercent() * 100).ToString("0.0")+ "%"

  • 8/11/2019 data Region

    36/101

    If (FindMemoryBPercent() * 100) > 90 Then procmemB.ForeColor = Color.Red ProcmemperB.ForeColor = Color.Red Else procmemB.ForeColor = Color.Black ProcmemperB.ForeColor = Color.Black End If

    ' Check for over-limit conditions.

    If (m_dOutputsPercent > 1.0) Then ' Over limit of output record width.

    strLoad = "Too many outputs have been selected for the current Output Rate and Communications Rate." strWarning = strWarning + strLoad

    End If

    If (m_dDspTimePercent > 1.0) Then ' Over limit of Digital Signal Processor time.strLoad = "Some process (setup, calculations, etc.) has used

    too many Digital Signal Processor (DSP) cycles" strWarning = strWarning + strLoad End If

    If (m_dMemoryAPercent > 1.0) Then ' Over limit of type "A" memory.

    strLoad = "The selected functions require more type ""A"" memory than is available." strWarning = strWarning + strLoad End If

    If (m_dMemoryBPercent > 1.0) Then ' Over limit of type "B" memory.

    strLoad = "The selected functions require more type ""B"" memory than is available." strWarning = strWarning + strLoad

    End If

    czWarning = strWarning ' If warning string was requested and is not empty, showit.

    If (bWarnIfOver AndAlso (Not strWarning = "")) Then MsgBox(strWarning)

    End If End If Application.DoEvents() ' Return pointer to a statically-allocated warning string

    ' if there is a warning; otherwise, return a null pointer.

    If Not (strWarning = "") Then czWarning = strWarning Return czWarning

    Else Return Nothing End If

  • 8/11/2019 data Region

    37/101

    Catch ex As Exception sw.WriteLine(Now.ToString + ": Refreshh Exception" + ex.Message) End Try End Function ''' ''' Function:FindOutputsPercent ''' This function calculates the percentage for Output width.

    ''' ''' ''' Public Function FindOutputsPercent() As Double Try 'update outputs precentage

    Dim strWork As String Dim Out As New CScroller Out = scrollOutputs Out.SetData("Output Signal Usage Report") Dim nBaud As UInteger = nBaudRate

    Dim nOverhead As UInteger = (0.1 * nBaudRate) Dim nAvailable As UInteger = nBaud - nOverhead Dim nOutputRate As UInteger = m_nOutputRate Dim nBitsPerOutput As UInteger = 20L Dim nBitsPerSecond As UInteger = nOutputRate * nBitsPerOutput Dim nMaxOutputs As UInteger = Math.Floor(nAvailable / nBitsPerSecond) Dim nAbsoluteMaximum As UInteger = 128L Dim nLesserOfTwo As UInteger = Math.Min(nMaxOutputs, nAbsoluteMaximum) Dim nReserved As UInteger = 4L

    'fail safe -WhiteBox Testing Start

    If nLesserOfTwo

  • 8/11/2019 data Region

    38/101

    Public Function FindDspTimePercent() As Double Try 'update DSPTime percentage Dim Out As New CScroller Out = scrollDspTime ' Find Usable Dsp Cycles available per second.

    Dim quadDspUsable As New Quad '= TotalDspCycles - DspCyclesVariance

    - DspCyclesExtraMargin

    'fail safe -White Box Testing Start 'If quadDspUsable.nCyc = 0 Then ' Exit Function 'End If 'fail safe -White Box Testing End

    quadDspUsable.nCyc = TotalDspCycles.nCyc - DspCyclesVariance.nCyc -DspCyclesExtraMargin.nCyc quadDspUsable.nIni = TotalDspCycles.nIni - DspCyclesVariance.nIni -DspCyclesExtraMargin.nIni

    quadDspUsable.nOut = TotalDspCycles.nOut - DspCyclesVariance.nOut -DspCyclesExtraMargin.nOut quadDspUsable.nUni = TotalDspCycles.nUni - DspCyclesVariance.nUni -DspCyclesExtraMargin.nUni

    ' Allow for input processing.

    Dim quaPreCycles As New Quad quaPreCycles = ReportPreprocessingUsage(Out, eQuad.EQP_CYC) 'calculate the quaSecondPreCycles using Quad structure,Scan_Rate_From_Tcf Dim quaSecondPreCycles As New Quad quaSecondPreCycles.nIni = quaPreCycles.nIni * Scan_Rate_From_Tcf

    quaSecondPreCycles.nUni = quaPreCycles.nUni * Scan_Rate_From_Tcf quaSecondPreCycles.nCyc = quaPreCycles.nCyc * Scan_Rate_From_Tcf quaSecondPreCycles.nOut = quaPreCycles.nOut * Scan_Rate_From_Tcf

    ' Allow for calculation/output processing.Dim quaCalcCycles As New Quad

    quaCalcCycles = ReportCalculationUsage(Out, eQuad.EQP_CYC)

    Dim quaSecondCalcCycles As New Quad 'calculate the quaSecondCalcCycles using Quad structure,m_nOutputRate quaSecondCalcCycles.nIni = quaCalcCycles.nIni * m_nOutputRate quaSecondCalcCycles.nUni = quaCalcCycles.nUni * m_nOutputRate quaSecondCalcCycles.nCyc = quaCalcCycles.nCyc * m_nOutputRate quaSecondCalcCycles.nOut = quaCalcCycles.nOut * m_nOutputRate

    'Allow for calls to the inner loop from the outer loop.

    Dim quaCallCycles As New Quad quaCallCycles = ReportCallUsage(Out, eQuad.EQP_CYC) Dim quaSecondCallCycles As New Quad 'calculate the quaSecondCallCycles using Quad structure,m_nOutputRate quaSecondCallCycles.nIni = quaCallCycles.nIni * m_nOutputRate

    quaSecondCallCycles.nUni = quaCallCycles.nUni * m_nOutputRate quaSecondCallCycles.nCyc = quaCallCycles.nCyc * m_nOutputRate quaSecondCallCycles.nOut = quaCallCycles.nOut * m_nOutputRate

  • 8/11/2019 data Region

    39/101

    ' Allow for turnaround at end of calculation/output processing.

    Dim quaTurnaround As New Quad quaTurnaround = ReportTurnaroundUsage(Out, eQuad.EQP_CYC) 'calculate the quaSecondTurnCycles using Quad structure,m_nOutputRate

    Dim quaSecondTurnCycles As New Quad quaSecondTurnCycles.nIni = quaTurnaround.nIni * m_nOutputRate quaSecondTurnCycles.nUni = quaTurnaround.nUni * m_nOutputRate quaSecondTurnCycles.nCyc = quaTurnaround.nCyc * m_nOutputRate quaSecondTurnCycles.nOut = quaTurnaround.nOut * m_nOutputRate 'calculate the nDspused based on the Quad structures Dim nDspUsed As Integer = quaSecondPreCycles.nCyc + quaSecondCalcCycles.nCyc + quaSecondCallCycles.nCyc + quaSecondTurnCycles.nCyc m_dDspTimePercent = (1.0 * nDspUsed / quadDspUsable.nCyc) 'return DSpTime percent Return m_dDspTimePercent Catch ex As Exception

    sw.WriteLine(Now.ToString + ": FindDspTimePercent Exception" + ex.Message) End Try End Function ''' ''' Function:GetSignalOffsetFromChannel ''' This function returns signal offset value if scf structure sigrec channel and o_data channel values are matched. ''' ''' ''' ''' Public Function GetSignalOffsetFromChannel(ByVal Channel As UShort) As UShor

    t Try 'check the scf structure sigrec channel and o_data channel values are matched then return signal offset value Dim i As UShort For i = 0 To MAXSIG - 1

    'fail safe -White Box Testing Start If dataDescriptor.o_data.chan Is Nothing Then Exit Function End If 'fail safe -White Box Testing End

    If dataDescriptor.o_data.chan(i) = dataDescriptor.sigrec(Channel).chanl Then Return i End If Next Return NOT_USED_WORD

    Catch ex As Exception sw.WriteLine(Now.ToString + ": GetSignalOffsetFromChannel Exception"+ ex.Message) End Try End Function

    ''' ''' Function:GetTimeSignalOffset ''' This function returns signal offset based on the scf structure time_trce

  • 8/11/2019 data Region

    40/101

    '''

    ''' ''' Public Function GetTimeSignalOffset() As UShort Try 'return signal offset based on the scf structure time_trce

    Return Math.Floor(dataDescriptor.oddcrap.time_trace / 2)

    Catch ex As Exception sw.WriteLine(Now.ToString + ": GetTimeSignalOffset Exception" + ex.Message) End Try End Function ''' ''' Function:GetTimeMask ''' This function returns time_mask value based on the scf structure

    ''' '''

    ''' Public Function GetTimeMask() As UShort Try 'return time_mask value based on the scf structure

    Return dataDescriptor.oddcrap.time_mask Catch ex As Exception sw.WriteLine(Now.ToString + ": GetTimeMask Exception" + ex.Message) End Try End Function ''' ''' Function:GetAbbreviation ''' It returns calculation name '''

    ''' ''' ''' Public Function GetAbbreviation(ByVal MaximumSize As Integer) As String Try 'getting the passed name of calculation listview text Dim sname As String = FN1(passedname, sa) Return sname Catch ex As Exception sw.WriteLine(Now.ToString + ": GetAbbreviation Exception" + ex.Message) End Try End Function ''' ''' Function:IsValidChannel ''' It checks the cannel value is within the 127 or not. ''' ''' ''' ''' Public Function IsValidChannel(ByVal Channel As UShort) As Boolean Try 'checking the channel value is with in the limit or not If Not (Channel >= 0 AndAlso Channel < MAXSIG) Then Return False

    Else Return True End If

  • 8/11/2019 data Region

    41/101

    Catch ex As Exception sw.WriteLine(Now.ToString + ": IsValidChannel Exception" + ex.Message) End Try End Function ''' ''' Function:NotValidChannel

    ''' It checks the cannel value is within the 127 or not. ''' ''' ''' ''' Public Function NotValidChannel(ByVal Channel As UShort) As Boolean Try 'checking the channel value is with in the limit or not If Not (Channel < 0 Or Channel >= MAXSIG) Then Return False Else Return True

    End If Catch ex As Exception sw.WriteLine(Now.ToString + ": NotValidChannel Exception" + ex.Message) End Try End Function ''' ''' Function:GetChannelGraphLabelLong ''' It returns the glabel for passed channel. ''' ''' ''' '''

    Public Function GetChannelGraphLabelLong(ByVal nChannel As UShort) As String Try 'return's the graphlable Return (DemandChannelGraphLabel(nChannel)) Catch ex As Exception sw.WriteLine(Now.ToString + ": GetChannelGraphLabelLong Exception" +ex.Message) End Try End Function ''' ''' Function:IsChannelCurrent ''' This function checks that the selected channel is a current channel or not. ''' ''' ''' ''' Public Function IsChannelCurrent(ByVal Channel As UShort) As Boolean Try 'checking channel values is with in the limit or not

    If (Channel < 0 Or Channel >= MAXSIG) Then Return False End If 'ONINVALIDCHANNEL(False, Channel) 'checking the channel is analog or not and return's pwr_flags value

    If (IsChannelAnalog(Channel)) Then Return (Not CBool((dataDescriptor.sigrec(Channel).Cpwr_flags.bVoltage)))

  • 8/11/2019 data Region

    42/101

    Else Return False End If Catch ex As Exception sw.WriteLine(Now.ToString + ": IsChannelCurrent Exception" + ex.Message) End Try

    End Function ''' ''' Function:IsChannelAnalog ''' This function checks that the passed channel is analog or not. ''' ''' ''' ''' Public Function IsChannelAnalog(ByVal Channel As UShort) As Boolean Try

    ' This function only looks to see if bit 1 is set. This will return

    true for ALL analog types. If (Channel < 0 Or Channel >= MAXSIG) Then Return False End If If (Channel >= dataDescriptor.o_data.ccnt) Then Return False ElseIf (dataDescriptor.sigrec(Channel).flags And ANALOG) Then Return True Else Return False End If

    Catch ex As Exception

    sw.WriteLine(Now.ToString + ": IsChannelAnalog Exception" + ex.Message) End Try End Function ''' ''' Function:IsChannelAnalog ''' This function checks that the passed channel is analog or not. ''' ''' ''' ''' Public Function IsSCFDATAChannelAnalog(ByVal Channel As UShort) As Boolean Try

    ' This function only looks to see if bit 1 is set. This will returntrue for ALL analog types. If (Channel < 0 Or Channel >= MAXSIG) Then Return False End If If (Channel >= dataDescriptor.o_data.ccnt) Then Return False ElseIf (scfdata.sigrec(Channel).flags And ANALOG) Then Return True Else Return False

    End If

    Catch ex As Exception

  • 8/11/2019 data Region

    43/101

    sw.WriteLine(Now.ToString + ": IsChannelAnalog Exception" + ex.Message) End Try End Function ''' ''' Function:UpdateValues ''' This function updates the output rate and line frequency etc.,

    ''' ''' ''' Public Function UpdateValues() Try 'update the nBaudRate,m_nBaudRate,nInRate,m_nLineFreq,nMaxInList,m_nOutputRate values nBaudRate = 230400 m_nBaudRate = 230400 nInRate = 4800 m_nLineFreq = 60 nMaxInList = 124

    m_nOutputRate = 60 Catch ex As Exception sw.WriteLine(Now.ToString + ": UpdateValues Exception" + ex.Message) End Try End Function ''' ''' Function:GetNumberChannels ''' This function returns total no.of channels in a file. ''' ''' ''' Public Function GetNumberChannels() As UShort Try

    'returns the channel count value Return (dataDescriptor.o_data.ccnt) Catch ex As Exception sw.WriteLine(Now.ToString + ": GetNumberChannels Exception" + ex.Message) End Try End Function ''' ''' Function:GetChannelGraphLabel ''' This function returns glabel based on the channel type. ''' That means if the selected channel is a analog then it returns analog glabel ''' If it is a digital channel then digital glabel is retyurned. ''' ''' ''' ''' Public Function GetChannelGraphLabel(ByVal channel As UShort) As String Try 'retruns the glabel either analog channel or digital channel

    Dim cReturn As String = "" Dim strEmpty As String = "" Dim Digitalchannel As UShort If (channel And IND_DIG) Then 'if given channel is digital then digital glabel should be retur

    n Digitalchannel = channel Xor IND_DIG ON_INVALID_INDIVIDUAL_DIGITAL_CHANNEL(Digitalchannel)

  • 8/11/2019 data Region

    44/101

    cReturn = dataDescriptor.digitalchannel(Digitalchannel).glabel cReturn = cReturn.Trim("") Else 'if given channel is analog then analog glabel should be return ON_INVALID_CHANNEL(channel)

    'fail safe -White Box Testing Start

    If dataDescriptor.sigrec Is Nothing Then Exit Function End If 'fail safe -White Box Testing End

    cReturn = dataDescriptor.sigrec(channel).glable cReturn = cReturn.Trim("") End If Return (cReturn) Catch ex As Exception sw.WriteLine(Now.ToString + ": GetChannelGraphLabel Exception" + ex.Message)

    End Try End Function ''' ''' Function:ON_INVALID_CHANNEL ''' This function checks the analog channel number is with in the 127 or not. ''' If that number is less than 0 or greater than 127 then it returns false. ''' ''' ''' ''' Public Function ON_INVALID_CHANNEL(ByVal channel As UShort) As Boolean 'checking channel is with in the limit or not

    If (channel < 0 Or channel > MAXSIG) Then 'MsgBox("channel is not with in a range") Return False End If Return True End Function ''' ''' Function:ON_INVALID_INDIVIDUAL_DIGITAL_CHANNEL ''' This function checks the digital channel number is with in the 127 or not. ''' If that number is less than 0 or greater than 127 then it returns false. ''' ''' ''' ''' Public Function ON_INVALID_INDIVIDUAL_DIGITAL_CHANNEL(ByVal Digitalchannel As UShort) 'checking the digital channel is with in the limit or not If (Digitalchannel < 0 Or Digitalchannel > MAXDIG) Then MsgBox("Digital channel is not with in a range") End If End Function

    ''' ''' Function:UpdateControls

    ''' This is the main function for updating the GUI. ''' This function is called when user opening a configuration file, adding the inputs into putputs list.

  • 8/11/2019 data Region

    45/101

    ''' When user selects a calculation this function is called because based onthe calculation, it updates the input listview. ''' It also updates the input listview column text. ''' If any modifications are performed by user in output listview this function is called for updating that list view. ''' '''

    ''' ''' Public Function UpdateControls(ByVal Exclude As ULong) Try 'when outlistview selected item count should be greaterthan zero then deleteslection button should be enabled true other enabled false If OutputsListView.SelectedItems.Count > 0 Then DeleteSelectionBtn.Enabled = True Else DeleteSelectionBtn.Enabled = False End If 'check if updatecontrols call same time in the same function , like

    "recursion" in that situation this flag exit the updatecontrols()If NoRecFlag = True Then Exit Function End If NoRecFlag = True Nin = 0 Dim nUseLongNames As Short = 0 'check if the uselongsignalnames checked true either false then setthe nuselongnames flag sets true either false

    If ConadataUseLongSignamesCheckBox.Checked = True Then nUseLongNames = 1 Else nUseLongNames = 0

    End If 'based on the exclude and UCEX_LISTBOXES update the input list viewand outputlist view If (Not (Exclude And UCEX_LISTBOXES)) Then Application.DoEvents() 'updates the inputs list and outputs list FillDependentListBoxes() End If 'update the output,input list view column text and update the progress bar Statistics(True) 'set the input listview column text Dim strHeading As String = "" If ((Not SCFFlag) Or (Not TCFFlag)) Then ShowAllSignalsCheckBox.Checked = False ShowAllSignalsCheckBox.Enabled = False ShowAllSignalsCheckBox.Visible = False InputsListView.Columns(0).Text = "Inputs" ElseIf (cTotalInputsDisallowed > cTotalInputsForced) Then ShowAllSignalsCheckBox.Enabled = True ShowAllSignalsCheckBox.Visible = True InputsListView.Columns(0).Text = "Inputs (" + InputsListView.Items.Count.ToString + ")" ElseIf CBool(cTotalInputsDisallowed) Then ShowAllSignalsCheckBox.Enabled = True

    ShowAllSignalsCheckBox.Visible = True InputsListView.Columns(0).Text = "Inputs (" + dataDescriptor.o_data.ccnt.ToString + ")"

  • 8/11/2019 data Region

    46/101

    Else ShowAllSignalsCheckBox.Enabled = False ShowAllSignalsCheckBox.Visible = True InputsListView.Columns(0).Text = "Inputs (" + dataDescriptor.o_data.ccnt.ToString + ")" End If 'if input listview item is selected then update the IpOpTextBox text

    If (nMostRecentlySelectedList = IDC_LIST_INPUT) Then FormatMostRecentInput() End If 'if output listview item is selected then update the IpOpTextBox text If (nMostRecentlySelectedList = IDC_LIST_SELECTED) Then ' FormatMostRecentSelection() End If

    'set the title based on the input listview Dim strTitle As String = ""

    If (strTitle.Length And strTitle.Contains("*")) Then If (Not bWasModified) Then End If Else If (bWasModified) Then strTitle = strTitle + "*" End If End If OutputpersecLbl.Enabled = SCFFlag OPSComboBox.Enabled = SCFFlag LineFreqLbl.Enabled = SCFFlag LFComboBox.Enabled = SCFFlag Return Nothing

    Catch ex As Exception sw.WriteLine(Now.ToString + ": UpdateControls Exception" + ex.Message) End Try

    End Function ''' ''' Function:FillDependentListBoxes ''' This function updates the input list based on selected calculation ''' And also updates the output list view. ''' ''' ''' Public Function FillDependentListBoxes() Try 'update the input listview based on the calculation listview selection

    FillInputListBox() 'update the output listview based on the outputlistview and uselongname checkbox checked OutputListviewUpdate() Return True Catch ex As Exception sw.WriteLine(Now.ToString + ": FillDependentListBoxes Exception" + ex.Message)

    End Try End Function '''

  • 8/11/2019 data Region

    47/101

    ''' Function:FillInputListBox ''' This function is called when user opens a file, that time input listviewfilled with glabels. ''' When user selects a calculation, this function updates the input list with related glabels of selected calculation. ''' While updating input listview for each and every channel it gives the image tags.

    ''' If "Show All Signals" check box is checked this function updates the input listview with glabels. ''' ''' ''' Public Function FillInputListBox() Try 'flag is used to recursion If InputListFlag Then Exit Function End If

    Dim selindex As Integer = -1 'store the input listview selected items index If InputsListView.SelectedItems.Count > 0 Then selindex = InputsListView.SelectedIndices(0) End If If CalculationsListView.SelectedItems.Count = 0 Then pFunction = "" End If 'stores the calculation listview selected item text If CalculationsListView.SelectedItems.Count > 0 Then pFunction = CalculationsListView.SelectedItems(0).Text End If

    'check the input flag InputListFlag = False 'clears the input listview items

    InputsListView.Items.Clear() Dim nType As CHANNEL_TYPE Dim iImage As Short Dim iItem As UShort Dim iScfItem As UShort Dim iListItem As Short Dim nListItems As Short Dim bIsAnalog As Boolean Dim bIsDirect As Boolean Dim bHideUsedEntries As Boolean Dim bItemForced As Boolean Dim bItemDisallowed As Boolean 'check if calculation listview item is selected or not If bModifyingFunctionList Then Return False End If ' CSaveList& List = c_listInputs Dim bShowAll As Boolean 'based on the ShowAllSignalsCheckBox either checked or unchecked, bShowAll flag is set either true or false

    If (ShowAllSignalsCheckBox.Checked) Then bShowAll = True

    Else bShowAll = False End If

  • 8/11/2019 data Region

    48/101

    Dim strlabel As String = "" cTotalInputsForced = 0 cTotalInputsExisting = 0 cTotalInputsDisallowed = 0 Dim lvitem As ListViewItem Nin = 0 Dim pf As Boolean

    For i As Integer = 0 To GetNumberChannels() - 1 NInputItemArray(i) = 0 Next 'check if scf is exits or not

    If (SCFFlag) Then 'calculate the total number of channles cTotalInputsExisting = GetNumberChannels() For iItem = 0 To cTotalInputsExisting - 1 'calulate the graph label based on the uselongnamescheckbox

    If ConadataUseLongSignamesCheckBox.Checked = True Then 'if UseLongSignamesCheckBox checked true then return ide

    nt strlabel = DemandChannelLongname(iItem) Else 'if UseLongSignamesCheckBox checked false then return glabel strlabel = DemandChannelGraphLabel(iItem) End If 'calculate the type of channel

    nType = GetChannelSignalType(iItem) 'check if the given channel is analog or not bIsAnalog = IsChannelAnalog(iItem) 'check if the given channel is direct or not bIsDirect = IsDirect(iItem)

    'calculate the what type of icon is suitable for the given channel iImage = IconFromType(nType) 'set the flags Defeault false for every channel bItemDisallowed = False bItemForced = False bHideUsedEntries = False 'based on the icon type set the images

    Dim str As String = "" If iImage = 24 Then str = "IDI_24_ROUND_C" ElseIf iImage = 23 Then str = "IDI_23_SQUARE_CN" Else str = "IDI_19_SQUARE" End If 'based on the calculation listview set flag true or false If pFunction Is Nothing Or pFunction = "" Then pf = False Else pf = True End If 'based on the calculation list view items the flags sholudbe set true or false If (pf And (Not (IsDisallowedSignal(iItem) Is Nothing Or IsD

    isallowedSignal(iItem) = ""))) Then bItemDisallowed = True cTotalInputsDisallowed = cTotalInputsDisallowed + 1

  • 8/11/2019 data Region

    49/101

    If (bShowAll) Then bItemForced = True cTotalInputsForced = cTotalInputsForced + 1 End If End If 'based on the calculation list view items the flags sholudbe set true or false

    Dim index As Integer = Element(pFunction) If (pf And IsInList(index, iItem) And bHideUsedEntries) Then bItemDisallowed = True

    cTotalInputsDisallowed = cTotalInputsDisallowed + 1 If (bShowAll) Then bItemForced = True cTotalInputsForced = cTotalInputsForced + 1 End If End If 'based on the flags(based on calculation lsitview selectionitems) update the input listview for specific channels

    If (bItemForced Or (Not (bItemDisallowed))) Then Dim iIn As Integer = 0 lvitem = New ListViewItem lvitem.Text = strlabel

    lvitem.ImageKey = str If bIsAnalog And bIsDirect Then lvitem.ImageKey = "integrate" End If NInputItemArray(Nin) = iItem

    InputsListView.BeginUpdate() InputsListView.Items.Add(lvitem)

    InputsListView.EndUpdate() 'if input listview item are already selected then main that selection as usual Dim selcount As Integer = InputsListView.Items.Count - 1 If InputListViewSelectedItems.Count > 0 Then For j As Integer = 0 To InputListViewSelectedItems.Count - 1 If InputListViewSelectedItems.Item(j) = iItem Then InputListFlag = True InputsListView.Items(selcount).Selected = True InputsListView.Focus() InputListFlag = False End If Next End If Nin = Nin + 1 End If Next 'after populating inputlistview then UseLongSignamesCheckBox should be visible mode ConadataUseLongSignamesCheckBox.Visible = True End If nListItems = 0

    'after populating inputlistview then based on the inputlistview items count ,UseLongSignamesCheckBox should be visible mode or invisible mode If InputsListView.Items.Count = 0 Then

  • 8/11/2019 data Region

    50/101

    ConadataUseLongSignamesCheckBox.Visible = False Else ConadataUseLongSignamesCheckBox.Visible = True End If 'update the inputlist view but some time it acts like recursion

    UpdateControls(0) Return True

    Catch ex As Exception sw.WriteLine(Now.ToString + ": FillInputListBox Exception" + ex.Message) End Try End Function ''' ''' Function:DemandChannelLongname ''' This function returns ident or glabel based on the channel type. ''' It returns glabel if the ident is empty. ''' '''

    ''' ''' Public Function DemandChannelLongname(ByVal Channel As UShort) As String Try

    Dim CReturn As String = "" 'check if given channel is digial or analog If (Channel And IND_DIG) Then 'if channel is digital then returns the digital channel ident orglabel Return DemandDigitalLongname(Channel) Else 'ON_INVALID_CHANNEL(CReturn)

    'checking if the given channel is with in the limit or not If Not (Channel >= 0 Or Channel < MAXSIG) Then Return Nothing End If

    'fail safe -White Box testing Start If dataDescriptor.sigrec Is Nothing Then Exit Function End If 'fail safe -White Box testing End

    'return the given chanenl long name as ident CReturn = dataDescriptor.sigrec(Channel).ident CReturn = CReturn.Trim("") CReturn = CReturn.TrimStart CReturn = CReturn.TrimEnd If CReturn = "" Then 'if ident is empty then returns the glable CReturn = dataDescriptor.sigrec(Channel).glable CReturn = CReturn.Trim("") If CReturn = "" Or CReturn Is Nothing Then 'if glable is also empty then return the channel number

    CReturn = "[#" + Channel.ToString + "]" Else CReturn = "[" + CReturn + "]"

    End If Return CReturn Else

  • 8/11/2019 data Region

    51/101

    Return CReturn End If

    Return CReturn End If Catch ex As Exception sw.WriteLine(Now.ToString + ": DemandChannelLongname Exception" + ex

    .Message) End Try End Function ''' ''' Function:DemandDigitalLongname ''' It returns digital channel ident ''' If any channels ident is empty then it returns glabel. ''' ''' ''' ''' Public Function DemandDigitalLongname(ByVal DigitalChannel As UShort) As Str

    ing Try

    Dim CReturn As String = "" 'check if given channel is digital or not DigitalChannel = DigitalChannel And (Not (IND_DIG)) 'check the digital channel is with in the limit or not If Not (DigitalChannel >= 0 Or DigitalChannel < MAXDIG) Then Return Nothing End If

    'fail safe -White Box Testing Start If dataDescriptor.digitalchannel Is Nothing Then

    Exit Function End If

    'return the digital channel long name as ident CReturn = dataDescriptor.digitalchannel(DigitalChannel).ident CReturn = CReturn.Trim("") If CReturn Is Nothing Then 'if ident is empty then return digital channel glable

    CReturn = dataDescriptor.digitalchannel(DigitalChannel).glabel CReturn = CReturn.Trim("") If CReturn Is Nothing Then 'if glable is nothing then return the channel number CReturn = "[%" + DigitalChannel.ToString + "]" Else CReturn = "[" + CReturn + "]" End If Return CReturn Else Return CReturn

    End If Return CReturn Catch ex As Exception sw.WriteLine(Now.ToString + ": DemandDigitalLongname Exception" + ex.Message)

    End Try End Function

  • 8/11/2019 data Region

    52/101

    '''

    ''' Function:strComposeDefaultName ''' This function clubs the calculation name, ident and glabel for updatingthe first column of output list. ''' '''

    ''' ''' Public Function strComposeDefaultName(ByVal Data As String) As String Try 'return a string like combination of calculation listview item and input listview item Dim iScfC As Integer Dim bSecond As Boolean Dim iFunction As UInteger Dim strAlt As String = "" Dim Name As String = "" 'getting the channel name in the DATA

    Dim chnal As String = GetInputName(Data) 'getting the function name in the DATA Dim funname As String = getFunctionName(Data) 'changing the function name based on the shortnames If funname = "1Frq" Then funname = "Single Ph.Frequency" ElseIf funname = "1Pwr" Then funname = "Single Phase Power" ElseIf funname = "1Mag" Then funname = "Magnitude" ElseIf funname = "Dir" Then funname = "Direct Current" ElseIf funname = "Phsr" Then

    funname = "Phasor" ElseIf funname = "1Pwr3Eq" Then funname = "Single Ph.Power Eq." ElseIf funname = "3Frq" Then funname = "Three Ph. Frequency" ElseIf funname = "3Mag" Then funname = "Three Ph. Magnitude" ElseIf funname = "PosSeq" Then funname = "Positive Sequence" ElseIf funname = "3Pwr" Then funname = "Three Phase Power" End If 'getting the channel index iScfC = GetChannel(chnal) 'getting the function index iFunction = Element(funname) 'getting the fucntion name Dim pFun As String = Element(iFunction) 'getting the fucntion short name ' Dim Shortname As String = FN1(passedname, pFun) 'combine the two string(fucntion and channel) ' If ConadataUseLongSignamesCheckBox.Checked = True Then ' Name = pFun + " on " + DemandChannelLongname(iScfC) ' Else 'fail-safe

    If iScfC = -1 Then Exit Function End If

  • 8/11/2019 data Region

    53/101

    'fail-safe Name = pFun + " on " + DemandChannelLongname(iScfC) + "(" + DemandChannelGraphLabel(iScfC) + ")" ' End If 'System.Text.RegularExpressions.Regex.Replace(DemandChannelGraphLabel(iScfC), "\W", " ").Trim 'GetPassedName()

    'return the combined string

    Return Name Catch ex As Exception sw.WriteLine(Now.ToString + ": strComposeDefaultName Exception" + ex.Message) End Try End Function ''' ''' Function:IsDirect ''' This function checks the channel is a direct or not. ''' ''' '''

    ''' Public Function IsDirect(ByVal Channel As UShort) As Boolean Try

    'fail safe -White Box Testing Start If dataDescriptor.sigrec Is Nothing Then Exit Function End If 'fail safe -White Box Testing End

    'check if the given channel is direct or nor and check if the channel is with in a limit or not If (CBool((Channel >= 0 Or Channel < MAXSIG)) And (Not (Not CBool(da

    taDescriptor.sigrec(Channel).vdata.asets.pcalib.dcbit.DcBit)))) Then Return True Else Return False End If Catch ex As Exception sw.WriteLine(Now.ToString + ": IsDirect Exception" + ex.Message) End Try End Function ''' ''' Function:IsscfdataDirect ''' This function checks the channel is a direct or not. ''' ''' ''' ''' Public Function IsscfdataDirect(ByVal Channel As UShort) As Boolean Try

    'fail safe -White Box Testing Start If scfdata.sigrec Is Nothing Then Exit Function End If 'fail safe -White Box Testing End

    'check if the given channel is direct or nor and check if the channel is with in a limit or not If (CBool((Channel >= 0 Or Channel < MAXSIG)) And (Not (Not CBool(sc

  • 8/11/2019 data Region

    54/101

    fdata.sigrec(Channel).vdata.asets.pcalib.dcbit.DcBit)))) Then Return True Else Return False End If Catch ex As Exception sw.WriteLine(Now.ToString + ": IsscfdataDirect Exception" + ex.Messa

    ge) End Try End Function ''' ''' Function:IconFromType ''' It