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

bdDetect: Enrich USB serial data with info about USB device #15764

Merged
merged 17 commits into from Nov 23, 2023

Conversation

LeonarddeR
Copy link
Collaborator

@LeonarddeR LeonarddeR commented Nov 9, 2023

Link to issue number:

Blocks #15693

Summary of the issue:

Many braille displays use a serial converter from FTDI with VID 0x403" and PID 0x6001. Given the weird nature of Albatross devices not being able to identify themselves on request, the Albatross driver is currently a disturbing factor in automatic detection.

Description of user facing changes

None.

Description of development approach

  1. This pr enriches information for serial ports in bdDetect. The _DeviceInfoFetcher class now has an extra autoprop usbComPorts that bundles com port info with USB metadata. If all works as expected, the Albatross driver will be able to limit itself to Albatross devices only after this pr by using the busReportedDeviceDescription dictionary entry.
  2. Removed duplicated code from hwPortUtils

Testing strategy:

Testing with Albatross from @burmancomp would be appreciated.
It can be tested using bdDetect.getConnectedUsbDevicesForDriver("albatross"). This should yield device matches with details about the underlying USB device.

Known issues with pull request:

None known

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@burmancomp
Copy link
Contributor

Yes, I am about to test this likely tomorrow.

@burmancomp
Copy link
Contributor

Portable version of nvda_snapshot_pr15764-29937,d9a7c5be.exe, python console:

next(bdDetect.getConnectedUsbDevicesForDriver("albatross"))
DeviceMatch(type='serial', id='VID_0403&PID_6001', port='COM5', deviceInfo={'hardwareID': 'USB\VID_0403&PID_6001&REV_0400', 'port': 'COM5', 'usbID': 'VID_0403&PID_6001', 'friendlyName': 'USB Serial Port (COM5)', 'devicePath': '\\?\usb#vid_0403&pid_6001#tmboijcd#{a5dcbf10-6530-11d2-901f-00c04fb951ed}', 'deviceDescription': 'USB Serial Converter'})
Let me know did I test correctly?

@LeonarddeR
Copy link
Collaborator Author

Yes, this is correct. I need to expand hwPortUtils but I at least know how.
Could you by any chance do the following?

  1. Open Device Manager
  2. Open ports (com & lpt)
  3. Select your com5 port
  4. Look up de device details and in there, the Bus reported device description
    I assume that's USB Serial Port, right?

@burmancomp
Copy link
Contributor

Yes, it is "USB Serial Port", and usb serial converter bus reported device description is "Albatross Braille Display".

Let me know if you need any additional information.

@LeonarddeR
Copy link
Collaborator Author

I think the most recent commit should finally give us what's needed, namely Albatross Braille Display in the busReportedDeviceDescription

@burmancomp
Copy link
Contributor

Unfortunately albatross did not start, and it is not present in list of displays.

import bdDetect
next(bdDetect.getConnectedUsbDevicesForDriver("albatross"))
Traceback (most recent call last):
File "", line 1, in
File "bdDetect.pyc", line 441, in getConnectedUsbDevicesForDriver
File "baseObject.pyc", line 62, in get
File "baseObject.pyc", line 168, in _getPropertyViaCache
File "bdDetect.pyc", line 245, in _get_usbDevices
File "hwPortUtils.pyc", line 424, in listUsbDevices
OSError: [WinError 1168] Elementtiä ei löydy.

@LeonarddeR
Copy link
Collaborator Author

LeonarddeR commented Nov 11, 2023 via email

@burmancomp
Copy link
Contributor

Yes I tested in python console getting those result.

@LeonarddeR
Copy link
Collaborator Author

Ah I'm sorry, somehow I didn't get your test result.

@LeonarddeR
Copy link
Collaborator Author

Pretty sure last commit eventually should get you going

@burmancomp
Copy link
Contributor

burmancomp commented Nov 13, 2023

congratulations @LeonarddeR!

