Repository navigation
USBPort: high-throughput readStream(), serial matching, endpoint-by-address - #120
Merged
Merged
Conversation
…tching and endpoint-by-address readData() reads one wMaxPacketSize packet at a time into an internal buffer, which is right for a command/response dialog but far too slow to drain a high-bandwidth bulk IN stream: a device that bursts faster than the host reads (a camera reading out its sensor) overruns its FIFO and the data comes back corrupted. - readStream(length, endPoint, chunkSize, timeout): read `length` bytes in large chunks (default wMaxPacketSize*16 = 16 KB, a SuperSpeed burst) in a tight loop, trimming the final short read. Independent of the internal buffer. - open() now honors serialNumber (via custom_match) so a specific unit can be selected when several identical devices are present; previously it was ignored. - endPointForAddress(address): resolve an endpoint by its USB address (e.g. 0x83), clearer than an interface index on multi-endpoint devices. readData/writeData/ flush now accept an endpoint object as well as an index (backward compatible). Validated on a ThorLabs Kiralux CS505MUP1 (5 MP polarization camera): command dialog on EP 0x02/0x82, and readStream on EP 0x83 delivering a full 7.5 MB frame at ~61 MB/s with no corruption, where packet-sized readData could not keep up. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Cwn4LmnBsBpXbQKRh6ByZr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
USBPort.readData()reads onewMaxPacketSizepacket at a time into an internal buffer — right for a command/response dialog, but far too slow to drain a high-bandwidth bulk IN stream. A device that bursts faster than the host reads (a camera reading out its sensor) overruns its FIFO, and the data comes back corrupted (periodic striping). SoUSBPort, as it was, could speak to a camera's command channel but not read its images.Changes (backward compatible)
readStream(length, endPoint=None, chunkSize=None, timeout=None)— readlengthbytes in large chunks (defaultwMaxPacketSize * 16= 16 KB, one SuperSpeed burst) in a tight loop, trimming the final short read. Independent of the internal buffer used byreadData.open()now honorsserialNumber(viacustom_match) so a specific unit can be selected when several identical devices are connected. It was stored but ignored before.endPointForAddress(address)— resolve an endpoint by its USB address (e.g.0x83), clearer than an interface index on multi-endpoint devices.readData/writeData/flushnow accept an endpoint object as well as an index.Validation (real hardware)
Tested on a ThorLabs Kiralux CS505MUP1 (5 MP polarization camera, VID/PID
1313:4001, USB 3.0, 5 endpoints):The command dialog runs on EP
0x02/0x82;readStreamdelivers a full 7.5 MB frame on EP0x83at ~61 MB/s with no corruption — where packet-sizedreadDatacould not keep up. Driver/context: https://github.com/DCC-Lab/Kiralux-python🤖 Generated with Claude Code