OneCompiler

run2

152

Example heading with h2 size

Example heading with h3 size

Following is sample java code.


1_ReadWrite.py
#__________________________________________
import clr
import sys, os
import time
from win32com.client import Dispatch

# Load ASAM assemblies from the global assembly cache (GAC)
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

# The following lines must be adapted to the dSPACE platform used
#------------------------------------------------------------------------------------------------
# Set IsMPApplication to true if you are using a multiprocessor platform
#IsMPSystem = True
# Use an MAPort configuration file that is suitable for your platform and simulation application
# See the folder Common\PortConfigurations for some predefined configuration files
MAPortConfigFile = r"D:\AUD_FRAMEWORK\python_files\MAPortConfigSCALEXIO.xml"

# Set the name of the task here (specified in the application's TRC file)
# Note: the default task name is "HostService" for PHS bus systems, "Periodic Task 1" for VEOS systems
# Task = "HostService" 
#--------------------------------------------------------------------------


#----------------------------------------------------------------------
# For multiprocessor platforms different tasknames and variable names have to be used.
# Some variables are part of the subappliaction "masterAppl", some belong to the 
# subapplication "slaveAppl"
#----------------------------------------------------------------------
# if IsMPSystem:
#     masterTaskPrefix = "masterAppl/"
#     slaveTaskPrefix = "slaveAppl/"
#     masterVariablesPrefix = "masterappl/Model Root/master/CentralLightEcu/"
#     slaveVariablesPrefix = "slaveappl/Model Root/slave/FrontRearLightEcu/"

# else:
#     masterTaskPrefix = ""
#     slaveTaskPrefix = ""
#     masterVariablesPrefix = "Model Root/"
#     slaveVariablesPrefix = "Model Root/"

# masterTask = masterTaskPrefix + Task
# slaveTask = slaveTaskPrefix + Task
batteryvolt= "Model Root/IOUserInterface/IO_PAR/Simulator/Power_Supply/Voltage_Out/Value"
batteryread = 'Model Root/IOUserInterface/IO_DISP/Simulator/Power_Supply/Simulator_Voltage_In/In1'
modelRoot =  "Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_2/LowBeamCmd/Value"
#--------------------------------------------------------------------------
# Set the working directory for this demo script
#--------------------------------------------------------------------------
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:
        #--------------------------------------------------------------------------
        # Create a TestbenchFactory object; the TestbenchFactory is needed to 
        # create the vendor-specific Testbench
        #--------------------------------------------------------------------------        
        MyTestbenchFactory = TestbenchFactory()

        #--------------------------------------------------------------------------
        # Create a dSPACE Testbench object; the Testbench object is the central object to access
        # factory objects for the creation of all kinds of Testbench-specific objects
        #--------------------------------------------------------------------------
        MyTestbench = MyTestbenchFactory.CreateVendorSpecificTestbench("dSPACE GmbH", "XIL API", "2018-B")

        #--------------------------------------------------------------------------
        # We need an MAPortFactory to create an MAPort and also a ValueFactory to create ValueContainer
        # objects
        #--------------------------------------------------------------------------
        MyMAPortFactory = MyTestbench.MAPortFactory
        MyValueFactory = MyTestbench.ValueFactory

        #--------------------------------------------------------------------------
        # Create and configure an MAPort object and start the simulation
        #--------------------------------------------------------------------------
        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 batgtery voltage now is: %s %s\n" % (batteryread, NewReadVal.Value))
            
            time.sleep(5)

        # DemoMAPort.Write(TurnSignalLever, MyValueFactory.CreateFloatValue(0.0))
        # print("Writing value 0.0 to %s\n" % (TurnSignalLever))

        print("")
        print("Demo successfully finished!\n")

    except TestbenchPortException as ex:
        #-----------------------------------------------------------------------
        # Display the vendor code description to get the cause of an error
        #-----------------------------------------------------------------------
        print("A TestbenchPortException occurred:")
        print("CodeDescription: %s" % ex.CodeDescription)
        print("VendorCodeDescription: %s" % ex.VendorCodeDescription)
        raise
    finally:
        #-----------------------------------------------------------------------
        # Attention: make sure to dispose the MAPort object in any case to free
        # system resources like allocated memory and also resources and services on the platform
        #-----------------------------------------------------------------------
        if DemoMAPort != None:
            DemoMAPort.Dispose()
            DemoMAPort = None




#____________________________________

common_fcns.py
#_______________________________-


# -*- coding: utf-8 -*-
"""
Created on Mon Feb  5 18:51:46 2024

@author: TN0G118148
"""
import os
import time
import shutil
import globals
# import step_libraries
# import re
from openpyxl.styles import PatternFill
# import HelperReadingFloat32 as HRF32
# import ast, operator
import win32com.client
import random
# from datetime import datetime
# #from xlsx2html import xlsx2html
# import pandas as pd
#
# from tkinter import *
# from tkinter import filedialog
# from PIL import ImageTk, Image

def print_info(error_SL):
    try:
#        if "Error" in Error_AUD.Value or "Failed" in Error_AUD.Value or "Exit" in Error_AUD.Value:
        if error_SL != None:
            if globals.setup == 0:
                globals.SL.Offset(1,8).Value = "ERROR"
               # globals.SL1.Offset(1,8).Value = "ERROR"
                #print on cmd window
                print("ERROR\t" + error_SL)
                #update debug file including info of SL error
                globals.debug_file.write("ERROR\t" + error_SL)
            else:
                #print on cmd window
                print("ERROR\n" + error_SL)
                #update debug file including info of SL error
                globals.debug_file.write("ERROR\t" + error_SL)
            
        else:

                #globals.SL.Offset(1,8).Value = "PASSED"
                #globals.SL1.Offset(1,8).Value = "PASSED"
                fill_cell2 = PatternFill(patternType='solid', 
                           fgColor='35FC03')
                globals.SL.Offset(1,8).fill = fill_cell2
                #globals.SL1.Offset(1,8).fill = fill_cell2
                #print on cmd window
                print("PASSED")
                #update debug file including info of SL error
                globals.debug_file.write("PASSED")
                       
        globals.debug_file.flush()  
        
        globals.error_SL = None
        
    except Exception:
        print ("exception")
        
        #Open Excel file
def openxl(excel,filepath):
    try:
        xlfile = excel.Workbooks.Open(filepath)
        excel.visible = True
        return xlfile
    except Exception as log:
        raise Exception(log)
        

