[s7] S7 — STRING/WSTRING/CHAR/WCHAR #337
Reference in New Issue
Block a user
Delete Branch "auto/s7/PR-S7-A2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
S7 STRING / WSTRING / CHAR / WCHAR codecs for issue #288.
S7StringCodecstatic class with encode/decode for each wire format:2 + maxLenbytes (header: declared-max byte + actual-len byte) + ASCII payload4 + 2 × maxLenbytes (two UInt16-BE header words) + UTF-16BE payloadactualLen > maxLenis clamped on read and rejected on write.S7DataTypeenum gainsWString,Char,WCharmembers alongside existingString. All four map toDriverDataType.String.S7Driver.ReadOneAsync/WriteOneAsyncroute viaPlc.ReadBytesAsync/WriteBytesAsynckeyed off the parsed address. HonoursS7TagDefinition.StringLength(default 254).Test plan
dotnet build src/ZB.MOM.WW.OtOpcUa.Driver.S7— clean (0 / 0)dotnet test tests/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests— 85 / 85 passed (21 new: golden-byte vectors, round-trip per type, header-clamp behavior, length-cap rejection)🤖 Auto-generated by the Mode-B execution loop. Closes #288.
Closes #288
Closes the NotSupportedException cliff for S7 string-shaped types. - S7DataType gains WString, Char, WChar members alongside the existing String entry. - New S7StringCodec encodes/decodes the four wire formats: STRING : 2-byte header (max-len + actual-len bytes) + N ASCII bytes -> total 2 + max_len. WSTRING : 4-byte header (max-len + actual-len UInt16 BE) + N×2 UTF-16BE bytes -> total 4 + 2 × max_len. CHAR : 1 ASCII byte (rejects non-ASCII on encode). WCHAR : 2 UTF-16BE bytes. Header-bug clamp: actualLen > maxLen is silently clamped on read so firmware quirks don't walk past the wire buffer; rejected on write to avoid silent truncation. - S7Driver.ReadOneAsync / WriteOneAsync issue ReadBytesAsync / WriteBytesAsync against the parsed Area / DbNumber / ByteOffset and honour S7TagDefinition.StringLength (default 254 = S7 STRING max). - MapDataType returns DriverDataType.String for the three new enum members so OPC UA discovery surfaces them as scalar strings. Tests: 21 new cases on S7StringCodec covering golden-byte vectors, encode/decode round-trips, the firmware-bug header-clamp, ASCII-only guard on CHAR, and the StringLength default. 85/85 passing. Closes #288