Fix write stringex (#162)

* Add StringEx.ToByteArray(...)

* Add Serialization.SerializeDataItem(DataItem)

Supports StringEx VarType or offloads to SerializeValue method.

* Use SerializeDataItem in S7WriteMultiple

* Assume string length without header in StringEx.ToByteArray

VarTypeToByteLength already assumed that StringEx declared count for
the number of characters without the header, this now matches that
behavior.

* Add unit tests for StringEx conversions

* Fix incorrect value passed to Encoding.GetBytes

The length must actually be within string limits.
This commit is contained in:
Michael Croes
2018-07-11 09:47:43 +02:00
committed by Raphael Schlameuß
parent a1b69a5c5a
commit 2204ab360c
5 changed files with 153 additions and 3 deletions

View File

@@ -23,7 +23,7 @@ namespace S7.Net.Protocol
foreach (var item in dataItems)
{
message.Add(Parameter.Template);
var value = Serialization.SerializeValue(item.Value);
var value = Serialization.SerializeDataItem(item);
var wordLen = item.Value is bool ? 1 : 2;
message[paramOffset + Parameter.Offsets.WordLength] = (byte) wordLen;