{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

The example code below illustrates how to handle events with N5990A Valiframe automation.\n", "
These examples suppress all windows dialog prompts and instead redirect messages to the Python prompt

\n", "*For a more general overview of automation of Agilent Instruments using Python including N5990A ValiFrame [see here](Python_Automation.ipynb)*\n", "
\n", "
\n", "First we will make our imports and connections to the ValiFrame environment." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import time\n", "import win32api\n", "import sys\n", "sys.path.append('C:\\\\Program Files (x86)\\\\BitifEye\\\\ValiFrame\\\\MPhy') # Add the location of the Valiframe dll's to the system path\n", "import clr # Import the Common Runtime Library Python module\n", "\n", "clr.AddReference(\"ValiFrameRemote\") # Create a reference from CLR to the ValiFrameRemote DLL\n", "clr.AddReference(\"VFBase\") # Create a reference from CLR to the VFBase DLL\n", "clr.AddReference(\"VFSequence\") # Create a reference from CLR to the VFSequence DLL\n", "clr.AddReference(\"VFUserInterface\") # Create a reference from CLR to the VFUserInterface DLL\n", "\n", "from BitifEye.ValiFrame.ValiFrameRemote import * # Import the entire ValiFrameRemote namespace from the DLL\n", "from BitifEye.ValiFrame.Base import * # Import the entire Base namespace from the DLL\n", "from BitifEye.ValiFrame.Sequence import * # Import the entire Sequence namespace from the DLL\n", "from BitifEye.ValiFrame.UserInterface import * # Import the entire UserInterface namespace from the DLL\n", "from BitifEye.Controls import * # Import the entire Controls namespace from the DLL" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we need to create functions to handle what happens when Valiframe creates an event.\n", "
In the example below we choose to handle events in the following way:\n", "" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def my_LogChanged(logentry):\n", " pass\n", "\n", "def my_StatusChanged(source,status):\n", " print('Status Changed: ' + status)\n", "\n", "def my_ProcedureCompleted(procedure,xmlresult):\n", " raw_input('Procedure Completed: ' + procedure + ' ' + xmlresult)\n", "\n", "def my_DialogPopUp(source, args):\n", " #args.Dialog.ShowDialog() #Uncomment to show Valiframe dialog box for all cases\n", " msgbox = args.DialogText\n", "\n", " # Definition for args.DialogType\n", " #Member name Value Description \n", " #Form 0 General Form if the dialog is not one of the other dialog types \n", " #MessageBox 1 Standard Windows.Forms.MessageBox. \n", " #ConnectionDialog 2 Connection dialog. The dialog which pops up if a connection change is required. \n", " #UserInformationDialog 3 User Information Dialog, which contains a text and one button. \n", " #UserDecisionDialog 4 User Decision Dialog, which contains one text and 2 buttons. \n", " #InfoDialog 5 Info Dialog, which is the same as the UserInformationDialog (obsolete, will be removed in one of the next releases). \n", "\n", " if args.DialogType == 0:\n", " raw_input('General Form Dialog: '+str(msgbox))\n", " # add actions here.....\n", " # args.Dialog.ShowDialog() #Uncomment to show dialog box for this case\n", " elif args.DialogType == 1:\n", " raw_input('Standard Windows.Forms.MessageBox: '+str(msgbox))\n", " # add actions here.....\n", " # args.Dialog.ShowDialog() #Uncomment to show dialog box for this case\n", " elif args.DialogType == 2:\n", " raw_input('Connection Dialog: '+str(msgbox))\n", " # add actions here.....\n", " # args.Dialog.ShowDialog() #Uncomment to show dialog box for this case\n", " elif args.DialogType == 3:\n", " raw_input('UserInformationDialog: '+str(msgbox))\n", " # add actions here.....\n", " # args.Dialog.ShowDialog() #Uncomment to show dialog box for this case\n", " elif args.DialogType == 4:\n", " raw_input('UserDecisionDialog: '+str(msgbox))\n", " # add actions here.....\n", " # args.Dialog.ShowDialog() #Uncomment to show dialog box for this case\n", " elif args.DialogType == 5:\n", " raw_input('InfoDialog: '+str(msgbox))\n", " # add actions here.....\n", " # args.Dialog.ShowDialog() #Uncomment to show dialog box for this case\n", " else:\n", " raw_input('Message not handled: '+str(msgbox))" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we need to create an instance of the ValiFrameRemote object" ] }, { "cell_type": "code", "collapsed": false, "input": [ "my_vf_mipi = ValiFrameRemote() # Creates an instance of the ValiFrameRemote class" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we need to register the event ValiFrame event handlers with the functions created above" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#register event handlers\n", "my_vf_mipi.LogChanged += LogChangedEventHandler(my_LogChanged);\n", "my_vf_mipi.StatusChanged += StatusChangedEventHandler(my_StatusChanged);\n", "my_vf_mipi.ProcedureCompleted += ProcedureCompletedEventHandler(my_ProcedureCompleted);\n", "my_vf_mipi.DialogPopUp += DialogShowEventHandler(my_DialogPopUp);" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 12 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we launch the application & load a config" ] }, { "cell_type": "code", "collapsed": false, "input": [ "my_vf_mipi.InitApplication(\"MPhy\") # Initialize the application\n", "my_vf_mipi.LoadProject(\"my_MIPI3_proj.vfp\")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Example 1: Synchronous RunProcedure() or RunProcedure() methods

\n", "" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# run procedures synchronously\n", "results = my_vf_mipi.RunProcedure(5500000)" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Start\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Station Init\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Product MPhy Init\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Init\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Connection Dialog: Connect the outputs of Data0 to the test fixture of the DUT.\\par Connect the Trig/Ref Clock outputs of the JBERT to the Ref Clock Input of the DUT.\\par Add TTCs of 250 ps to the signal path.\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Standard Windows.Forms.MessageBox: Missing Levels Calibration! Do you like to run the test without calibration?\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Start Iteration 0\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Step 0\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Step 1\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s CleanUp\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Complete\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Product MPhy Complete\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Station Complete\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Complete\n" ] } ], "prompt_number": 6 }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the above example the program pauses at each line above waiting for the user to hit enter per our use of raw_input()." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Example 2: Asynchronous StartRun() method

\n", "" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# run procedures asynchronously\n", "my_procedure = [5500000] ## define variable for procedures to execute\n", "my_vf_mipi.SelectProcedures(my_procedure)\n", "my_vf_mipi.StartRun()\n", "while True:\n", " time.sleep(2)\n", " status = my_vf_mipi.GetActualStatus()\n", " if status == 'Complete':\n", " break" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Connection Dialog: Connect the outputs of Data0 to the test fixture of the DUT.\\par Connect the Trig/Ref Clock outputs of the JBERT to the Ref Clock Input of the DUT.\\par Add TTCs of 250 ps to the signal path.\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Standard Windows.Forms.MessageBox: Missing Levels Calibration! Do you like to run the test without calibration?\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Status Changed: Start\n", "Status Changed: Station Init\n", "Status Changed: Product MPhy Init\n", "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Init\n", "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Start Iteration 0\n", "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Step 0\n", "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Step 1\n", "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s CleanUp\n", "Status Changed: Procedure Test 2.1.1 - HS-RX Differential Input Voltage Amplitude Data0 at 1.248 GBit/s Complete\n", "Status Changed: Product MPhy Complete\n", "Status Changed: Station Complete\n", "Status Changed: Complete\n" ] } ], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "# Unregister the event handlers\n", "my_vf_mipi.LogChanged -= LogChangedEventHandler(my_LogChanged);\n", "my_vf_mipi.StatusChanged -= StatusChangedEventHandler(my_StatusChanged);\n", "my_vf_mipi.ProcedureCompleted -= ProcedureCompletedEventHandler(my_ProcedureCompleted);\n", "my_vf_mipi.DialogPopUp -= DialogShowEventHandler(my_DialogPopUp);\n", "# close object\n", "my_vf_mipi.Finalize()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Copyright \u00a9 2011 Agilent Technologies Inc. All rights reserved.\n", "\n", "You have a royalty-free right to use, modify, reproduce and distribute this content (and/or any modified version) in any way you find useful, provided that you agree that Agilent has no warranty, obligations or liability." ] } ], "metadata": {} } ] }