OneCompiler

fault

1354

Example heading with h2 size

Example heading with h3 size

Following is sample java code.


#--------------------------------------------------------------------------------------------------
# Import python modules.
#--------------------------------------------------------------------------------------------------
import os
import sys
import win32api # Sleep

#--------------------------------------------------------------------------------------------------
# Import .NET assemblies
#--------------------------------------------------------------------------------------------------
import clr
import System


# Load ASAM assemblies from the global assembly cache (GAC)
assemblyString = "ASAM.XIL.Interfaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=bf471dff114ae984"
clr.AddReference(assemblyString)

assemblyString = "ASAM.XIL.Implementation.TestbenchFactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fc9d65855b27d387"
clr.AddReference(assemblyString)

# Import XIL API .NET classes from the .NET assemblies
from ASAM.XIL.Implementation.TestbenchFactory.Testbench import TestbenchFactory
from ASAM.XIL.Interfaces.Testbench.EESPort.Error import EESPortException
from ASAM.XIL.Interfaces.Testbench.EESPort.Enum import EESPortState, ErrorCategory, ErrorType, LoadType, TriggerType

#----------------------------------------------------------------------
# Define the variables to use in this demo
#----------------------------------------------------------------------
vendorName           = "dSPACE GmbH"
productName          = "XIL API"
productVersion       = "2020-A"

# Get the directory of this script
workingDir = os.path.dirname(os.path.realpath(__file__))
if os.path.isdir(workingDir) == 0:
    workingDir = os.getcwd()

workingDir = os.path.abspath(workingDir)

#-------------------------------------------------------------------------------------
# The following file path variable must be modified by user.
#-------------------------------------------------------------------------------------
##portConfigFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDir, r"..\Common\PortConfigurations\FullSizeVariant1\FullSizeVariant1.portconfig"))
##portConfigFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDir, r"..\Common\PortConfigurations\FullSizeVariant2\FullSizeVariant2.portconfig"))
##portConfigFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDir, r"..\Common\PortConfigurations\MidSizeBasedOnDS2210\MidSizeBasedOnDS2210_DS789.portconfig"))
portConfigFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDir, r"..\Common\PortConfigurations\MidSizeBasedOnDS2211\MidSizeBasedOnDS2211.portconfig"))
##portConfigFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDir, r"..\Common\PortConfigurations\MidSizeBusBasedOnDS2211\MidSizeBusBasedOnDS2211.portconfig"))
##portConfigFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDir, r"..\Common\PortConfigurations\SCALEXIO\SCALEXIO.portconfig"))

#--------------------------------------------------------------------------------------------------
# Helpers
#--------------------------------------------------------------------------------------------------
def GetStateAsString(eesPort):
    """get eesport state as string
    @param eesPort - the eesport instance
    """
    if eesPort.State == EESPortState.eDISCONNECTED:
        return 'Disconnected'
    elif eesPort.State == EESPortState.eCONNECTED:
        return 'Connected'
    elif eesPort.State == EESPortState.eDOWNLOADED:
        return 'Downloaded'
    elif eesPort.State == EESPortState.eACTIVATED:
        return 'Activated'
    else:
        return '<????>'