`>>> import bdDetect

next(bdDetect.getConnectedUsbDevicesForDriver("albatross"))
DeviceMatch(type='serial', id='VID_0403&PID_6001', port='COM5', deviceInfo={'hardwareID': 'USB\VID_0403&PID_6001&REV_0400', 'port': 'COM5', 'usbID': 'VID_0403&PID_6001', 'friendlyName': 'USB Serial Port (COM5)', 'devicePath': '\\?\usb#vid_0403&pid_6001#tmboijcd#{a5dcbf10-6530-11d2-901f-00c04fb951ed}', 'busReportedDeviceDescription': 'Albatross Braille Display'})`

I am about to close #15693.

@LeonarddeR
Copy link
Collaborator Author

Note that this pr doesn't yet contain a workaround for Albatross. Therefore I'd leave #15693 open and adapt it after merge of this pr.

@LeonarddeR LeonarddeR marked this pull request as ready for review November 13, 2023 11:48
@LeonarddeR LeonarddeR requested a review from a team as a code owner November 13, 2023 11:48
@burmancomp
Copy link
Contributor

burmancomp commented Nov 13, 2023

Thank you for information. I leave it open.

@burmancomp
Copy link
Contributor

Thank you for information. I leave it open.

ps. After reading your previous comment and then inspecting your initial comment I realized that your thought is that albatross driver is changed too. I realized it before writing my previous comment (which I am quoting in this comment).

@LeonarddeR
Copy link
Collaborator Author

This pr does not yet improve the Albatross driver by itself.

@burmancomp
Copy link
Contributor

But albatross driver can query bus reported device description?

@LeonarddeR
Copy link
Collaborator Author

Sure, after this is merged.

source/hwPortUtils.py Outdated Show resolved Hide resolved
source/hwPortUtils.py Show resolved Hide resolved
source/hwPortUtils.py Outdated Show resolved Hide resolved
source/hwPortUtils.py Outdated Show resolved Hide resolved
"devicePath": idd.DevicePath
})
if _isDebug():
log.debug("%r" % usbId)
Copy link
Member

Choose a reason for hiding this comment

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

can this use an f-string

Copy link
Member

Choose a reason for hiding this comment

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

this is unresolved

source/hwPortUtils.py Outdated Show resolved Hide resolved
source/hwPortUtils.py Outdated Show resolved Hide resolved
user_docs/en/changes.t2t Outdated Show resolved Hide resolved
user_docs/en/changes.t2t Show resolved Hide resolved
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
@LeonarddeR LeonarddeR marked this pull request as draft November 14, 2023 06:51
@AppVeyorBot
Copy link

See test results for failed build of commit c9ce3f98b6

@LeonarddeR
Copy link
Collaborator Author

The only way I could get rid of the c901 was by rewriting the if/elif statements into a match statement.

@LeonarddeR LeonarddeR marked this pull request as ready for review November 15, 2023 20:07
@lukaszgo1
Copy link
Contributor

The only way I could get rid of the c901 was by rewriting the if/elif statements into a match statement.

That works only because match and case statements are not measured for complexity by mccabe, so the function is as complex as before, the only change is that complexity is not checked for a language construct used. If it is indeed so hard to simplify it perhaps the noqa comment should remain, so that it is clear we haven't really gained anything here?

@LeonarddeR
Copy link
Collaborator Author

In that case I prefer to revert the match statement.

@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Nov 21, 2023
@seanbudd
Copy link
Member

so the function is as complex as before

I don't think this is true - the function was still split up into listComPorts/_getBluetoothPortInfo which reduced complexity in listComPorts significantly, and I am fairly sure to the point of legitimate c901 removal in both functions.

source/hwPortUtils.py Outdated Show resolved Hide resolved
"devicePath": idd.DevicePath
})
if _isDebug():
log.debug("%r" % usbId)
Copy link
Member

Choose a reason for hiding this comment

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

this is unresolved

@AppVeyorBot
Copy link

See test results for failed build of commit 1c32201dea

Copy link
Member

@seanbudd seanbudd left a comment

Choose a reason for hiding this comment

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

Thanks @LeonarddeR

@seanbudd seanbudd merged commit 5669fdf into nvaccess:master Nov 23, 2023
1 check passed
@nvaccessAuto nvaccessAuto added this to the 2024.1 milestone Nov 23, 2023
burmancomp added a commit to burmancomp/nvda that referenced this pull request Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-breaking-change conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants