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

Short example of handling messages from the Compliance Apps

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\"\"\"Import the compiled Python for .Net module\"\"\"\n", "import clr\n", "#import visa\n", "from visa import *\n", "scope = instrument(\"TCPIP0::156.140.158.229::inst0::INSTR\") # Connect to the scope using the VISA address (see below)\n", "\"\"\"Import .NET types\"\"\"\n", "from System.Runtime.Remoting import *\n", "from System.Windows.Forms import *\n", "\n", "\"\"\"Import the Agilent automated test app remote library DLL\"\"\"\n", "clr.AddReference(\"Agilent.Infiniium.AppFW.Remote\")\n", "from Agilent.Infiniium.AppFW.Remote import *" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Code below establishes connection with Scope Compliance Framework on scope at IP address 169.254." ] }, { "cell_type": "code", "collapsed": false, "input": [ "\"\"\"Connect to the automated test application running on the scope\n", "This will wait for the application to be fully launched and ready\n", "before proceeding\"\"\"\n", "scopeIpAddress = '156.140.158.229'\n", "scope.write(\":SYSTEM:LAUNCH 'U7232B DisplayPort Test App'\")\n", "remoteObj = RemoteAteUtilities.GetRemoteAte(scopeIpAddress)\n", "remoteApp = IRemoteAte(remoteObj)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Message handling requires establishing a call back path for .NET remoting to operate properly. The following code establishes the path to the file Agilent.Infiniium.AppFw.Remote.config. No modifications are needed to this file." ] }, { "cell_type": "code", "collapsed": false, "input": [ "configFileFullPath = \"c:\\Python27\\DLLs\\Agilent.Infiniium.AppFw.Remote.config\";\n", "RemotingConfiguration.Configure(configFileFullPath, False);" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following is the Python message handler that will handle simple messages being generated by the compliance application framework. It is the responsibility of the message handler function to handle all the possible messages that can be generated as all simple messages require a response. If a message is not handled correctly an exception will be generated aborting the execution of the compliance applicaiton. The end of the function's else construct has a statement stating \"Message Not Handled\" and should only be needed during development debug. Ultimately all messages need to caught and therefore the string \"Message Not Handled\" should never be encountered." ] }, { "cell_type": "code", "collapsed": false, "input": [ "\"\"\"Define the event callback handler\"\"\"\n", "def SimpleMessageEventHandler(source, args):\n", " print 'Received message: ' + args.Message\n", "\n", " if args.Message.find('Please configure the DUT to output HFTP signal without SSC. Trigger') >= 0:\n", " print \"no signal found \"\n", " args.Response = DialogResult.Cancel\n", " \n", " elif args.Message.find('selected tests completed') >= 0:\n", " print \"All tests completed\"\n", " args.Response = DialogResult.OK\n", " \n", " elif args.Message.find('Please configure the DUT to output HFTP signal without SSC') >= 0:\n", " print \"HFTP w/o SSC\"\n", " args.Response = DialogResult.OK\n", "\n", " elif args.Message.find('setup is required') >= 0:\n", " print \"Setup required message caught\"\n", " args.Response = DialogResult.Retry\n", "\n", " elif args.Message.find('following data available') >= 0:\n", " print \"following data available\"\n", " args.Response = DialogResult.No\n", "\n", " elif args.Message.find('selected tests reported problems') >= 0:\n", " args.Response = DialogResult.OK\n", " \n", " elif args.Message.find('Expected Signal Not Found') >= 0:\n", " print \"Expected Signal Not Found\"\n", " args.Response = DialogResult.Cancel\n", " \n", " else:\n", " print 'Message not handled'" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "EventSinK object handles messages being generated by compliance application framework. It is this object which we will contain the name of the Python message handler function. Setting the property RedirectMessagesToClient = True will allow messages to be sent to our message handler rather than being displayed on the scope display. The function will be assigned to handle simple messages. These messages can require a \"Cancel\", \"OK\",\"NO\" or \"Retry\" type response. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "eventSink = RemoteAteUtilities.CreateAteEventSink(remoteApp, None, scopeIpAddress)\n", "\n", "\"\"\"Subscribe to events of interest\"\"\"\n", "eventSink.RedirectMessagesToClient = True\n", "eventSink.SimpleMessageEvent += SimpleMessageEventHandler" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "eventSink.SimpleMessageEvent -= SimpleMessageEventHandler" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "eventSink.Finalize()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 7 } ], "metadata": {} } ] }