Skip to content

Commit 331e6a4

Browse files
SeanMolletclaude
andcommitted
Fix BoolRegister.ReadAsync reading the DT area instead of X/Y/R
ReadAreaByteRangeAsync takes an areaPrefix parameter that defaults to RegisterPrefix.DT. BoolRegister.ReadAsync did not pass it, so a direct read of a bit register resolved against the data area rather than the bit area: reading R183 actually read DT18 and returned bit 3 of that word. Reads silently returned wrong values rather than failing, and on a PLC whose low DT registers happen to be zero every bit register reads as false. The address itself was resolved correctly (GetMewName/MemoryAddress), and the write path (WriteSingleBitAsync) was already correct, so only reads were affected. AreaBase already passes registerType through, so the polled path was unaffected too - this only hit direct ReadAsync. Verified against an FP-series PLC over MEWTOCOL by comparing against raw RCC word reads (WR18 = 0x82A8, WX0 = 0x000D): 12 of 12 bit registers across the R and X areas now match, where previously all 12 returned false. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 1e27436 commit 331e6a4

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

MewtocolNet/Registers/Classes/BoolRegister.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ private async Task<bool> WriteSingleBitAsync(bool val) {
116116
/// <inheritdoc/>
117117
public async Task<bool> ReadAsync() {
118118

119-
var res = await attachedInterface.ReadAreaByteRangeAsync((int)MemoryAddress, (int)GetRegisterAddressLen() * 2);
119+
//pass the register type, otherwise this falls back to the DT area default and
120+
//reads a data register instead of the X/Y/R bit area
121+
var res = await attachedInterface.ReadAreaByteRangeAsync((int)MemoryAddress, (int)GetRegisterAddressLen() * 2, RegisterType);
120122
if (res == null) throw new Exception($"Failed to read the register {this}");
121123

122124
var matchingReg = attachedInterface.memoryManager.GetAllRegisters()

0 commit comments

Comments
 (0)