OneCompiler

read slexio

172

import clr
import sys
import os
import time
from win32com.client import Dispatch
import common_def

clr.AddReference("ASAM.XIL.Implementation.TestbenchFactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fc9d65855b27d387")
clr.AddReference("ASAM.XIL.Interfaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=bf471dff114ae984")
clr.AddReference("ASAM.XIL.Implementation.FrameworkFactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=d64b0277da8a2c74")

Import XIL API.NET classes from the .NET assemblies

from ASAM.XIL.Implementation.TestbenchFactory.Testbench import TestbenchFactory
from ASAM.XIL.Interfaces.Testbench.Common.Error import TestbenchPortException
from ASAM.XIL.Interfaces.Testbench.MAPort.Enum import MAPortState

MAPortConfigFile = "D:\AUD_FRAMEWORK\python_files\MAPortConfigSCALEXIO.xml"

batteryvolt = "Model Root/I0UserInterface/IO_PAR/Simulator/Power_Supply/Voltage_Out/Value"
batteryread = 'Model Root/IOUserInterface/IO_DISP/Simulator/Power_Supply/Simulator_Voltage_In/In1'

WorkingDir = os.path.dirname(sys.argv[0])
if not os.path.isdir(WorkingDir):
WorkingDir = os.getcwd()
if not os.path.isdir(WorkingDir):
os.mkdir(WorkingDir)

MAPortConfigFile = os.path.join(WorkingDir, MAPortConfigFile)

if name == "main":

DemoMAPort = None

try:
    MyTestbenchFactory = TestbenchFactory()
    MyTestbench = MyTestbenchFactory.CreateVendorSpecificTestbench("dSPACE GmbH", "XIL API", "2018-B")
    MyMAPortFactory = MyTestbench.MAPortFactory
    MyValueFactory = MyTestbench.ValueFactory
    print("Creating MAPort instance...")
    # Create an MAPort object using the MAPortFactory
    DemoMAPort = MyMAPortFactory.CreateMAPort("DemoMAPort")
    print("...done.\n")

    # Load the MAPort configuration
    print("Configuring MAPort...")
    DemoMAPortConfig = DemoMAPort.LoadConfiguration(MAPortConfigFile)
    # Apply the MAPort configuration
    DemoMAPort.Configure(DemoMAPortConfig, False)
    print("...done.\n")
    if DemoMAPort.State != MAPortState.eSIMULATION_RUNNING:
        # Start the simulation
        print("Starting simulation...")
        DemoMAPort.StartSimulation()
        print("...done.\n")

    # volt = [10.00, 8.7, 12.0, 9.0, 14.0]
    #
    # for i in range(len(volt)):
    #     DemoMAPort.Write(batteryvolt, MyValueFactory.CreateFloatValue(volt[i]))
    #     print("Writing value voltage to %s\n" % batteryvolt)
    #
    #     NewReadVal = DemoMAPort.Read(batteryread)
    #
    #     print("Read battery voltage now is: %s %s\n" % (batteryread, NewReadVal.Value))
    #
    #     time.sleep(5)

    KL30_off_path,KL30_off_value = common_def.KL30_off()
    DemoMAPort.Write(batteryvolt, MyValueFactory.CreateFloatValue(KL30_off_value))
    KL30_on_path,KL30_on_value = common_def.KL30_on()
    DemoMAPort.Write(batteryvolt, MyValueFactory.CreateFloatValue(KL30_on_value))
    LED_read_path,LED_read_Value = common_def.SLML_STATUS_FD_LEFT()
    DemoMAPort.Write(batteryvolt, MyValueFactory.CreateFloatValue(KL30_on_value))

    print("Demo successfully finished!\n")

except TestbenchPortException as ex:
    print("A TestbenchPortException occurred:")
    print("CodeDescription: %s" % ex.CodeDescription)
    print("VendorCodeDescription: %s" % ex.VendorCodeDescription)
    raise

finally:
    if DemoMAPort is not None:
        DemoMAPort.Dispose()
        DemoMAPort = None