Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pylink/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class JLink(object):
# so we base this number on that. Other models have 80 bytes.
MAX_BUF_SIZE = 336

# Override to false, used in targets not requiring connection
target_connection_required = True

# Maximum number of CPU registers.
MAX_NUM_CPU_REGISTERS = 256

Expand Down Expand Up @@ -167,7 +170,7 @@ def wrapper(self, *args, **kwargs):
Raises:
JLinkException: if the JLink's target is not connected.
"""
if not self.target_connected():
if (not self.target_connected()) and self.target_connection_required:
raise errors.JLinkException('Target is not connected.')
return func(self, *args, **kwargs)
return wrapper
Expand Down
9 changes: 3 additions & 6 deletions pylink/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ def find_library_windows(cls):

# Find all the versioned J-Link directories.
ds = filter(lambda x: x.startswith('JLink'), os.listdir(dir_path))
for jlink_dir in ds:
# The DLL always has the same name, so if it is found, just
# return it.
lib_path = os.path.join(dir_path, jlink_dir, dll)
if os.path.isfile(lib_path):
yield lib_path
lib_path = os.path.join(dir_path, ds[-1], dll) # use the latest jlink DLL (ds[-1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this won't necessarily return the newest version. os.listdir returns the directories in the order specified by the underlying filesystem. In some cases, this is just the latest directory created, which is generally the latest installed version, but can be an older version if someone switches between versions often.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree... However I am not sure I have the bandwidth and the environment to test it also on Linux and Mac.
A logic behavior would be to make the user either to pic a specific version and as default, if nothing is specified, use the latest.

Maybe somebody can improve this and provide implementation for Mac and Linux?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, I like the idea of that behaviour. The reason why I said that listdir might not be the best approach is that the order isn't guaranteed, so if we say that we always return the latest one, then we have to do some sorting in addition to listdir. To sort properly, we'll need to handle the different file naming conventions that have been had over time.

if os.path.isfile(lib_path):
yield lib_path

@classmethod
def find_library_linux(cls):
Expand Down