示例#1
0
    def find_serial_ports():
        serial_list = []

        if is_win():
            from winreg import OpenKey, HKEY_LOCAL_MACHINE, EnumValue

            def enumerate_values(key):
                i = 0
                while True:
                    try:
                        yield EnumValue(key, i)
                        i += 1
                    except WindowsError:
                        break

            with OpenKey(HKEY_LOCAL_MACHINE,
                         'HARDWARE\\DEVICEMAP\\SERIALCOMM') as key:
                for value in enumerate_values(key):
                    if re.match(r'COM\d+', value[1]):
                        serial_list.append(value[1])

        elif is_linux():
            for value in os.listdir('/dev/'):
                if re.match(r'tty(USB|ACM)\d+', value):
                    serial_list.append(os.path.join('/', 'dev', value))
        else:
            pass

        return serial_list
示例#2
0
def get_default_jlink_path():
    if is_win():
        from winreg import OpenKey, QueryValueEx, EnumKey, KEY_READ, HKEY_CURRENT_USER

        def enumerate_keys(key):
            i = 0
            while True:
                try:
                    yield EnumKey(key, i)
                    i += 1
                except WindowsError:
                    break

        jlink_root_path = 'Software\SEGGER\J-Link'
        jlink_install_path = ''

        with OpenKey(HKEY_CURRENT_USER, jlink_root_path, 0,
                     KEY_READ) as registry:
            for subdir in enumerate_keys(registry):
                with OpenKey(registry, subdir) as install_path:
                    path, _ = QueryValueEx(install_path, "InstallPath")

                    # check that JLinkExe is actually installed in path
                    binary = os.path.join(path, JLINK_EXE)
                    if os.path.isfile(binary) and os.access(binary, os.X_OK):
                        jlink_install_path = path

        return jlink_install_path

    elif is_linux():
        for path in os.environ["PATH"].split(os.pathsep):
            binary = os.path.join(path, JLINK_EXE)
            if os.path.isfile(binary) and os.access(binary, os.X_OK):
                return path

        return ''

    else:
        return ''
示例#3
0
import os
import socket
import tempfile
import subprocess
import sys
from configparser import ConfigParser
from shlex import split

from api.application import Application, ApplicationError
from api.utils import SDK_ROOT, is_linux, is_win

if is_win():
    CLI_PROGRAMMER_DEFAULT_PATH = os.path.join(SDK_ROOT,
                                               'binaries/cli_programmer.exe')
elif is_linux():
    CLI_PROGRAMMER_DEFAULT_PATH = os.path.join(SDK_ROOT,
                                               'binaries/cli_programmer')
else:
    CLI_PROGRAMMER_DEFAULT_PATH = ''

jlink_gdb_server_instance = None


def start_jlink_gdb_server(cmd_str, port):
    global jlink_gdb_server_instance
    if jlink_gdb_server_instance is not None or cmd_str is None:
        # Already started or no command
        return

    # Check that something is listening on the same port