feat(s7): String (S7 STRING) scalar read+write via S7.Net.Types.S7String
This commit is contained in:
@@ -618,8 +618,11 @@ public sealed class S7Driver
|
||||
S7DataType.UInt64 => System.Buffers.Binary.BinaryPrimitives.ReadUInt64BigEndian(block),
|
||||
S7DataType.Float64 => System.Buffers.Binary.BinaryPrimitives.ReadDoubleBigEndian(block),
|
||||
|
||||
S7DataType.String => throw new NotSupportedException(
|
||||
"S7 String scalar reads land in a follow-up PR"),
|
||||
// S7 classic STRING: [maxLen byte][curLen byte][chars…]. S7.Net's S7String.FromByteArray
|
||||
// reads the two-byte header and returns exactly curLen ASCII chars, ignoring the reserved
|
||||
// padding past curLen — it validates curLen against the block, so no extra guard is needed.
|
||||
S7DataType.String => global::S7.Net.Types.S7String.FromByteArray(block),
|
||||
|
||||
S7DataType.DateTime => throw new NotSupportedException(
|
||||
"S7 DateTime scalar reads land in a follow-up PR"),
|
||||
|
||||
@@ -662,7 +665,13 @@ public sealed class S7Driver
|
||||
}
|
||||
|
||||
case S7DataType.String:
|
||||
throw new NotSupportedException("S7 String scalar writes land in a follow-up PR");
|
||||
// S7.Net's S7String.ToByteArray builds [maxLen=StringLength][curLen][chars…] and pads
|
||||
// the result to the full reserved field (StringLength + 2 bytes) — exactly the width
|
||||
// ReadScalarBlockAsync read, so WriteBytesAsync writes the whole reserved STRING. A value
|
||||
// longer than StringLength throws ArgumentException (S7.Net rejects overflow; we do NOT
|
||||
// silently truncate). A null value encodes as the empty string.
|
||||
return global::S7.Net.Types.S7String.ToByteArray(Convert.ToString(value) ?? "", tag.StringLength);
|
||||
|
||||
case S7DataType.DateTime:
|
||||
throw new NotSupportedException("S7 DateTime scalar writes land in a follow-up PR");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user