-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
expand info/debug/warning msgs if USB device serial_number
not readable
#423
base: main
Are you sure you want to change the base?
Conversation
Examples of messages running the code import logging
import pyvisa
logging.basicConfig(level=logging.DEBUG)
rm = pyvisa.ResourceManager("@py")
rm.list_resources() on Linux with permissions /dev/usb/001/016 not set correctly (I also have a USB RAW device on my system, so you can see the modified message for that as well).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling this! Left some notes, will test the code in a bit.
Please note I do not have authority over the code, @MatthieuDartiailh has the last word. My comments are suggestions at best.
@@ -336,7 +372,7 @@ def list_resources() -> List[str]: | |||
serial = dev.serial_number | |||
except (NotImplementedError, ValueError, usb.USBError): | |||
msg = ( | |||
"Found a device whose serial number cannot be read." | |||
"Found a USB RAW device whose serial number cannot be read." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we run into the same permissions issue here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do. I thought pyvisa didn't care about RAW devices (because it doesn't control them), but I realize now that assumption may be incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USB RAW are weird because there are supported by NI but are not part of the IVI specs. If we can provide more information we should though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I observed in pyvisa issue Linux host and getting permissions to talk to a USBTMC device
USBTMC devices show up as both /dev/usbtmcN and /dev/bus/usb/NNN/NNN
Both instances need to have suitable permissions for pyvisa with pyvisa-py to be able to communicate
If only the /dev/usbtmcN has permissions then you get WARNING Found a device whose serial number cannot be read
pyvisa_py/usb.py
Outdated
logger.warning( | ||
"User does not have permission to %s %s, so the above USB INSTR" | ||
" device cannot be used by pyvisa; see" | ||
" https://pyvisa.readthedocs.io/projects/pyvisa-py/en/latest/faq.html" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should link to the specific anchor once docs are updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only issue with that is we need to keep the two in sync; a change in the docs will necessitate a change in the code. That could be annoying for a maintainer, so I left it out. But if that's what you want, I'm happy add the anchor to the link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt that docs organisation will change drastically enough to make this a big issue, and since we're going to the trouble of linking we might as well link to the exact spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a direct link would be better. Anything that can reduce the number of obscure bug reports is something I am happy to include.
Really appreciate all your helpful feedback, @arr-ee . I will push updates according to your comments ASAP, and hopefully have a first pass at adding to the docs that can be reviewed as well. I want to re-iterate how helpful the feedback you gave is, not really being aware of all the ins-and-outs of pyvisa & pyvisa-py (like code organization in the usbutils module; wouldn't have thought of that as an outsider). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Once the minor requested changes are in I will merge.
pyvisa_py/usb.py
Outdated
logger.warning( | ||
"User does not have permission to %s %s, so the above USB INSTR" | ||
" device cannot be used by pyvisa; see" | ||
" https://pyvisa.readthedocs.io/projects/pyvisa-py/en/latest/faq.html" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a direct link would be better. Anything that can reduce the number of obscure bug reports is something I am happy to include.
@@ -336,7 +372,7 @@ def list_resources() -> List[str]: | |||
serial = dev.serial_number | |||
except (NotImplementedError, ValueError, usb.USBError): | |||
msg = ( | |||
"Found a device whose serial number cannot be read." | |||
"Found a USB RAW device whose serial number cannot be read." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USB RAW are weird because there are supported by NI but are not part of the IVI specs. If we can provide more information we should though.
@jllanfranchi any idea when you will be able to address the comments ? |
Friendly ping @jllanfranchi |
…readable if INSTR USB device, - say that device is USB INSTR that failed in warning message - catch exception - debug message with traceback if logging level is DEBUG - info message 1-line error summary if logging level is INFO - if path f"/dev/bus/usb/{dev.bus:03d}/{dev.address:03d}" exists, check permissions on that file & refer to FAQ link (known issue on Linux) if RAW USB device, - say that device is USB RAW that failed in warning message
f7a08a7
to
da964f3
Compare
I took the liberty to rebase and address the log and the platform gating. @arr-ee we have no entry in the FAQ for the permissions but we do have one in the installation. Would you have time to look at how to improve it ? in particular it may make sense to include @DavidLutton latest comment somewhere. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #423 +/- ##
==========================================
- Coverage 24.47% 24.45% -0.03%
==========================================
Files 23 23
Lines 3485 3505 +20
Branches 398 405 +7
==========================================
+ Hits 853 857 +4
- Misses 2627 2643 +16
Partials 5 5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
if INSTR USB device,
if RAW USB device,
I will work on documentation fixes now, but wanted to get this in front of you for feedback in the meantime, @arr-ee (et al.).
black . && isort -c . && flake8
withnoerrors black & isort OK; flake8 doesn't like a few lines' lengths