Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB JLink selection by Serial Number #151

Open
kriscrisu opened this issue Nov 18, 2022 · 2 comments
Open

USB JLink selection by Serial Number #151

kriscrisu opened this issue Nov 18, 2022 · 2 comments

Comments

@kriscrisu
Copy link

kriscrisu commented Nov 18, 2022

Hello,

I'm porting to PyLink an old Python script that used the JLINKARM.dll directly. Sometimes J-Link selection by serial number is important, the script should report an error and quit if the specific J-Link it should use does not seem to be connected. I thought that could be done at JLink object creation time, but that is not happening. The serial_no argument passed to JLink.__init__() seems to be discarded, if a J-Link with a different serial number is connected to the PC it will be used with no warning whatsoever.

Environment

Windows 10 Pro Version 21H2, Python 2.7.18, JLink 7.20a and PyLink 0.14.3

Steps to reproduce

1. import pylink
2. dbg = pylink.jlink.JLink(serial_no=600115433)
3. dbg.num_connected_emulators()
Output: 1
4. dbg.connected_emulators()
Output: [JLinkConnectInfo(J-Link PLUS <Serial No. 600115434>, Conn. USB)]
5. dbg.open()
6. dbg.serial_number
Output: 600115434

Right now it looks like the only method to actually select a J-Link by serial number is passing the serial_no parameter to the JLink.open() function. For example, if at step 5 something like the following is used:

5*. dbg.open(serial_no=600115433)

an error will be reported and my script will be able to exit with an error code as expected.

@hkpeprah
Copy link
Contributor

Looks like the passed parameter for the constructor is only used for the context manager, and not for the open(). I think maybe we could document this better, or possibly we should retain this value when .open() is called as well. What do you think would be the better option for your use case? I could see the argument to be made that if the argument passed to the constructor is different than the one passed to .open() that the latter should take priority, so it could be a simple change where we check is None, and then set it to the __serial_no.

@kriscrisu
Copy link
Author

I think you should either remove the serial number from the parameter list passed to the constructor or use it when .open() is called without any arguments. From a user's perspective it does not make much sense to pass a J-Link serial number to the object constructor if this number is not going to be used in subsequent user operations. Then like you said, if a different serial number is passed to the .open() function the latter should take precedence, that makes sense.
As it is right now, this feature is rather confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants