Short example of handling messages from the Compliance Apps

In [1]:
"""Import the compiled Python for .Net module"""
import clr
#import visa
from visa import *
scope = instrument("TCPIP0::") # Connect to the scope using the VISA address (see below)
"""Import .NET types"""
from System.Runtime.Remoting import *
from System.Windows.Forms import *

"""Import the Agilent automated test app remote library DLL"""
from Agilent.Infiniium.AppFW.Remote import *

Code below establishes connection with Scope Compliance Framework on scope at IP address 169.254.

In [2]:
"""Connect to the automated test application running on the scope
This will wait for the application to be fully launched and ready
before proceeding"""
scopeIpAddress = ''
scope.write(":SYSTEM:LAUNCH 'U7232B DisplayPort Test App'")
remoteObj = RemoteAteUtilities.GetRemoteAte(scopeIpAddress)
remoteApp = IRemoteAte(remoteObj)

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.

In [3]:
configFileFullPath = "c:\Python27\DLLs\Agilent.Infiniium.AppFw.Remote.config";
RemotingConfiguration.Configure(configFileFullPath, False);

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.

In [4]:
"""Define the event callback handler"""
def SimpleMessageEventHandler(source, args):
    print 'Received message: ' + args.Message

    if args.Message.find('Please configure the DUT to output HFTP signal without SSC. Trigger') >= 0:
         print "no signal found "
         args.Response = DialogResult.Cancel
    elif args.Message.find('selected tests completed') >= 0:
         print "All tests completed"
         args.Response = DialogResult.OK
    elif args.Message.find('Please configure the DUT to output HFTP signal without SSC') >= 0:
         print "HFTP w/o SSC"
         args.Response = DialogResult.OK

    elif args.Message.find('setup is required') >= 0:
         print "Setup required message caught"
         args.Response = DialogResult.Retry

    elif args.Message.find('following data available') >= 0:
         print "following data available"
         args.Response = DialogResult.No

    elif args.Message.find('selected tests reported problems') >= 0:
        args.Response = DialogResult.OK
    elif args.Message.find('Expected Signal Not Found') >= 0:
        print "Expected Signal Not Found"
        args.Response = DialogResult.Cancel
        print 'Message not handled'

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.

In [5]:
eventSink = RemoteAteUtilities.CreateAteEventSink(remoteApp, None, scopeIpAddress)

"""Subscribe to events of interest"""
eventSink.RedirectMessagesToClient = True
eventSink.SimpleMessageEvent += SimpleMessageEventHandler
In [6]:
eventSink.SimpleMessageEvent -= SimpleMessageEventHandler
In [7]: