Advertisement
Guest User

Logic 2 Automation Process Multiple Captures

a guest
Jul 25th, 2022
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.98 KB | None | 0 0
  1. # Imports
  2. import os, os.path, signal, subprocess, collections, csv, glob, time, socket
  3. from saleae import automation
  4.  
  5. # Configuration
  6. localCaptureDir = "D:\\Captures"
  7.  
  8. channel_names = {
  9.     0: 'EFI to ASC',
  10.     1: 'ASC to EFI',
  11.     4: 'ASC to AT',
  12.     5: 'AT to ASC',
  13. }
  14.  
  15. channel_analyzers = {
  16.     0: 'Async Serial',
  17.     1: 'Async Serial',
  18.     4: 'Async Serial',
  19.     5: 'Async Serial'
  20. }
  21.  
  22. analyzer_config_template = {
  23.     'Bit Rate (Bits/s)': 9600,
  24.     'Bits per Frame': '8 Bits per Transfer (Standard)',
  25.     'Stop Bits': '1 Stop Bit (Standard)',
  26.     'Parity Bit': 'No Parity Bit (Standard)',
  27.     'Significant Bit': 'Least Significant Bit Sent First (Standard)',
  28.     'Signal inversion': 'Inverted',
  29.     'Mode': 'Normal'
  30. }
  31.  
  32. logic2_env = os.environ.copy()
  33. logic2_env["ENABLE_AUTOMATION"] = "1"
  34. logic2_process = -1
  35. manager = -1
  36.  
  37. # Functions
  38. # Start Logic 2 Application
  39. def startLogic2():
  40.     # Start the Logic 2 application on port 10430
  41.     global logic2_process
  42.     logic2_process = subprocess.Popen(["C:\Program Files\Logic\Logic.exe","--automation"], env=logic2_env)
  43.     print("Logic 2 process id:", logic2_process.pid, "\n")
  44.     connection_timeout = time.perf_counter()
  45.     while True:
  46.         try:
  47.             with socket.create_connection(("localhost", 10430), timeout=5.0):
  48.                 break
  49.         except OSError as ex:
  50.             time.sleep(0.01)
  51.             if time.perf_counter() - connection_timeout >= 5.0:
  52.                 raise TimeoutError('Logic 2 Application did not start or did not accept connections') from ex
  53.    
  54. # Stop Logic 2 Application
  55. def stopLogic2():
  56.     global logic2_process
  57.     logic2_process.terminate()
  58.     logic2_process.wait()
  59.  
  60. # Main program starts here
  61.  
  62. # Iterate over each found capture file
  63. for file in glob.glob(localCaptureDir + "\\*.sal"):
  64.     startLogic2()
  65.     manager = automation.Manager(port=10430)
  66.     filename = file.replace(localCaptureDir + "\\", "").replace(".sal", "")
  67.     print("Extracting bytes from " + filename + "...")
  68.  
  69.     # Open capture file
  70.     capture = manager.load_capture(localCaptureDir + "\\" + filename + ".sal")
  71.  
  72.     # Clear all analyzers
  73.     analyzers = []
  74.  
  75.     # Add analyzers
  76.     for channel in channel_analyzers.keys():
  77.         analyzer_config = analyzer_config_template
  78.         analyzer_config['Input Channel'] = channel
  79.         analyzers.append(
  80.             capture.add_analyzer(
  81.                 name = channel_analyzers[channel],
  82.                 label = channel_names[channel],
  83.                 settings = analyzer_config
  84.             )
  85.         )
  86.  
  87.     # Export data
  88.     capture.export_data_table(
  89.         filepath = localCaptureDir + "\\Exports\\" + filename + ".csv",
  90.         analyzers = analyzers,
  91.         radix = automation.RadixType.HEXADECIMAL
  92.     )
  93.  
  94.     # Clear all analyzers and close file
  95.     # for analyzer in analyzers: capture.remove_analyzer(analyzer)
  96.     capture.close()
  97.  
  98.     # Close the connection and the Logic 2 application
  99.     manager.close()
  100.     stopLogic2()
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement