OneCompiler

fault3

1216

Example heading with h2 size

Example heading with h3 size

Following is sample java code.



import os
import win32api
import clr
import System

# Load required .NET assemblies
clr.AddReference("ASAM.XIL.Interfaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=bf471dff114ae984")
clr.AddReference("ASAM.XIL.Implementation.TestbenchFactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fc9d65855b27d387")

# Import XIL API classes
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, TriggerType

# Helper function to get EESPort state as a string
def GetStateAsString(eesPort):
    return EESPortState(eesPort.State).ToString()

# Simplified function to run the demo
def ExecuteDemo():
    try:
        # Set up test bench
        tb_factory = TestbenchFactory()
        testbench = tb_factory.CreateVendorSpecificTestbench("dSPACE GmbH", "XIL API", "2020-A")
        eesPort = testbench.EESPortFactory.CreateEESPort("Demo: EESPort Basics")
        
        # Load and configure EESPort
        config_path = os.path.abspath(r"..\Common\PortConfigurations\MidSizeBasedOnDS2211\MidSizeBasedOnDS2211.portconfig")
        eesPortConfig = eesPort.LoadConfiguration(config_path)
        eesPort.Configure(eesPortConfig)
        
        # Create and set error configuration
        errorConfig = testbench.EESPortFactory.CreateErrorConfiguration("Advanced Error Config")
        factory = errorConfig.GetErrorFactory()
        
        # Create and add various error sets
        error_sets = {
            "First error set (Interrupt errors)": [
                factory.CreateInterruptError("Signal 1").AsSimple().ToBaseError(),
                factory.CreateInterruptError("Signal 2").AsSimple().ToBaseError(),
                factory.CreateInterruptError("Signal 3").AsSimple().ToBaseError()
            ],
            "Second error set (Timing error)": [
                factory.CreateTimingError("Signal 4", 100).AsSimple().ToBaseError()  # Delay of 100ms
            ],
            "Third error set (Value errors)": [
                factory.CreateValueError("Signal 5", 999).AsSimple().ToBaseError(),  # Incorrect value
                factory.CreateValueError("Signal 6", -1).AsSimple().ToBaseError()    # Another incorrect value
            ],
            "Fourth error set (Range error)": [
                factory.CreateRangeError("Signal 7", 0, 100).AsSimple().ToBaseError()  # Out of range error
            ],
            "Fifth error set (Connection error)": [
                factory.CreateConnectionError("Port 1").AsSimple().ToBaseError()  # Connection failure
            ]
        }
        
        for set_name, errors in error_sets.items():
            errorSet = errorConfig.CreateErrorSet(set_name, TriggerType.eMANUAL)
            for error in errors:
                errorSet.AddError(error)
            errorConfig.AddErrorSet(errorSet)
        
        eesPort.SetErrorConfiguration(errorConfig)
        eesPort.Download()
        eesPort.Activate()
        
        # Trigger errors and monitor state
        for _ in range(len(error_sets)):
            eesPort.Trigger()
            print(f"Active error set: {eesPort.GetActiveErrorSet().Name}")
            win32api.Sleep(2000)
        
        # Clean up
        eesPort.Deactivate()
        eesPort.Unload()
        eesPort.Disconnect()
        eesPort.Dispose()
        
        return True
    except EESPortException as e:
        print(f"EESPortException: {e.Message}")
    except System.Exception as e:
        print(f"System.Exception: {e.Message}")
    return False

# Run the demo
if __name__ == '__main__':
    print("Starting XIL API EESPort Demo")
    if ExecuteDemo():
        print("Demo completed successfully!")
    else:
        print("Demo encountered an error.")