Welcome to the fifth and final part of the tutorial series about Omicron Control Center (OCC) Custom Dialog. In this tutorial, I will show you how to get a real-time feedback when data was change. This will be helpful that you will be notified what will be the outcome of the changed data. Check the video below.
Now, open the OCC document that we used in the previous tutorial. If you don't have it check this link (Omicron Control Center Custom Dialog - Creating Custom Dialog With Dropdown Control) then come back here once you have OCC document.
Click the Yes button to create a new SourceControllerFunction function. At the very end of the script, new function has been added.
Now, copy the code below and replace the SetTheSourceController procedure then execute this command.
See you next time.
Now, open the OCC document that we used in the previous tutorial. If you don't have it check this link (Omicron Control Center Custom Dialog - Creating Custom Dialog With Dropdown Control) then come back here once you have OCC document.
When the document is loaded, open the script view by clicking the Script View button under the View tab then stop the script if its running.
Now, find the SetTheSourceController sub procedure. We're going to modify this codes and use different methods of loading data from the test object and saving back to test object. Point the mouse pointer and click between Begin Dialog and End Dialog then click the Edit Dialog button under the Tools group at Script tab to position the cursor inside the dialog. Make sure the cursor is inside the Begin and End Dialog because if not, it will create a new dialog instead of editing the existing dialog.
Once the UserDialog Editor open, right click on the form to edit the UserDialog properties. Type SourceControllerFunction in the Dialog Function without space, to automatically create a SourceControllerFunction procedure in the Script window. Now, add cancel button in the form then click the save and exit button from the toolbar. See the image below.
Click the Yes button to create a new SourceControllerFunction function. At the very end of the script, new function has been added.
Rem See DialogFunc help topic for more information.
Private Function SourceControllerFunction(DlgItem$, Action%, SuppValue?) As Boolean
Select Case Action%
Case 1 ' Dialog box initialization
Case 2 ' Value changing or button pressed
Rem SourceControllerFunction = True ' Prevent button press from closing the dialog box
Case 3 ' TextBox or ComboBox text changed
Case 4 ' Focus changed
Case 5 ' Idle
Rem Wait .1 : SourceControllerFunction = True ' Continue getting idle actions
Case 6 ' Function key
End Select
End Function
Now, we have to move the Source_Array and Soure_Enum from the SetSourceController procedure to the main or general class.
' ************************************************************
' This is module *Module1 .
' Automatically generated uses comments are placed here.
' Don't edit these lines.
' {BEGINUSES}
'#Uses "*Module1"
' {ENDUSES}
' ************************************************************
Public Const BASIC_INFO_PATH As String = "CUSTOM.RELAY_INFORMATION.BASIC"
Public Const SOURCE_PATH As String = "CUSTOM.RELAY_PARAMETERS.SOURCE"
Public Const TEST_CONTROLLER_PATH As String = "CUSTOM.TEST_CONTROLLER"
Public GlobalTO As XRio
Dim Source_Array() As String
Dim Source_Enum As AutoParameter
Now, we have to create a new function that getting data from the test object like Source Name data to display when the source data has changed.
Private Function GetSourceControllerFeedback(Reference As String) As String
Select Case Reference
Case "Source 1"
GetSourceControllerFeedback = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(SOURCE_PATH & ".SOURCE1.NAME"))
Case "Source 2"
GetSourceControllerFeedback = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(SOURCE_PATH & ".SOURCE2.NAME"))
End Select
End Function
Now, navigate to SourceControllerFunction function then start new coding. First, we have to initialize the dialog box. Under Case 1, we're going to load the enumeration data to the dropdown list and display the current source name in the selected source name textbox. Next, move the Source_Array and Source_Enum from the SetSourceController procedure to inside the Select Case 1 at SourceControllerFunction. Next, we have to set the selected source name textbox to read only by using DlgEnable and set it to False so that we can't edit the data.
Rem See DialogFunc help topic for more information.
Private Function SourceControllerFunction(DlgItem$, Action%, SuppValue?) As Boolean
Select Case Action%
Case 1 ' Dialog box initialization
Set Source_Enum = GlobalTO.XRioDocument.GetParamFromIDs(TEST_CONTROLLER_PATH & ".SOURCE")
Source_Array = GetParameterEnumList(Source_Enum)
DlgEnable "txtSelectedSource",False
DlgListBoxArray "dlbSource",Source_Array()
DlgValue "dlbSource",GetEnumIndex(Source_Enum)
DlgText "txtSelectedSource", GetSourceControllerFeedback(DlgText("dlbSource"))
Case 2 ' Value changing or button pressed
Rem SourceControllerFunction = True ' Prevent button press from closing the dialog box
Case 3 ' TextBox or ComboBox text changed
Case 4 ' Focus changed
Case 5 ' Idle
Rem Wait .1 : SourceControllerFunction = True ' Continue getting idle actions
Case 6 ' Function key
End Select
End Function
Now, in the Select Case 2, this will be triggered when the objects (DlgItem) in the dialog box is pressed. We have need to add Select Case DlgItem for dlbSource, btnOK, CancelButton in this case.
Rem See DialogFunc help topic for more information.
Private Function SourceControllerFunction(DlgItem$, Action%, SuppValue?) As Boolean
Select Case Action%
Case 1 ' Dialog box initialization
Set Source_Enum = GlobalTO.XRioDocument.GetParamFromIDs(TEST_CONTROLLER_PATH & ".SOURCE")
Source_Array = GetParameterEnumList(Source_Enum)
DlgEnable "txtSelectedSource",False
DlgListBoxArray "dlbSource",Source_Array()
DlgValue "dlbSource",GetEnumIndex(Source_Enum)
DlgText "txtSelectedSource", GetSourceControllerFeedback(DlgText("dlbSource"))
Case 2 ' Value changing or button pressed
Rem SourceControllerFunction = True ' Prevent button press from closing the dialog box
Select Case DlgItem
Case "dlbSource"
DlgText "txtSelectedSource", GetSourceControllerFeedback(DlgText(DlgItem))
SourceControllerFunction = True
Case "btnOK"
SetEnumValue Source_Enum, DlgValue("dlbSource")
Set Source_Enum = Nothing
Case "CancelButton"
Set Source_Enum = Nothing
Case Else
End Select
Case 3 ' TextBox or ComboBox text changed
Case 4 ' Focus changed
Case 5 ' Idle
Rem Wait .1 : SourceControllerFunction = True ' Continue getting idle actions
Case 6 ' Function key
End Select
End Function
Now, back to the SetTheSourceController procedure, we need to declare Integer of DialogResult to get the Dialog result when we click the OK or Cancel button the custom dialog we've created. To see what I mean, execute the SetTheSourceController command to load the dialog box then click cancel button and that will give error called User pressed cancel.
Sub SetTheSourceController()
On Error GoTo ErrorHandler
Set GlobalTO = Document.TestObjects(1).Specific
Begin Dialog UserDialog 480,105,"Source Controller",.SourceControllerFunction ' %GRID:10,7,1,1
Text 10,14,140,14,"Source:",.lblSource
Text 10,42,140,14,"Selected Source:",.lblSelectedSource
DropListBox 160,14,300,21,Source_Array(),.dlbSource,2
TextBox 160,42,300,21,.txtSelectedSource
OKButton 370,70,90,21,.btnOK
CancelButton 270,70,90,21
End Dialog
Dim dlg As UserDialog
Dim DialogResult As Integer
DialogResult = Dialog (dlg)
Set GlobalTO = Nothing
Exit Sub
ErrorHandler:
MsgBox(Err.Description, vbOkOnly+ vbCritical,"Error")
End Sub
Now, we have successfully created a custom dialog box with feedback. The overall codes should be looks like the codes below.
' ************************************************************
' This is module *Module1 .
' Automatically generated uses comments are placed here.
' Don't edit these lines.
' {BEGINUSES}
'#Uses "*Module1"
' {ENDUSES}
' ************************************************************
Public Const BASIC_INFO_PATH As String = "CUSTOM.RELAY_INFORMATION.BASIC"
Public Const SOURCE_PATH As String = "CUSTOM.RELAY_PARAMETERS.SOURCE"
Public Const TEST_CONTROLLER_PATH As String = "CUSTOM.TEST_CONTROLLER"
Public GlobalTO As XRio
Dim Source_Array() As String
Dim Source_Enum As AutoParameter
Sub SetRelayInformation()
On Error GoTo ErrorHandler
Set GlobalTO = Document.TestObjects(1).Specific
Begin Dialog UserDialog 480,273,"Relay Information Dialog Editor" ' %GRID:10,7,1,1
Text 10,14,140,14,"Substation Name:",.lblSubstationName
Text 10,42,140,14,"Substation Address:",.lblSubstationAddress
Text 10,70,140,14,"CB Name:",.lblCBName
Text 10,98,140,14,"Circuit Name:",.lblCircuitName
Text 10,126,140,14,"Device Type:",.lblDeviceType
Text 10,154,140,14,"Manufacturer:",.lblManufacturer
Text 10,182,140,14,"Serial Number:",.lblSerialNumber
Text 10,210,140,14,"Device Address:",.lblDeviceAddress
TextBox 160,14,300,21,.txtSubstationName
TextBox 160,42,300,21,.txtSubstationAddress
TextBox 160,70,300,21,.txtCBName
TextBox 160,98,300,21,.txtCircuitName
TextBox 160,126,300,21,.txtDeviceType
TextBox 160,154,300,21,.txtManufacturer
TextBox 160,182,300,21,.txtSerialNumber
TextBox 160,210,300,21,.txtDeviceAddress
OKButton 370,238,90,21,.btnOK
End Dialog
Dim dlg As UserDialog
dlg.txtSubstationName = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".SUBSTATION_NAME"))
dlg.txtSubstationAddress = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".SUBSTATION_ADDRESS"))
dlg.txtCBName = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".CB_NAME"))
dlg.txtCircuitName = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".CIRCUIT_NAME"))
dlg.txtDeviceType = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".DEVICE_TYPE"))
dlg.txtManufacturer = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".MANUFACTURER"))
dlg.txtSerialNumber = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".SERIAL_NUMBER"))
dlg.txtDeviceAddress = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".DEVICE_ADDRESS"))
Dialog dlg
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".SUBSTATION_NAME").ParameterString.SetDisplayValue dlg.txtSubstationName, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".SUBSTATION_ADDRESS").ParameterString.SetDisplayValue dlg.txtSubstationAddress, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".CB_NAME").ParameterString.SetDisplayValue dlg.txtCBName, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".CIRCUIT_NAME").ParameterString.SetDisplayValue dlg.txtCircuitName, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".DEVICE_TYPE").ParameterString.SetDisplayValue dlg.txtDeviceType, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".MANUFACTURER").ParameterString.SetDisplayValue dlg.txtManufacturer, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".SERIAL_NUMBER").ParameterString.SetDisplayValue dlg.txtSerialNumber, ""
GlobalTO.XRioDocument.GetParamFromIDs(BASIC_INFO_PATH & ".DEVICE_ADDRESS").ParameterString.SetDisplayValue dlg.txtDeviceAddress, ""
Document.TestObjects(1).CommitChanges
Set GlobalTO = Nothing
Exit Sub
ErrorHandler:
MsgBox(Err.Description, vbOkOnly+ vbCritical,"Error")
End Sub
Function GetDisplayString(Parameter As AutoParameter) As String
If Not Parameter Is Nothing Then
GetDisplayString = Parameter.DisplayString
Else
GetDisplayString = "-"
End If
End Function
Sub SetTheSourceController()
On Error GoTo ErrorHandler
Set GlobalTO = Document.TestObjects(1).Specific
Begin Dialog UserDialog 480,105,"Source Controller",.SourceControllerFunction ' %GRID:10,7,1,1
Text 10,14,140,14,"Source:",.lblSource
Text 10,42,140,14,"Selected Source:",.lblSelectedSource
DropListBox 160,14,300,21,Source_Array(),.dlbSource,2
TextBox 160,42,300,21,.txtSelectedSource
OKButton 370,70,90,21,.btnOK
CancelButton 270,70,90,21
End Dialog
Dim dlg As UserDialog
Dim DialogResult As Integer
DialogResult = Dialog (dlg)
Set GlobalTO = Nothing
Exit Sub
ErrorHandler:
MsgBox(Err.Description, vbOkOnly+ vbCritical,"Error")
End Sub
Function GetParameterEnumList(EnumParameter As AutoParameter) As String()
Dim Result As String
If Not EnumParameter Is Nothing Then
For i = 1 To EnumParameter.ParameterEnum.EnumValues.Count
Result = Result & EnumParameter.ParameterEnum.EnumValues.Item(i).DisplayName & ","
Next
Else
Result = "-,"
End If
GetParameterEnumList = Split(Result,",")
End Function
Function GetEnumIndex(EnumParameter As AutoParameter) As Integer
Dim Result As Integer
If Not EnumParameter Is Nothing Then
For i = 1 To EnumParameter.ParameterEnum.EnumValues.Count
If Trim(UCase(EnumParameter.ParameterEnum.EnumValues.Item(i).DisplayName)) Like Trim(UCase(EnumParameter.DisplayString)) Then
Result = i-1
End If
Next
Else
Result = 0
End If
GetEnumIndex=Result
End Function
Sub SetEnumValue(EnumParameter As AutoParameter, ValueIndex As Integer)
If Not EnumParameter Is Nothing Then
EnumParameter.ParameterEnum.SetDisplayValue EnumParameter.ParameterEnum.EnumValues.Item(ValueIndex+1).DisplayName, ""
End If
End Sub
Rem See DialogFunc help topic for more information.
Private Function SourceControllerFunction(DlgItem$, Action%, SuppValue?) As Boolean
Select Case Action%
Case 1 ' Dialog box initialization
Set Source_Enum = GlobalTO.XRioDocument.GetParamFromIDs(TEST_CONTROLLER_PATH & ".SOURCE")
Source_Array = GetParameterEnumList(Source_Enum)
DlgEnable "txtSelectedSource",False
DlgListBoxArray "dlbSource",Source_Array()
DlgValue "dlbSource",GetEnumIndex(Source_Enum)
DlgText "txtSelectedSource", GetSourceControllerFeedback(DlgText("dlbSource"))
Case 2 ' Value changing or button pressed
Rem SourceControllerFunction = True ' Prevent button press from closing the dialog box
Select Case DlgItem
Case "dlbSource"
DlgText "txtSelectedSource", GetSourceControllerFeedback(DlgText(DlgItem))
SourceControllerFunction = True
Case "btnOK"
SetEnumValue Source_Enum, DlgValue("dlbSource")
Set Source_Enum = Nothing
Case "CancelButton"
Set Source_Enum = Nothing
Case Else
End Select
Case 3 ' TextBox or ComboBox text changed
Case 4 ' Focus changed
Case 5 ' Idle
Rem Wait .1 : SourceControllerFunction = True ' Continue getting idle actions
Case 6 ' Function key
End Select
End Function
Private Function GetSourceControllerFeedback(Reference As String) As String
Select Case Reference
Case "Source 1"
GetSourceControllerFeedback = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(SOURCE_PATH & ".SOURCE1.NAME"))
Case "Source 2"
GetSourceControllerFeedback = GetDisplayString (GlobalTO.XRioDocument.GetParamFromIDs(SOURCE_PATH & ".SOURCE2.NAME"))
End Select
End Function
So, this is the final tutorial for the Omicron Control Center Custom Dialog series. In the next tutorial, I will show you how to implement UserField in the OCC document with the integration of the custom dialog that we created in this series. Check the video below to see what I mean.
See you next time.
Comments
Post a Comment