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 p.loadA2lFile(r"C:\Repos\sumac\Test试\G001_1_GTT_SinX3\G001_1_GTT.a2l") print("Connecting to ECU...") p.connectToXcpSlaveCanClassic('') # Empty string => Use first found physical device print("Setup logging") # Setup what to log, how fast and in what format # Contains periods in seconds, sorted xcp_periods = p.getAvailableXcpSamplePeriods() 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 = [ ('CpuLoad_Total', slowest), ('PcbTemp_T', fastest), ('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("CpuLoad_Total") print("Last value:", value) # 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.disconnectFromXcpSlave()