#------------------------------------------------------------------------------
# Define the demo function.
#------------------------------------------------------------------------------
def ExecuteDemo():
    #--------------------------------------------------------------------------
    # Enclose XIL API class objects with try:-finally: block, to ensure that
    # these objects are deleted at the end of the function.
    #--------------------------------------------------------------------------
    testbenchFactory = None
    testbench = None
    eesPort = None
    eesPortConfig = None
    errorConfiguration = None
    success = False

    try:
        # Create TestBenchFactory.
        testbenchFactory = TestbenchFactory()
        testbench = testbenchFactory.CreateVendorSpecificTestbench(vendorName, productName, productVersion)

        # Create an EESPort instance.
        print(" 1. Create EESPort.") 
        eesPort = testbench.EESPortFactory.CreateEESPort("Demo: EESPort Basics")

        print(" 2. Load vendor specific EESPort configuration from file '%s'" % portConfigFilePath)
        eesPortConfig = eesPort.LoadConfiguration(portConfigFilePath)

        print(" 3. Configure EESPort.")
        eesPort.Configure(eesPortConfig)

        # Create an empty error configuration.
        print(" 4. Create and configure a new error configuration.")
        errorConfiguration = testbench.EESPortFactory.CreateErrorConfiguration("Basics error configuration")
        factory = errorConfiguration.GetErrorFactory()
        errorConfiguration.AddErrorSet(errorConfiguration.CreateErrorSet("First error set (3 active errors)", TriggerType.eMANUAL))
        errorConfiguration.AddErrorSet(errorConfiguration.CreateErrorSet("Second error set (2 active errors)", TriggerType.eMANUAL))
        errorConfiguration.AddErrorSet(errorConfiguration.CreateErrorSet("Third error set (1 active errors)", TriggerType.eMANUAL))
        errorConfiguration.AddErrorSet(errorConfiguration.CreateErrorSet("Last error set (No active errors)", TriggerType.eMANUAL))

        # Add errors to first error set.
        errorConfiguration.ErrorSets[0].AddError(factory.CreateInterruptError("Signal 1").AsSimple().ToBaseError())
        errorConfiguration.ErrorSets[0].AddError(factory.CreateInterruptError("Signal 2").AsSimple().ToBaseError())
        errorConfiguration.ErrorSets[0].AddError(factory.CreateInterruptError("Signal 3").AsSimple().ToBaseError())

        # Add errors to second error set.
        errorConfiguration.ErrorSets[1].AddError(factory.CreateInterruptError("Signal 2").AsSimple().ToBaseError())
        errorConfiguration.ErrorSets[1].AddError(factory.CreateInterruptError("Signal 3").AsSimple().ToBaseError())

        # Add errors to third error set.
        errorConfiguration.ErrorSets[2].AddError(factory.CreateInterruptError("Signal 3").AsSimple().ToBaseError())

        #-------------------------------------------------------------
        # Set the new created error configuration to EESPort.
        #-------------------------------------------------------------
        eesPort.SetErrorConfiguration(errorConfiguration)

        # Download.
        print(" 5. Download the error configuration.")
        eesPort.Download()

        # Activate.
        print(" 6. Activate the error configuration.")
        eesPort.Activate()
        print("     EESPort state: %s" % GetStateAsString(eesPort))

        # Trigger.
        print(" 7. Trigger(Activate) error sets.")
        eesPort.Trigger()
        print("     Current active error set is '%s'." % eesPort.GetActiveErrorSet().Name)
        print("      -> Wait 2 seconds.")
        win32api.Sleep(2000)

        eesPort.Trigger()
        print("     Current active error set is '%s'." % eesPort.GetActiveErrorSet().Name)
        print("      -> Wait 2 seconds.")
        win32api.Sleep(2000)

        eesPort.Trigger()
        print("     Current active error set is '%s'." % eesPort.GetActiveErrorSet().Name)
        print("      -> Wait 2 seconds.")
        win32api.Sleep(2000)

        eesPort.Trigger()
        print("     Current active error set is '%s'." % eesPort.GetActiveErrorSet().Name)
        print("      -> Wait 1 seconds.")
        win32api.Sleep(1000)

        #Deactivate.
        print(" 8. Deactivate the error configuration..")
        eesPort.Deactivate()

        # Unload.
        print(" 9. Unload the error configuration..")
        eesPort.Unload()

        # Disconnect.
        print("10. Disconnect EESPort.")
        eesPort.Disconnect()

        success = True

    except EESPortException as e:
        print("EESPortException caught: %s" % e.Message)
        #print("VendorCode: %s, VendorCodeDescription: %s" % (e.VendorCode, e.VendorCodeDescription))
        #print(e.StackTrace)
        
    except System.ArgumentOutOfRangeException as e:
        print("ArgumentOutOfRangeException caught: %s" % e.Message)
        ##Show StackTrace
        #print(e.StackTrace)

    except System.Exception as e:
        print("Exception caught: %s" % e.Message)
        ##Show StackTrace
        #print(e.StackTrace)

    finally:
        eesPortConfig       = None
        errorConfiguration  = None
        testbench           = None
        testbenchFactory    = None
        
        if eesPort:
            print("11. Dispose EESPort.")
            eesPort.Dispose()
            eesPort = None

    return success


#--------------------------------------------------------------------------------------------------
# Main Program
#--------------------------------------------------------------------------------------------------
if __name__ == '__main__':

    print("\n--------------------------------------------------")
    print("            XIL API EESPort Demo : Basics         ")
    print("--------------------------------------------------")
            
    ExecuteDemo()

    print("--------------------------------------------------")
    print("      XIL API EESPort Demo : Basics finished!     ")
    print("--------------------------------------------------")