#This function is used to open the parameters file and pick up the path locations of TL, INCA database,etc
# def getparameters(parameters_file):
#     #global parameters
#
#     globals.parameters = {'engine': None,
#                           'rom_filename' : None,
#                           'sdf_file' : None,
#                           'incadb_path' : None,
#                           'tl_path' : None,
#                           'hils_exp' : None,
#                           'platform' : None,
#                           'port_config_file' : None,
#                           'TargetECU_name' : None,
#                           'TargetCAN_name' : None,
#                           'TargetECU_DescFile' : None,
#                           'TargetCAN_DescFile' : None,
#                           'Port_Config' : None
#                           }
#
#     parameters_row_start = 1
#     parameters_row_end = parameters_file.Worksheets(1).Range("B" + str(parameters_file.Worksheets(1).Rows.Count)).End(-4162).Row
#     parameters_valid_range = parameters_file.Worksheets(1).Range("B" + str(parameters_row_start) +":C" + str(parameters_row_end))
#
#     for each_row in parameters_valid_range.Rows:
#         for each_cell in each_row.Columns[0]:
#             key = each_cell.Text
#             value = each_row.Columns[1].Text
#             if key == "Engine":
#                 globals.parameters['engine'] = value
#             elif key == "ROM file Name":
#                 globals.parameters['rom_filename'] = value
#             elif key == "HILS_SDF_file":
#                 globals.parameters['sdf_file'] = value
#             elif key == "INCA Database":
#                 globals.parameters['incadb_path'] = value
#             elif key == "TEST LIBRARY Path":
#                 globals.parameters['tl_path'] = value
#             elif key == "platform":
#                 globals.parameters['platform'] = value
#             elif key == "PortConfigFile":
#                 globals.parameters['port_config_file'] = value
#             elif key == "HILS_Experiment file":
#                 globals.parameters['hils_exp'] = value
#             elif key == "ECU DDT Name":
#                 globals.parameters['TargetECU_name'] = value
#             elif key == "CAN DDT Name":
#                 globals.parameters['TargetCAN_name'] = value
#             elif key == "ECU Description File":
#                 globals.parameters['TargetECU_DescFile'] = value
#             elif key == "CAN Description File":
#                 globals.parameters['TargetCAN_DescFile'] = value
#             elif key == "Port_Config":
#                 globals.parameters['Port_Config'] = value
#             elif key == "Exp_name":
#                 globals.parameters['Exp_name'] = value
#
#
#
#     #print parameters
#     #parameters_file.Close
#     parameters_file.Close()
#     return globals.parameters

def create_result(tl_path):
    #This function creates a result folder and pastes TL(result) file and report file in it
    #Also returns the location of TL result and report along with their file name
    try:
        #extracting the folder path of TL, tl_path contains tlname with folder path
        tl_locdetails = os.path.split(os.path.abspath(tl_path))
        #tl_locdetails[0] = tlpath,tl_locdetails[1] = tlfilename
        foldername = "\\Results_" + os.path.splitext(tl_locdetails[1])[0] + "\\"
        globals.Result_path = tl_locdetails[0] + foldername
        #Giving new name for TL
        result_name = "Result_" + os.path.splitext(tl_locdetails[1])[0] +  "_" + time.strftime("%Y%m%d_%H%M%S") + os.path.splitext(tl_locdetails[1])[1]
        #Creating a new folder to place the results
        if not os.path.exists(globals.Result_path):
             os.makedirs(globals.Result_path)
        #Copy pasting the TL document in the results folder
        report_source = shutil.copy(tl_path, globals.Result_path + result_name)
        globals.Result_loc = globals.Result_path + result_name
        print("Result_loc", globals.Result_loc)
        #report_source = tl_locdetails[0] + "\\Report_" + tl_locdetails[1]
        print("report_source", report_source)
        print("condition statement", os.path.isfile(report_source))
        # if os.path.isfile(report_source):
        #     report_name = "Report_" + tl_locdetails[1].split(".")[0] +  "_" + time.strftime("%Y%m%d_%H%M%S") + os.path.splitext(tl_locdetails[1])[1]
        #     shutil.copy(report_source, globals.Result_path + report_name)
        #     Report_loc = globals.Result_path + report_name
        # else:
        #     Report_loc = None
        
        
        return report_source,globals.Result_loc
    except:
        raise Exception("Error in opening TL sts")
        
def check_type():
    check_value = globals.SL.Offset(1,4).Value #Value to be checked
    if(type(check_value)==str):        
        if(check_value=="left"):
            return 2
        elif(check_value=="right") :
            return 1
        elif(check_value=="both") :
            return 3
        elif(check_value=="crank") :
            return 5
        elif(check_value=="run") :
            return 4
       
        elif(check_value[0]=="B") :
            values=check_value.split("(")[1].split(")")[0].split(",")
            globals.range1=int(values[0])
            globals.range2=int(values[1])            
            return 11111
            
    else:
        return check_value
    
    
    
#This function is used to read the variable to be checked and compare the results with the expected value  

def result_calc():
    check_value=None
    read_value=None
    check_value=check_type()
   
    #check_value = globals.SL.Offset(1,4).Value #Value to be checked        
    print("check_value assignme", check_value)
    read_value = globals.SL.Offset(1,7).Value #Software Variable Value
    check = check_value
    
    if(check_value==11111):        
        if(check in range(globals.range1,globals.range2)):            
            globals.SL.Offset(1,6).Value = "PASSED"
        else:            
            globals.SL.Offset(1,6).Value = "FAILED"
            
    # elif(check_value==100):        
    #     if(globals.SL.Offset(1,5).Value !="ERROR" ):
    #         globals.SL.Offset(1,6).Value ="PASSED"
            
    else:
      
       if read_value == check_value:  
           globals.SL.Offset(1,6).Value = "PASSED"
       elif read_value != check_value:
          globals.SL.Offset(1,6).Value = "FAILED"
  
       

    
def select_number():
    r=random.randint(1,50000)
    if r not in globals.randomList:
        # appending the random number to the resultant list, if the condition is true
        globals.randomList.append(r)
        globals.seq_Num=r
    else:
      select_number()

# def GUI():
#     def browse_TL_path():
#         TL_Path.set(filedialog.askopenfilename(filetypes=[("All Files", "*.*")]))
 
    # def submit():
    #     print("TL Path:", TL_Path.get())
    #     tkwindow.destroy()
    # # Create main TKinter window
    # tkwindow = Tk()
    # tkwindow.geometry('400x350')
    # tkwindow.title('Mareli Test Automation ')
    #
    # # logo = PhotoImage(file=r"C:\Users\RB001004323\Desktop\logo.png")
    # # Label(tkwindow, image=logo).grid(row=1, column=5)
    #
    # TL_Path = StringVar()
    #
    # TL_Label = Label(tkwindow, text="TL Path").grid(row=5, column=0)
    # TL_Entry = Entry(tkwindow, textvariable=TL_Path).grid(row=5, column=1)
    # TL_Button = Button(tkwindow, text="Browse TL", command=browse_TL_path).grid(row=5, column=2)
    # Button(tkwindow, text="Submit", command=submit).grid(row=9, columnspan=3)
    #
    # tkwindow.mainloop()
    # return TL_Path.get()
            
def perform_operation(action_name,action_value):

    if action_name == "KL30_off":
        pass


#______________________________
globals.py


#______________________________

#Objects and variables which are required to be used across modules are initialized in this file

setup = 0
count=0
dir_path = None
parameters = None
Modelroot = None
cal_defaultvalues = {}
debug_file = None
Call_SL=None

#Handle for TL result document
Result_file = None
Result_path = None
Report_loc = None

#Handle for SL, to access values in row of SL
TL_sheet = None
SL = None
SL1 = None
SL_endrow = None
SL1_endrow=None
delay_time = 1
cnt=0
xl_endloc1=None
Sheet_No=None
#INCA handles for experiment
ExperimentView = None
Experiment = None
WrkDev = None

#Handles for AutomationDesk sequence folder and Inputs data container
ProjObj = None
Step_libraries = None
Inputs = None
InputchildObj = None # Objects inside Inputs data container
FIU_Inputs = None
FIU_InputschildObj = None


#Handle for 2nd Excelsheet
excel = None
#excel_open = None
Macro = None
Macro_path = None


# Time Logging
INCA_Start_time = None

#FIU Initial setting
FIU_setup = 1
FIU_used = False

#record condition
record_on = 0

#DefaultVariables
DefaultVars = []
DefaultCals = []

#DDT Client
hDDT = None
TargetECU_name = ""
TargetCAN_name = ""
TargetECU_DescFile = ""
TargetCAN_DescFile = ""
DDT_Status = False
step_libraries_1=None
#INCA_StoreValue Dictionary
INCA_StoreValue_Dict = {}

#Error handling
error_SL = None
SP = 0

#Stimuli
Stimuli_path = None

LED_Name = None
lis= None
data=None
randomList=[]
seq_Num=None
range1=None
range2=None
rowNum =None
clmNum=None
Result_loc=None

Voltage_path="()://Model Root/IOUserInterface/IO_PAR/Simulator/Power_Supply/Voltage_Out/Value"
CmdIgnSts='()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_10/CmdIgnSts/Value'

#CANOE 
canoe_inst=""

#Proxy
proxy_dict = {
"PROXI_Default":"30 30 30 30 30 30 35 36 33 39 30 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI1":"30 30 30 30 30 30 35 39 35 38 38 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI2":"30 30 30 30 30 30 33 33 34 32 35 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 00 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI3":"30 30 30 30 30 30 31 36 39 36 30 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI4":"30 30 30 30 30 30 32 32 32 30 31 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI5":"30 30 30 30 30 30 34 39 35 37 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI6":"30 30 30 30 30 30 31 39 32 38 36 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI7":"30 30 30 30 30 30 30 35 37 31 32 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI8":"30 30 30 30 30 30 31 36 35 30 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI9":"30 30 30 30 30 30 33 35 34 33 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI10":"30 30 30 30 30 30 36 30 34 36 31 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI11":"30 30 30 30 30 30 30 39 37 38 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI12":"30 30 30 30 30 30 32 38 36 38 38 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI13":"30 30 30 30 30 30 30 31 33 36 34 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
}

data={
      "left"  :  "2",
      "right" :  "1",
      "both"  :  "3",
      "crank" :  "5",
      "run"   :  "4"
      }

ExtNtc_SLML = { 
    "Turn_indicator" : "AnIn_4_LH",
    "Position_light" : "AnIn_3_LH",
    "Low_beam"       : "AnIn_1_LH",
    "High_beam"      : "AnIn_2_LH",
    "DRL"            : "AnIn_3_LH",
    "Signature_light": "AnIn_4_LH"
        }

ExtNtc_SLMR = { 
    "Turn_indicator" : "AnIn_4_RH",
    "Position_light" : "AnIn_3_RH",
    "Low_beam"       : "AnIn_1_RH",
    "High_beam"      : "AnIn_2_RH",
    "DRL"            : "AnIn_3_RH",
    "Signature_light": "AnIn_4_RH"
        }

LED_path_SLMR = {
    "Turn_indicator" : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED2_RH_Duty/In1",
    "Position_light" : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED6_RH_Duty/In1",
    "Low_beam"       : " ()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED1_RH_Duty/In1",
    "High_beam"      : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED5_RH_Duty/In1",
    "DRL"            : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED6_RH_Duty/In1",
    "Signature_light": "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED4_RH_Duty/In1"
    
    }
LED_path_SLML = {
    "Turn_indicator" : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED2_LH_Duty/In1",
    "Position_light" : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED6_LH_Duty/In1",
    "Low_beam"       : " ()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED1_LH_Duty/In1",
    "High_beam"      : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED5_LH_Duty/In1",
    "DRL"            : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED6_LH_Duty/In1",
    "Signature_light": "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED4_LH_Duty/In1"
    
    }

LED = {
       "Turn_indicator" : "LED2",
       "Position_light" : "LED6",
       "Low_beam"       : "LED1",
       "High_beam"      : "LED5",
       "DRL"            : "LED6",
       "Signature_light": "LED4",
       "Side_marker" : "HSD1",
       "Front_fog" : "HSD2"
       
       }

Ntc = {
       "AIN1" : "Analog_Input_1",
       "AIN2" : "Analog_Input_2",
       "AIN3" : "Analog_Input_3",
       "AIN4" : "Analog_Input_4",
       "AIN5" : "Analog_Input_5",
       "AIN6" : "Analog_Input_6",
       "AIN7" : "Analog_Input_7",
       "AIN8" : "Analog_Input_8",
       "AIN9" : "Analog_Input_9_Sns1",
       "AIN10" :"Analog_Input_10_Sns2"    
        }

HSD = {
          
       }



#________________________________

pre_tool_access2.py
#________________________________

import win32com.client
import time
# import ctypes
import globals
import step_libraries
from datetime import datetime
import common_fcns
import sys
import os


# 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"
#
# 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)





try:

    #______________________________________________________________________________

    globals.excel = win32com.client.Dispatch('Excel.application')
    globals.dir_path = os.path.dirname(os.path.realpath(sys.argv[0]))
    print(globals.dir_path)
    a = globals.dir_path.rfind("\\")
    print("vALUE OF A : ",a)
    fileLoc = globals.dir_path[:a]
    print(fileLoc)

    tl_path = r"C:\Users\AK001027556\Desktop\python_excel_script\Automation\DEMO Test\Test_Library_All_Feature_Activation.xlsx"
    Result_loc, globals.Report_loc = common_fcns.create_result(tl_path)
#_______________________
    print(Result_loc)
    print()
    print(globals.Report_loc)
#________________________
    globals.Result_file = common_fcns.openxl(globals.excel, Result_loc)
# _______________________
    print(globals.Result_file)

# ________________________

    now = datetime.now()
    # _______________________
    print(now)
    # ________________________


    dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
    globals.Result_file.Worksheets(1).Range("C1").Value = dt_string
    print("Opening TL - Completed")
    print("Result_loc", Result_loc, "Report_loc", globals.Report_loc, "Result_file", globals.Result_file)



    globals.Sheet_No = globals.Result_file.Sheets.Count
    # _______________________
    print(globals.Sheet_No)
    # ________________________
    #testsheet_no=1
    print("tl_operation_start")
    ##TL operation Start--------------------

    for testsheet_no in range(1, globals.Sheet_No + 1):
        globals.TL_sheet = globals.Result_file.Worksheets(testsheet_no)
        globals.excel.Visible = True
        SL_start = globals.TL_sheet.Range("C4")
        xl_endloc = "C" + str(globals.TL_sheet.Rows.Count)
        print("xl_endloc", xl_endloc)
        globals.SL_endrow = globals.TL_sheet.Range(xl_endloc).End(-4162).Row

        SL_endloc = "C" + str(globals.SL_endrow)
        print("SL_endloc", SL_endloc)
        SL_range = globals.TL_sheet.Range(SL_start, globals.TL_sheet.Range(SL_endloc))
        globals.SL = SL_start

        # #to update debug file and command window
        TL_starttime = time.time()
        # globals.debug_file.write("\n------------[START] - TL Execution-------------    ")

        print("\n------------[START] - TL Execution-------------")
        print("SL.Row", globals.SL.Row)
        print("SL_endrow", globals.SL_endrow)

        while globals.SL.Row <= globals.SL_endrow:
            #print ("globals.SL.Value ",globals.SL.Value)
            globals.rowNum = globals.SL.Row
            globals.clmNum = globals.SL_endrow
            print("SL.Row inside while loop", globals.SL.Row)
            print("SL_endrow inside while loop", globals.SL_endrow)
            print("SL :", globals.SL)
            print("SL Value : ", globals.SL.Value)
            if globals.SL.Value != None:
                try:
                    print("_______________________________________________________________")
                    print()
                    #to update debug file and command window
                    # globals.debug_file.write("\n" + str(globals.SL.Row) + "  " + str(globals.SL.Value) + "    ")
                    #eg: [1/40] - CD_SetKeyOn
                    print("[" + str(globals.SL.Row) + "/" + str(globals.SL_endrow) + "] - " + str(globals.SL.Value))
                    # if(str(globals.SL.Value)=="ECU_reset"):
                    #    common_fcns.post_condition()
                    #    #print("end_loc in main function",data)
                    #    common_fcns.Print_State()
                    # else:
                    globals.Result_file.Worksheets(testsheet_no)
                    #Getting the function name of the SL and calling it to execute
                    Call_SL = getattr(step_libraries, globals.SL.Value)
                    print("main call SL", Call_SL)
                    start_time = time.time()
                    # print("globals.SL.Row", globals.SL.Row, "globals.SL.Value", globals.SL.Value,
                    #       'globals.SL.Offset(1,2).Value', globals.SL.Offset(1, 2).Value, "globals.SL.Offset(1,3).Value",
                    #       globals.SL.Offset(1, 3).Value)

                    print("globals.SL.Row   ", globals.SL.Row)
                    print("Action : ", globals.SL.Value)
                    print('Message : ', globals.SL.Offset(1, 2).Value)
                    print("Signal : ", globals.SL.Offset(1, 3).Value)
                    print("Value : ", globals.SL.offset(1, 4).Value)
                    # Call_SL()
                    if callable(Call_SL):
                        result = Call_SL()
                        print(result)
                    else:
                        print("The attribute is not callable or does not exists.")
                    # print("SL called")
                    if globals.SL.Offset(1, 5).Value != "ERROR":
                        elapsed_time = time.time() - start_time
                        globals.SL.Offset(1, 8).Value = elapsed_time

                    print("_______________________________________________________________")

                #reading data and comparing results in tl:
                # common_fcns.result_calc()

                except Exception as log:
                    globals.SL.Offset(1, 8).Value = "Incorrect sequence name"
                    globals.SL.Offset(1, 5).Value = "ERROR"
                    globals.debug_file.write("ERROR    " + str(log))


            #wait for one second between SLs, delay time could be changed by TA_SetDelayBetweenSteps SL
            delay_time = 1
            time.sleep(globals.delay_time)
            globals.SL = globals.SL.Offset(2, 1)
        print("End of while in main")
        #commenting for now becuase only single sheet used

        testsheet_no = testsheet_no + 1

        globals.delay_time = 1

        # globals.debug_file.write("\n------------[END] - TL Execution-------------   \n ")
        print("\n------------[END] - TL Execution-------------")
        TL_endtime = time.time()
        TL_executiontime = TL_endtime - TL_starttime
        globals.TL_sheet.Range("I2").Value = TL_executiontime
    #-----------------------------------------------------------------------------------------------
    #to close the experiment and switch off IGN and Power supply after execution

    # if globals.Sheet_No == 1:
    #     func_call()
    # else:
    #     for testsheet_no in range(1,globals.Sheet_No):
    #         func_call()
    #         testsheet_no = testsheet_no + 1

    #only for demo
    time.sleep(5)
    ## TL operation end_____
    print("tl_operation_close")
    step_libraries.CD_Close()

    # if globals.Result_file != None:
    #     globals.Result_file.Save()
    #     globals.Result_file.Close()
    #     globals.Result_file = None
    # if globals.Macro != None:
    #     #globals.Macro1.Save()
    #     #globals.Macro1.Close()
    #     globals.excel.Workbooks("XLS_2_DDT.xlsm").Close(1)
    #     globals.Macro = None

    # globals.ProjObj.RemoveAll()
    # wait(120)

    # globals.ProjObj.Close()
    # AudObj.Quit()
    # time.sleep(2)
    # globals.excel.Application.Quit()
    #
    # globals.canoe_inst.stop_measurement()
    # globals.canoe_inst.quit()
    # caneo_setup = 0
    # globals.debug_file.close
    print("Process Completed")


except Exception as log:
    print()
    # if globals.Result_file != None:
    #     globals.Result_file.Save()
    #     globals.Result_file.Close()
    #
    # if AudObj != None:
    #     AudObj.Quit()
    #     time.sleep(2)
    #
    # if caneo_setup == 1:
    #     globals.canoe_inst.stop_measurement()
    #     globals.canoe_inst.quit()
    #     caneo_setup = 0
    # if globals.excel != None:
    #     globals.excel.Application.Quit()
    #
    # if globals.debug_file != None:
    #     globals.debug_file.close()
    #
    # ctypes.windll.user32.MessageBoxW(0, str(log) + ". Stopping Execution..", "Message", 0)
    #
    # if caneo_setup == 1:
    #     globals.canoe_inst.stop_measurement()
    #     globals.canoe_inst.quit()
    #     caneo_setup = 0
finally:
    print()
    # #globals.excel
    # globals.Result_file = None
    # globals.excel = None
    # #AUD
    # Inputs = None
    # globals.Step_libraries = None
    # globals.InputchildObj = None
    # globals.FIU_InputschildObj = None
    # PlatformLibObj = None
    # Platformtemplobj = None
    # PlatformObj = None
    # MyProjObj = None
    # globals.ProjObj = None
    # ProjsObj = None
    # time.sleep(5)
    # AudObj = None
    # #Error handling
    # globals.error_SL = None
#____________________________

step_libraries.py

#___________________________


# -*- coding: utf-8 -*-
"""
Created on Fri Feb  2 11:49:24 2024

@author: TN0G118148
"""
import globals
import time
import os
from pathlib import Path
import subprocess
import re
import common_fcns
import sys
import random
import itertools


#this function to check and get any error occured in AUD sequences
def CD_SL_Status():
    try:
        Sequence = globals.Step_libraries.SubBlocks.Item("CD_SL_Status")
        #ResObj0 = Sequence.Execute(random. randint(0, 5000),"")
        common_fcns.select_number()
        ResObj0 = Sequence.Execute(globals.seq_Num, "")

        Error_log = globals.InputchildObj.Item("Error")
        print("SL", globals.SL.Offset(1, 2).Value, Error_log.Value)
        if "Error" in Error_log.Value or "failed" in Error_log.Value:

            globals.SL.Offset(1, 5).Value = "ERROR"
            globals.SL.Offset(1, 6).Value = "   "
            globals.SL.Offset(1, 8).Value = "Error in step library execution "
            globals.debug_file.write("ERROR\n" + Error_log.Value)



        else:
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 6).Value = "   "
            #globals.SL.Offset(1,5).Value = "OK"
            globals.debug_file.write("PASSED")

        Error_log.Value = ""  #resetting the value
        ResObj0 = " "

    except Exception as log:
        print(log)
        globals.debug_file.write("ERROR    " + str(log))


def Update_err(log):
    globals.SL.Offset(1, 5).Value = "ERROR"
    globals.SL.Offset(1, 8).Value = str(log)
    globals.debug_file.write("ERROR    " + str(log))


def CD_OpenEnvironment():
    try:
        print("Loading Application", globals.Step_libraries)
        Sequence = globals.Step_libraries.SubBlocks.Item("CD_OpenEnvironment")
        #ResObj0 = Sequence.Execute(random. randint(0, 5000),"")
        common_fcns.select_number()
        ResObj0 = Sequence.Execute(globals.seq_Num, "")

        time.sleep(2)

        Sequence = globals.Step_libraries.SubBlocks.Item("CD_SL_Status")

        common_fcns.select_number()
        ResObj0 = Sequence.Execute(globals.seq_Num, "")

        Error_log = globals.InputchildObj.Item("Error")

        if "Error" in Error_log.Value:
            Error_log.Value = ""
            raise Exception("ERROR in Loading Application")
            print("ERROR in Loading Application")
        else:
            print("Loading Application - Completed")
    except:
        raise Exception("ERROR in Loading Application")


# used for demo purpose only
def CD_Close():
    try:
        Sequence = globals.Step_libraries.SubBlocks.Item("CD_Close")
        common_fcns.select_number()
        ResObj0 = Sequence.Execute(globals.seq_Num, "")

    except:
        print("ERROR")


def CD_CANCheckFrame():
    try:
        ActiveObj = globals.InputchildObj.item("Active")
        FrameName = globals.SL.Offset(1, 2).Value
        ActiveObj.Value = FrameName + '_' + FrameName + '_Enable'
        #ActiveObj.Value = globals.Modelroot[globals.SL.Offset(1,2).Value]                 

        Sequence = globals.Step_libraries.SubBlocks.Item("CD_CANCheckFrame")  # SL from AUD
        common_fcns.select_number()
        ResObj0 = Sequence.Execute(globals.seq_Num, "")

        CD_SL_Status()

    except Exception as log:
        Update_err(log)


def CD_CANUncheckFrame():
    try:
        ActiveObj = globals.InputchildObj.item("Active")
        FrameName = globals.SL.Offset(1, 2).Value
        ActiveObj.Value = FrameName + '_' + FrameName + '_Enable'
        #ActiveObj.Value = globals.Modelroot[globals.SL.Offset(1,2).Value]   

        Sequence = globals.Step_libraries.SubBlocks.Item("CD_CANUncheckFrame")  # SL from AUD
        common_fcns.select_number()
        ResObj0 = Sequence.Execute(globals.seq_Num, "")

        #ResObj0 = Sequence.Execute(data,"")
        CD_SL_Status()

    except Exception as log:
        Update_err(log)


#--------------------------------------CAN Read -----------------------------------------#
'''
    Version           : v0.1
    Function name     : can_read  
    Description       :
    Parameters used   :
    Created   by      :    Lakshmi Narayanan
    Created On        :
        
    Version          Date           Author         Change info   

'''


def can_read():
    return "Inside can Read function"
    # try:
    #     #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
    #     print("can_read inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
    #     sig_name = globals.SL.Offset(1, 3).Value
    #
    #     msg_name = globals.SL.Offset(1, 2).Value
    #
    #     # 'Platform()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_2/DRLCmd/Value'
    #     canpath = r"()://BusSystems/CAN/CAN/" + msg_name + "/RX/" + sig_name
    #     Sequ = globals.Step_libraries.SubBlocks.Item("CD_Canread")
    #
    #     keyObj = globals.InputchildObj.Item("can_path")
    #     keyObj.Value = canpath
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     #Update Log with AUD status
    #
    #     keyObj = globals.InputchildObj.Item("sig_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    # except Exception as log:
    #     Update_err(log)

    #--------------------------------End of CAN read function--------------------------------------#


#--------------------------------------CAN Write -----------------------------------------# 

'''
    Latest version    :
    Function name     : can_write
    Description       :
    Parameters used   :
    Created By        : Lakshmi Narayanan
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def can_write():
    return "Inside Can Write function"
    # try:
    #     #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
    #     print("can_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
    #     sig_name = globals.SL.Offset(1, 3).Value
    #     print("after sig")
    #     msg_name = globals.SL.Offset(1, 2).Value
    #     print("after msg")
    #     target_value = globals.SL.Offset(1, 4).Value
    #     print("after msg")
    #
    #     #canpath=r"()://BusSystems/CAN/CAN/"+msg_name+"/TX/"+ sig_name
    #     canpath = r"()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_2/" + sig_name + "/Value"
    #     canpath_sw = canpath + "_Switch"
    #     Sequ = globals.Step_libraries.SubBlocks.Item("CD_CanWrite")
    #
    #     keyObj = globals.InputchildObj.Item("can_path")
    #     keyObj.Value = canpath
    #     keyObj = globals.InputchildObj.Item("Target_value")
    #     keyObj.Value = target_value
    #     keyObj = globals.InputchildObj.Item("can_sw")
    #     keyObj.Value = canpath_sw
    #     lis = range(0, 5000)
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     keyObj = globals.InputchildObj.Item("current_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    #
    #
    # except Exception as log:
    #     Update_err(log)

    #--------------------------------End of CAN write function--------------------------------------#


#--------------------------------------KL30 OFF -----------------------------------------#   

'''
    Latest version    :
    Function name     : KL30_off
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def KL30_off():
    print("Kl30 is Running")
    return "Yes KL30 is returning something"
    # try:
    #     Sequ = globals.Step_libraries.SubBlocks.Item("KL30_off")
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     #ResObj0 = Sequ.Execute()
    #
    #     #Update Log with AUD status
    #
    #     keyObj = globals.InputchildObj.Item("current_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    #
    # except Exception as log:
    #     Update_err(log)


#--------------------------------End of KL30 OFF function--------------------------------------#         

#--------------------------------------KL30 ON -----------------------------------------#    

'''
    Latest version    :
    Function name     : KL30_on
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def KL30_on():
    print("KL30_on")
    # try:
    #     Sequ =globals.Step_libraries.SubBlocks.Item("KL30_on")
    #     target_value = globals.SL.Offset(1,4).Value
    #
    #
    #     keyObj = globals.InputchildObj.Item("KL30_Ip")
    #     keyObj.Value = globals.data[target_value]
    #
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num,"")
    #
    #
    #     #Update Log with AUD status
    #
    #
    #     keyObj = globals.InputchildObj.Item("current_value")
    #     globals.SL.Offset(1,7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1,5).Value !="ERROR" :
    #           common_fcns.result_calc()
    # except Exception as log:
    #     Update_err(log)


#--------------------------------End of KL30 ON function--------------------------------------#         


#--------------------------------------Ignition state -----------------------------------------# 

'''
    Latest version    :
    Function name     : ign_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def ign_write():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("Crank_mode inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)

        target_value = globals.SL.Offset(1, 4).Value

        Sequ = globals.Step_libraries.SubBlocks.Item("ign_write")

        keyObj = globals.InputchildObj.Item("can_path")
        keyObj.Value = globals.CmdIgnSts

        keyObj = globals.InputchildObj.Item("Target_value")
        keyObj.Value = globals.data[target_value]

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        #Update Log with AUD status

        keyObj = globals.InputchildObj.Item("current_value")
        globals.SL.Offset(1, 7).Value = keyObj.Value

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)
    #--------------------------------Ignition state function end--------------------------------------#


#--------------------------------------Message enable---------------------------------------------#

'''
    Latest version    :
    Function name     : msg_enable
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def msg_enable():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("can_enable inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
        sig_name = globals.SL.Offset(1, 3).Value
        print("after sig")
        msg_name = globals.SL.Offset(1, 2).Value
        print("after msg")
        target_value = globals.SL.Offset(1, 4).Value
        print("after msg")
        canpath = r"()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/MESSAGE_Enable/BCM_FD_2_en/Value"
        #canpath_sw =canpath+"_Switch"
        Sequ = globals.Step_libraries.SubBlocks.Item("msg_enable")

        keyObj = globals.InputchildObj.Item("can_path")
        keyObj.Value = canpath
        keyObj = globals.InputchildObj.Item("Target_value")
        keyObj.Value = target_value

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        #Update Log with AUD status

        keyObj = globals.InputchildObj.Item("current_value")
        globals.SL.Offset(1, 7).Value = keyObj.Value

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)


#--------------------------------------Message enable function end ---------------------------------------# 


#--------------------------------------Message Disable-----------------------------------------------------#       

'''
    Latest version    :
    Function name     : msg_disable
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def msg_disable():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("can_disable inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
        sig_name = globals.SL.Offset(1, 3).Value
        print("after sig")
        msg_name = globals.SL.Offset(1, 2).Value
        print("after msg")
        target_value = globals.SL.Offset(1, 4).Value
        print("after msg")
        canpath = r"()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/MESSAGE_Enable/BCM_FD_2_en/Value"
        #canpath_sw =canpath+"_Switch"
        Sequ = globals.Step_libraries.SubBlocks.Item("msg_disable")

        keyObj = globals.InputchildObj.Item("can_path")
        keyObj.Value = canpath
        keyObj = globals.InputchildObj.Item("Target_value")
        keyObj.Value = target_value

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        #Update Log with AUD status

        keyObj = globals.InputchildObj.Item("current_value")
        globals.SL.Offset(1, 7).Value = keyObj.Value

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)


#--------------------------------------Message disable function end ---------------------------------------# 

#--------------------------------------Voltage write-------------------------------------------------------#    

'''
    Latest version    :
    Function name     : vol_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def vol_write():
    return "Inside Voltage write function"
    # try:
    #     #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
    #     print("vol_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
    #     ''' sig_name = globals.SL.Offset(1,3).Value
    #     print("after sig")
    #     msg_name = globals.SL.Offset(1,2).Value
    #     print("after msg")'''
    #     target_value = globals.SL.Offset(1, 4).Value
    #     print("after msg")
    #     #canpath=r"()://BusSystems/CAN/CAN/"+msg_name+"/TX/"+ sig_name
    #     #canpath_sw =canpath+"_Switch"
    #     Sequ = globals.Step_libraries.SubBlocks.Item("Vol_Write")
    #
    #     keyObj = globals.InputchildObj.Item("can_path")
    #     keyObj.Value = globals.Voltage_path
    #     keyObj = globals.InputchildObj.Item("Target_value")
    #     keyObj.Value = target_value
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     #Update Log with AUD status
    #
    #     keyObj = globals.InputchildObj.Item("current_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    #
    # except Exception as log:
    #     Update_err(log)


#--------------------------------------Voltage write function end ---------------------------------------# 

#--------------------------------------Internal NTC write------------------------------------------------#

'''
    Latest version    :
    Function name     : InNtc_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def InNtc_write():
    return "Inside InNtc write function"
    # try:
    #     #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
    #     print("vol_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
    #     ''' sig_name = globals.SL.Offset(1,3).Value
    #     print("after sig")'''
    #     msg_name = globals.SL.Offset(1, 2).Value
    #     print("after msg")
    #     target_value = globals.SL.Offset(1, 4).Value
    #     #print("after msg")
    #     if msg_name == "SLMR":
    #         canpath = r"()://Model Root/IOUserInterface/IO_PAR/" + msg_name + "/Analog_Input/ECU_NTC_RH/Value"
    #     elif msg_name == "SLML":
    #         canpath = r"()://Model Root/IOUserInterface/IO_PAR/" + msg_name + "/Analog_Input/ECU_NTC_LH/Value"
    #
    #     #canpath_sw =canpath+"_Switch"
    #     Sequ = globals.Step_libraries.SubBlocks.Item("InNtc_write")
    #
    #     keyObj = globals.InputchildObj.Item("can_path")
    #     keyObj.Value = canpath
    #     keyObj = globals.InputchildObj.Item("Target_value")
    #     keyObj.Value = target_value
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     #Update Log with AUD status
    #
    #     keyObj = globals.InputchildObj.Item("current_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    #
    # except Exception as log:
    #     Update_err(log)

    #--------------------------------------Internal NTC write function end ---------------------------------------#


#--------------------------------------External NTC write -----------------------------------------------#

'''
    Latest version    :
    Function name     : ExtNtc_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def ExtNtc_write():
    return "Inside ExtNtc_ write function  "
    # try:
    #     #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
    #     print("vol_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
    #     ''' sig_name = globals.SL.Offset(1,3).Value
    #     print("after sig") '''
    #     msg_name = globals.SL.Offset(1, 2).Value
    #     Feature_name = globals.SL.Offset(1, 3).Value
    #     target_value = globals.SL.Offset(1, 4).Value
    #
    #     if (msg_name == "SLML"):
    #         AnIn_value = globals.ExtNtc_SLML[Feature_name]
    #
    #     elif (msg_name == "SLMR"):
    #         AnIn_value = globals.ExtNtc_SLMR[Feature_name]
    #
    #     #print("after msg")
    #     canpath = r"()://Model Root/IOUserInterface/IO_PAR/" + msg_name + "/Analog_Input/" + AnIn_value + "/Value"
    #     print(canpath)
    #     #canpath_sw =canpath+"_Switch"
    #     Sequ = globals.Step_libraries.SubBlocks.Item("ExtNtc_write")
    #
    #     keyObj = globals.InputchildObj.Item("can_path")
    #     keyObj.Value = canpath
    #     keyObj = globals.InputchildObj.Item("Target_value")
    #     keyObj.Value = target_value
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     #Update Log with AUD status
    #
    #     keyObj = globals.InputchildObj.Item("current_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    #
    # except Exception as log:
    #     Update_err(log)


#--------------------------------------External NTC write function end ---------------------------------------#

#--------------------------------------LED PWD Read-----------------------------------------------------------#    

'''
    Latest version    :
    Function name     : LED_read
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def LED_read():
    return "inside LED Read Function"
    # try:
    #     #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
    #     print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
    #
    #     feature_name = globals.SL.Offset(1, 3).Value
    #     msg_name = globals.SL.Offset(1, 2).Value
    #
    #     if (msg_name == "SLML"):
    #         LED_path = globals.LED_path_SLML[feature_name]
    #
    #     elif (msg_name == "SLMR"):
    #         LED_path = globals.LED_path_SLMR[feature_name]
    #
    #     Sequ = globals.Step_libraries.SubBlocks.Item("LED_read")
    #
    #     keyObj = globals.InputchildObj.Item("can_path")
    #     keyObj.Value = LED_path
    #     print("Value of LED path: ", keyObj.Value)
    #
    #     common_fcns.select_number()
    #     ResObj0 = Sequ.Execute(globals.seq_Num, "")
    #
    #     #Update Log with AUD status
    #
    #     keyObj = globals.InputchildObj.Item("Float_value")
    #     globals.SL.Offset(1, 7).Value = keyObj.Value
    #
    #     CD_SL_Status()
    #
    #     if globals.SL.Offset(1, 5).Value != "ERROR":
    #         common_fcns.result_calc()
    #
    # except Exception as log:
    #     Update_err(log)

    #--------------------------------------LED PWD Read function end ---------------------------------------#


#--------------------------------------Create fault-----------------------------------------------------# 

'''
    Latest version    :
    Function name     : set_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def set_FIU():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
        sig_name = globals.SL.Offset(1, 2).Value
        fault_type = globals.SL.Offset(1, 3).Value

        LED_Name = globals.LED[fault_type]
        #var="\\"

        FIU_path = sig_name + "\\LED\\" + LED_Name
        #FIU_path= sig_name+ "\" + LED_Name[:3] + "\" +LED_Name

        print("Value of FIU_path: ", FIU_path)
        Sequ = globals.Step_libraries.SubBlocks.Item("FIU_activate")

        keyObj = globals.InputchildObj.Item("SignalName")
        keyObj.Value = FIU_path

        keyObj = globals.InputchildObj.Item("Error_Category")
        keyObj.Value = globals.SL.Offset(1, 4).Value

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)

        #Update Log with AUD status
        CD_SL_Status()


#--------------------------------------Create fault function end ---------------------------------------#

#--------------------------------------Create fault-----------------------------------------------------# 

'''
    Latest version    :
    Function name     : set_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def set_HSD_FIU():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
        sig_name = globals.SL.Offset(1, 2).Value
        fault_type = globals.SL.Offset(1, 3).Value

        LED_Name = globals.LED[fault_type]
        var = "\\"

        FIU_path = sig_name + "\\HSD\\" + LED_Name
        #FIU_path= sig_name+ "\" + LED_Name[:3] + "\" +LED_Name

        print("Value of FIU_path: ", FIU_path)
        Sequ = globals.Step_libraries.SubBlocks.Item("FIU_activate")

        keyObj = globals.InputchildObj.Item("SignalName")
        keyObj.Value = FIU_path

        keyObj = globals.InputchildObj.Item("Error_Category")
        keyObj.Value = globals.SL.Offset(1, 4).Value

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)

        #Update Log with AUD status
        CD_SL_Status()


#--------------------------------------Create fault function end ---------------------------------------#


#--------------------------------------Create fault-----------------------------------------------------# 

'''
    Latest version    :
    Function name     : set_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def set_ntc_FIU():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
        ecu_name = globals.SL.Offset(1, 2).Value
        fault_type = globals.SL.Offset(1, 3).Value

        LED_Name = globals.Ntc[fault_type]

        FIU_path = ecu_name + "\\Analog_Input\\" + LED_Name

        print("Value of FIU_path: ", FIU_path)
        Sequ = globals.Step_libraries.SubBlocks.Item("FIU_activate")

        keyObj = globals.InputchildObj.Item("SignalName")
        keyObj.Value = FIU_path

        keyObj = globals.InputchildObj.Item("Error_Category")
        keyObj.Value = globals.SL.Offset(1, 4).Value

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)

        #Update Log with AUD status
        CD_SL_Status()


#--------------------------------------Create fault function end ---------------------------------------#

#--------------------------------------Remove fault-----------------------------------------------------#

'''
    Latest version    :
    Function name     : clear_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def clear_FIU():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)

        Sequ = globals.Step_libraries.SubBlocks.Item("FIU_deactivate")

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            common_fcns.result_calc()

    except Exception as log:
        Update_err(log)

        #Update Log with AUD status
        CD_SL_Status()


#--------------------------------------Remove fault function end ---------------------------------------#

#--------------------------------------Waiting time---------------------------------------------#  

'''
    Latest version    :
    Function name     : wait
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def wait():
    try:

        value = globals.SL.Offset(1, 4).Value
        print("after msg")
        Sequ = globals.Step_libraries.SubBlocks.Item("Wait")

        keyObj = globals.InputchildObj.Item("sig_value")
        keyObj.Value = value

        common_fcns.select_number()
        ResObj0 = Sequ.Execute(globals.seq_Num, "")

        #Update Log with AUD status
        CD_SL_Status()

        if globals.SL.Offset(1, 5).Value != "ERROR":
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"

        else:
            globals.SL.Offset(1, 6).Value = " "
            globals.SL.Offset(1, 5).Value = "Error"

    except Exception as log:
        Update_err(log)

    #--------------------------------------Wait time function end ---------------------------------------#


#--------------------------------------Modify variable using diagnsotic write-------------------------#

'''
    Latest version    :
    Function name     : set_proxy
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def set_proxy():
    try:

        para1 = globals.SL.Offset(1, 2).Value
        para2 = globals.SL.Offset(1, 4).Value
        print("the ecu:", para1, "the did:", para2)
        proxy_ip = globals.proxy_dict[para2]
        print("proxy_ip:", proxy_ip)
        resp = globals.canoe_inst.send_diag_request(para1, "2E 20 23 " + proxy_ip)
        print("the received byte:", resp)
        if resp[:2] == "6E":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Set_Proxy function end-------------------------#

#--------------------------------------Load default values to proxy-------------------------#

'''
    Latest version    :
    Function name     : clear_proxy
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def clear_proxy():
    try:

        para1 = globals.SL.Offset(1, 2).Value
        proxy_ip = globals.proxy_dict["PROXI_Default"]
        resp = globals.canoe_inst.send_diag_request(para1, "2E 20 23 " + proxy_ip)
        if resp[:2] == "6E":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Clear_Proxy function end-------------------------#

#--------------------------------------read proxy data using diagnsotic read-------------------------# 

'''
    Latest version    :
    Function name     : read_proxy
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def read_proxy():
    try:

        para1 = globals.SL.Offset(1, 2).Value
        resp = globals.canoe_inst.send_diag_request(para1, "22 20 24")
        if resp[:2] == "62":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Read_Proxy function end-------------------------#  

#--------------------------------------Clear DTC from history using diagnsotic Service-14-------------------------#  

'''
    Latest version    :
    Function name     : clear_dtc
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def clear_dtc():
    try:
        para1 = globals.SL.Offset(1, 2).Value
        resp = globals.canoe_inst.send_diag_request(para1, "14 FF FF FF")
        if resp[:2] == "54":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Clear dtc  function end-------------------------#

#--------------------------------------Check dtc status using diagnostic service-19-------------------------# 

'''
    Latest version    :
    Function name     : read_dtc
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def read_dtc():
    try:
        para1 = globals.SL.Offset(1, 2).Value
        dtc_no = globals.SL.Offset(1, 3).Value
        dtc_status = globals.SL.Offset(1, 4).Value
        resp = globals.canoe_inst.send_diag_request(para1, "19 02 0C")
        if resp[:2] == "59":
            dtc_no = resp.find(dtc_no)
            if dtc_status == "active":
                if dtc_no != -1:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "PASSED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp
                else:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "FAILED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp

            elif dtc_status == "inactive":
                if dtc_no == -1:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "PASSED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp
                else:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "FAILED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp
            else:
                print("ERROR")
                globals.SL.Offset(1, 6).Value = "ERROR"
                globals.SL.Offset(1, 5).Value = "NG"
                globals.SL.Offset(1, 7).Value = "Invalid parameter"

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            print("ERROR")
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "Missing parameter"


    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Read dtc function end-------------------------#   

#--------------------------------------End of Step libraries--------------------------#

#---------------------------------------History-------------------------------------#
'''  
Initial file version :1.0
Created on :
Created by : Lakshmi Narayanan
Modified by : Ramya B V             
    modified Date           Modified By            Purpose
    06/06/2024              Ramya B V               Modified functions by replacing if loop with Dictionaary to access data
Final version : 1.1
    
'''

#------------------------------------------------------------------------------------#