Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import os, os.path, signal, subprocess, collections, csv, glob, time, socket
- from saleae import automation
- # Configuration
- localCaptureDir = "D:\\Captures"
- channel_names = {
- 0: 'EFI to ASC',
- 1: 'ASC to EFI',
- 4: 'ASC to AT',
- 5: 'AT to ASC',
- }
- channel_analyzers = {
- 0: 'Async Serial',
- 1: 'Async Serial',
- 4: 'Async Serial',
- 5: 'Async Serial'
- }
- analyzer_config_template = {
- 'Bit Rate (Bits/s)': 9600,
- 'Bits per Frame': '8 Bits per Transfer (Standard)',
- 'Stop Bits': '1 Stop Bit (Standard)',
- 'Parity Bit': 'No Parity Bit (Standard)',
- 'Significant Bit': 'Least Significant Bit Sent First (Standard)',
- 'Signal inversion': 'Inverted',
- 'Mode': 'Normal'
- }
- logic2_env = os.environ.copy()
- logic2_env["ENABLE_AUTOMATION"] = "1"
- logic2_process = -1
- manager = -1
- # Functions
- # Start Logic 2 Application
- def startLogic2():
- # Start the Logic 2 application on port 10430
- global logic2_process
- logic2_process = subprocess.Popen(["C:\Program Files\Logic\Logic.exe","--automation"], env=logic2_env)
- print("Logic 2 process id:", logic2_process.pid, "\n")
- connection_timeout = time.perf_counter()
- while True:
- try:
- with socket.create_connection(("localhost", 10430), timeout=5.0):
- break
- except OSError as ex:
- time.sleep(0.01)
- if time.perf_counter() - connection_timeout >= 5.0:
- raise TimeoutError('Logic 2 Application did not start or did not accept connections') from ex
- # Stop Logic 2 Application
- def stopLogic2():
- global logic2_process
- logic2_process.terminate()
- logic2_process.wait()
- # Main program starts here
- # Iterate over each found capture file
- for file in glob.glob(localCaptureDir + "\\*.sal"):
- startLogic2()
- manager = automation.Manager(port=10430)
- filename = file.replace(localCaptureDir + "\\", "").replace(".sal", "")
- print("Extracting bytes from " + filename + "...")
- # Open capture file
- capture = manager.load_capture(localCaptureDir + "\\" + filename + ".sal")
- # Clear all analyzers
- analyzers = []
- # Add analyzers
- for channel in channel_analyzers.keys():
- analyzer_config = analyzer_config_template
- analyzer_config['Input Channel'] = channel
- analyzers.append(
- capture.add_analyzer(
- name = channel_analyzers[channel],
- label = channel_names[channel],
- settings = analyzer_config
- )
- )
- # Export data
- capture.export_data_table(
- filepath = localCaptureDir + "\\Exports\\" + filename + ".csv",
- analyzers = analyzers,
- radix = automation.RadixType.HEXADECIMAL
- )
- # Clear all analyzers and close file
- # for analyzer in analyzers: capture.remove_analyzer(analyzer)
- capture.close()
- # Close the connection and the Logic 2 application
- manager.close()
- stopLogic2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement