ppannuto / python-saleae

Python library to control a Saleae Logic Analyzer
Apache License 2.0
124 stars 55 forks source link

Saleae Init function doesn't take logic_path variable #82

Closed CoreyWilliamson closed 2 years ago

CoreyWilliamson commented 2 years ago

I'm trying to use the standalone version of the Saleae logic SW on Windows and am running into the issue where I can't get the path to the stand alone software passed to the "launch_logic" function in the Saleae class __init__ function. I found #58 which seemed to address the issue but it looks like the logic path doesn't quite make it from the Saleae() init function to the "launch_logic" function.

    def __init__(self, host='localhost', port=10429, quiet=False, args=None):
        self._to_send = []
        self.sample_rates = None
        self.connected_devices = None

        try:
            self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self._s.connect((host, port))
        except ConnectionRefusedError:
            log.info("Could not connect to Logic software, attempting to launch it now")
            Saleae.launch_logic(quiet=quiet, host=host, port=port, args=args)
    def launch_logic(timeout=15, quiet=False, host='localhost', port=10429, logic_path=None, args=None):
        '''Attempts to open Saleae Logic software
        :param timeout: Time in seconds to wait for the Logic software to launch
        :param quiet: Silence terminal output from Logic (Linux only, otherwise ignored)
        :param logic_path:
            Full path to Logic executable. If not provided, attempt to find Logic
            at a standard location.
        :param args:
            Optional argument string to pass to Logic executable
            Examples:
            -disablepopups (suppress notifications)
            -uploaderrors (accept the upload errors dialog and close it)
        :returns True if the Logic software launched and accepted a socket connection within the timeout
        '''
        if platform.system() == 'Darwin':
            logic_path = logic_path or '/Applications/Logic.app'
            if args is not None:
                logic_path += ' --args {}'.format(args)
            if os.system('open {}'.format(logic_path)) != 0:
                raise OSError("Failed to open Logic software")
        elif platform.system() == 'Linux':
            if quiet:
                mode = ' > /dev/null 2>&1 &'
            else:
                mode = ' &'
            arg_string = ''
            if args is not None:
                arg_string = ' ' + args
            if logic_path is not None:
                os.system(logic_path + arg_string + mode)
            elif PY2K:
                log.warn("PY2K support limited. If `Logic` is not on your PATH it will not open.")
                os.system("Logic" + arg_string + mode)
            else:
                path = shutil.which('Logic')
                if path is None:
                    raise OSError("Cannot find Logic software. Is 'Logic' in your PATH?")
                os.system(path + arg_string + mode)
        elif platform.system() == 'Windows':
            if logic_path is not None:
                p = logic_path
            else:
                p = os.path.join("C:", os.sep, "Program Files", "Saleae Inc", "Logic.exe")
                if not os.path.exists(p):
                    p = os.path.join("C:", os.sep, "Program Files", "Saleae LLC", "Logic.exe")

            popen_args = [p]
            if args is not None:
                popen_args.extend(args.split())

            subprocess.Popen(popen_args)

I think I'm missing something where or does the __init__ function need a variable "logic_path" which can be passed along to "launch_logic"?

ppannuto commented 2 years ago

launch_logic is a static method, i.e. you don't need an instance of the Saleae class to call it. Launching on class construction is a convenience mechanism for the common-case. If you need a custom launch, simply call launch_logic before instantiating Saleae class, and the library will connect to the already-running Logic instance.

Feel free to re-open with more details / info if that doesn't address your needs.