Following is my launch function.
from saleae import automation
import os
import time
import json
import argparse
def launch(path_to_exe, timeout, la_port):
“”"
Launch the Logic2 application.
Parameters:
path_to_exe (str): Path to the Logic2 executable.
timeout (int): Timeout for the launch in seconds.
la_port (int): Port to connect the Logic Analyzer.
Returns:
app: Logic2 application instance or None if launch fails.
"""
try:
app = automation.Manager.launch(application_path=path_to_exe, connect_timeout_seconds=timeout, grpc_channel_arguments=None, port=la_port)
time.sleep(2)
return app
except Exception as e:
print(f"Error launching Logic2 application: {e}")
return None
if name == “main”:
description_text = “A python script that contains various methods using Saleae’s Python API to perform Logic operations”
example_text = “Example usage: python script.py --start_capture --logic_ip 127.0.0.1 --logic_port 10430 …”
parser = argparse.ArgumentParser(description=description_text, epilog=example_text, formatter_class=argparse.RawDescriptionHelpFormatter)
# Apllication launch group
launch_group = parser.add_argument_group("Logic2 application launch", "Launch Logic2 application before data acquisition")
launch_group.add_argument('--launch', action='store_true', help='Launch Logic2 application')
launch_group.add_argument('--exe_path', default=None, type=str, help='Path where Logic2 exe is placed')
launch_group.add_argument('--timeout', default=10.0, type=float, help='Number of seconds to attempt to connect to gRPC server')
launch_group.add_argument('--la_port', default=10430, type=int, help='Port of the Logic Analyzer')
args = parser.parse_args()
if args.launch:
if not launch(args.exe_path, args.timeout, args.port):
exit()
Following is my perl code:
sub StartLogic_exe {
my ($path, $timeout, $port) = @_;
$path //= undef;
$timeout //= 10.0;
$port //= 10430;
my $pycli = "Path/to/python.exe";
my $py_script = "../tools/logic2/logic2manager.py";
my $args = "--launch --exe_path $path --timeout $timeout --port $port";
my $cmd = "$pycli $py_script $args";
my $out1 = System_Command($cmd, "log", 1);
LogEntry("Result: ".$out1);
Now the thing is I cannot return ‘app’ a launch instance to my perl code and further use it inside my perl code.
May be I should launch Logic 2 process the following way and later use connect():
subprocess.Popen([‘C:\Program Files\Logic\Logic.exe’, ‘–automation’, ‘–automationPort’, ‘10429’], shell=True, creationflags=subprocess.CREATE_NEW_CONSOLE)