Use consistent DWord conversion for both Int32 and UInt32. Unfortunately there is no Span or even a FromByteArray function accepting a offset, so just use the same Array.Copy falls used for double.
- Do not allow null string to be passed, raise ArgumentNullException.
- Do not allow string whose ASCII representation is longer than the reserved length, since this currently leads to silent data loss.
- Always write the full binary data length of 2 + reservedLength, since that is what the binary representation of that string is in S7 memory, even if some tail bytes are unused by the current string.
I also suspect that S7WriteMultiple would have chocked on that last bit, but I am not sure. There aren't any tests for writing multiple Dataitems right now.
Adjust tests accordingly. Mostly add some tail bytes where necessary, and assert on exceptions where this is now required.
- Adds true support for 64bit double / LReal datatype.
- Set old Types.Single and Types.Double to obselete. Both class names use .NET types instead of S7 type names, contrary to all other types.
- Remove already obsoleted conversion from DWord to Real. Why is this even necessary?
For users caring about converting from DWord, they can still convert to single. But unless we get LWord support, there won't be a direct conversion to double/LReal.
- Adjust unit tests by removing rounding, testing directly double read/writes.
There is quite a bit of breaking changes at least in the automated Struct and object functions which automatically translate .NET types to appropriate S7 types.
My consideration was that if we ever want to support 64bit types, there is no way against breaking those existing incorrect conversions from 64bit .NET double to 32 bit S7 Real variables.
Both Synchronous and Asynchronous need to build the same binary data package to write a bytes array. Move that package building out into a common function.
Also use IEnumerable to pass in data instead of converting it to array and back multiple times. Not that happy with the whole ByteArray class, we could probably just use a MemoryStream instead.
This requires reference types that can be null to be annotated by a ? operator, similar to value types.
This gives the advantage that the compiler can warn against any null dereference exceptions, of which this commits elimits a few.
To make the underlying protocol implementation not any more complicated and to eliminate existing problems, and not that precise error reporting, I replaced some return null statements with explicit Exceptions. This lead to the assumption that those core protocoll functions always return non-null objects if they do not throw, making the PLC code simpler.
Adjust some NotConnected tests to look for explicit PlcException instead of NullReferenceException.
Add new class Types.Dtl by taking the DateTime type and adjusting things.
Also add unit test with binary data calculated by hand. (Need to verify with actual S7 data)
* Refactor PLCAddress
- Change fields into properties
- Apply PascalCase naming to all properties
- Make Parse public static with out parameters
* Support creating DataItem from string
* Rename PlcAddress.Address to StartByte
* 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.