Fix SpiAdapter.Read buffer length mismatch in Mcp23xxx TransferFullDuplex#2492
Draft
Copilot wants to merge 3 commits into
Draft
Fix SpiAdapter.Read buffer length mismatch in Mcp23xxx TransferFullDuplex#2492Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
TransferFullDuplex requires writeBuffer and readBuffer to have the same length. The Read method was creating a 2-byte writeBuffer and a (buffer.Length + 2)-byte readBuffer, causing ArgumentException on real SPI devices. Fix: allocate writeBuffer with the same size as readBuffer, placing OpCode and register address in the first two bytes (remaining bytes are don't-care for the SPI read operation). Also fix the test mock's TransferFullDuplex to only pass command bytes to Write, preventing don't-care padding from corrupting register data. Agent-Logs-Url: https://github.com/dotnet/iot/sessions/7c410060-a096-49b1-8cfa-348f86e1f77b Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix System.ArgumentException for buffer length mismatch
Fix SpiAdapter.Read buffer length mismatch in Mcp23xxx TransferFullDuplex
Apr 9, 2026
krwq
requested changes
May 14, 2026
Member
krwq
left a comment
There was a problem hiding this comment.
This needs to be re-done with copilot CLI, doesn't seem correct
Allocate writeBuffer at the same length as readBuffer (buffer.Length + 2) with OpCode and register address in the first 2 bytes. This matches the pattern used in Mcp25xxx and fixes the ArgumentException thrown by UnixSpiDevice.TransferFullDuplex when buffers differ in length. Update the test mock's TransferFullDuplex to only forward the 2-byte command prefix (OpCode + RegisterAddress) to Write, since remaining bytes in the padded writeBuffer are don't-care and should not be written to mock registers. Agent-Logs-Url: https://github.com/dotnet/iot/sessions/16e97003-0f85-4e18-86ab-2bd7516ebc6b Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
Contributor
Author
Redone in 4c08fff. Removed the Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
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.
SpiAdapter.Read()to allocate equal-lengthwriteBufferandreadBufferforTransferFullDuplex(matching the Mcp25xxx pattern)SpiDeviceMock.TransferFullDuplexto only forward the 2-byte command prefix toWrite