pyvisa / pyvisa-py

A pure python PyVISA backend
https://pyvisa-py.readthedocs.io
MIT License
282 stars 120 forks source link

fix crash on Windows when opening multiple devices #244

Closed itayperl closed 4 years ago

itayperl commented 4 years ago

For some reason, PyUSB on Windows is unable to read the serial_number attribute from a device that's already open in another pyusb instance, and crashes with a cryptic "device has no langid" exception when it's accessed.

When a USB resource is opened, PyVISA-py tries to find the device by serial number. If there's already another open device, its serial_number attribute will be accessed in this search, triggering the langid exception.

With this fix we will silently ignore a device when accessing a search attribute on it raises an exception.

MatthieuDartiailh commented 4 years ago

That is bound to confuse people a lot ! Could you add something in the documentation about it.

itayperl commented 4 years ago

Hmm, what do you find confusing here? It feels reasonable to me to skip devices that we are unable to query.

The only thing that is a bit confusing to me is that on Linux ResourceManager.list_resources() returns all connected devices, whereas on Windows it only returns devices that are not already open (that's already the behavior today, not affected by this PR).

MatthieuDartiailh commented 4 years ago

I am pretty that some people will report that their device is not detected on Windows and as a consequence Ithink it is worth improving the documentation to mention that caveat. I am fine with your implementation.

MatthieuDartiailh commented 4 years ago

But we may want to log the fact that specific instrument could not be accessed and if on windows suggest one possible reason.

itayperl commented 4 years ago

I added a note about list_resources - is there any other scenario that should be documented? I don't think we need another log for this case - there's already a warning log here for this failure in list_resources.

MatthieuDartiailh commented 4 years ago

My bad I forgot about that warning.

MatthieuDartiailh commented 4 years ago

238 has the fix for the format issue. If you are fine waiting I will try to push https://github.com/pyvisa/pyvisa/pull/525 and #238 through next week. If you need the fix on master faster let me know.

itayperl commented 4 years ago

No rush! I'll use my fork in the meantime. Thanks!

MatthieuDartiailh commented 4 years ago

@itayperl can you address the conflicts ?

itayperl commented 4 years ago

@itayperl can you address the conflicts ?

Done.

MatthieuDartiailh commented 4 years ago

bors r+

bors[bot] commented 4 years ago

Build succeeded: