Welcome to my page. This is the second part of the Omicron Import Filter tutorial series. In this tutorial, I will show you how install and use the Import Filter that we've created in the previous tutorial in this series using two methods. The first one via Test Object and the second one is via script.
Open the Visual Studio project called MyImportFilter that we created in the first part of tutorial which can be found here (Omicron Import Filter - Create New Filter). Once the project opened, right click on the project at the solution explorer the click Open Folder in File Explorer. The project file directory will open. Open the bin\Debug folder and you will find the two files in that folder (MyImportFilter.dll and SampleFilter.xriofilter). Create new folder in that directory and set the folder name to MyImportFilter.
Move the MyImportFilter.dll file to the MyImportFilter folder then, copy the MyImportFilter folder and the SampleFilter.xriofilter file. Navigate to %PROGRAMFILES(x86)%\OMICRON\Test Universe\Apps\XRio\Filters for 32-bit or %PROGRAMFILES%\OMICRON\Test Universe\Apps\XRio\Filters for 64-bit then paste the MyImportFilter folder and the SampleFilter.xriofilter in the filters folder.
Now, download the OCC test document in this link (Omicron Control Center - Using Import Filter). This OCC test document was created in the previous tutorial (Omicron Control Center Custom Dialog - Change Data With Feedback).
Open the OCC test document then open the Test Object. From there we could access the import filter that we installed and run it. In the Test Object window, click the File>Import Relay Settings menu.
We have successfully execute the Import Filter via Test Object. Next I will show you how to execute the Import Filter using script.
Now open the Script window by clicking the Script View button at the View tab. Stop the script if running. Copy the code below and paste it to the very bottom of the script.
Const TEXT_IMPORT_SETTINGS As String = "Do you want to import the relay setting?"
Const USER_DIALOG_IMPORT_SETTINGD As String = "Import Relay Setting "
Public Sub ImportRelaySettings()
On Error GoTo ErrorHandler
Dim xrioapp As XRio
Dim i As Integer
Dim fil As Variant
Dim Automation As Integer
Dim IsImportFilterFound As Boolean
IsImportFilterFound=False
Automation=GenericMessageBox(TEXT_IMPORT_SETTINGS,USER_DIALOG_IMPORT_SETTINGD,1)
If Automation = vbYes Then
Set xrioapp = Document.TestObjects(1).Specific
For i = 1 To xrioapp.XRioFilters.Count
If xrioapp.XRioFilters(i).ID = "MyImportFilter.SampleFilter" Then
IsImportFilterFound=True
If xrioapp.XRioFilters(i).ShowParameterDialog(True) Then
If xrioapp.XRioFilters(i).ExecuteImport Then
End If
End If
Exit For
End If
Next
If Not IsImportFilterFound Then
MsgBox("No import filter installed on this computer for this test plan/routine.", vbOkOnly+ vbInformation,"Import Filter Not Installed")
End If
Set xrioapp = Nothing
Document.TestObjects(1).CommitChanges
End If
Exit Sub
ErrorHandler:
MsgBox ("Importing relay settings cannot be perform." & vbNewLine & "Maybe the import filter was not installed.", vbOkOnly+ vbCritical,"Error")
End Sub
Public Function GenericMessageBox(Text As String, Title As String, style As Integer) As Integer
'Parameters:
'Text: The text prompted to the user
'Title: Title of the Message Box
'Style: Choose between two styles, 1 = YesNo with Yes as default and question mark, 2 = OkCancel with Ok as default and information icon
Dim MsgBoxStyle As Integer
If style = 1 Then
MsgBoxStyle = vbYesNo Or vbDefaultButton1 Or vbQuestion
ElseIf style = 2 Then
MsgBoxStyle = vbOkCancel Or vbDefaultButton1 Or vbInformation
End If
GenericMessageBox = MsgBox(Text,MsgBoxStyle,Title)
End Function
Highlight the ImportRelaySetting procedure as shown in the image below then click the User Commands button under Tools group. Check on the Show as button, set the display name to Import Relay Settings and set the tooltip to Click here to import the relay settings. Then, click Add button and close the user commands dialog box.
Close the Script window by clicking the Back to Report View button and check the Home tab, the Import Relay Settings command should be added in the ribbon menu.
We have successfully executed the Import Filter using the script. In the next tutorial, I will show you how to create a user interface (UI) for this Import Filter and I will show you how to access the Test Object parameters in the user interface (UI). See you next time.
Comments
Post a Comment