import Pass as p import time as t if __name__ == '__main__': # Note that A2L filename needs to be a raw string if it contains backslash # Empty string for device to connect through => Use first found physical device p.addXcpEcu("ecu", r"C:\Repos\sumac\Test\G001_1_GTT_SinX3\G001_1_GTT_stripped_Ascii_2dArray.a2l", p.XcpConnectionType.XCP_CAN_CLASSIC, "") print("Connecting to ECU...") p.connectToXcpEcus() print("Setup logging") # Setup what to log, how fast and in what format # Contains periods in seconds, sorted xcp_periods = p.getAvailableXcpDaqListPeriods("ecu") fastest = xcp_periods[0] # First element is the fastest period slowest = xcp_periods[-1] # Last is the slowest print("Fastest task at every", fastest, "seconds, slowest at every", slowest, "second") pre_buffer_sz = 1.0 # Additional seconds to log, before 'startLogging' is called # # Variables to log, given as a Python list that contains tuples of string and double # xcp_vars = [ ('ecu.CpuLoad_Total', slowest), ('ecu.PcbTemp_T', fastest), ('ecu.KL15_U', slowest) ] dbc_vars = [] p.startDaq(xcp_vars, p.TimestampSource.TRANSPORT_PROTOCOL, dbc_vars) # Alt. SLAVE_WHEN_AVAILABLE # With Data acquisition started the getLatestSample service is available. It returns # the latest received sample for a signal. value = p.getLatestMeasurementSample("ecu.CpuLoad_Total") print(f"Latest value: {value[0]} with timestamp {value[1]}") # Activating recording with 1 second pre-trigger. That means that 1 second of data before startRecording() is # called will be in the log. This is useful to see what's causing an event without logging the entire time, i.e. # activate recording with a suitable pretrigger, use getLatestMeasurementSample() in a loop to detect the event and then # startRecording() p.activateRecording(p.RecorderType.MDF4_2, 1.0) # Actually start recording data print("Start recording data") p.startRecording() # Sleep while logging # This is only for pausing the Python script sleep_time = 1.0 print("Sleep %.01f seconds" % sleep_time) t.sleep(sleep_time) # Stop and store p.stopRecording() p.saveRecording(r"C:\tmp\unnamed") p.stopDaq() print("Disconnect") p.disconnectFromAllXcpEcus()