Commit Graph

132 Commits

Author SHA1 Message Date
Michael Croes
2204ab360c 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.
2018-07-11 09:47:43 +02:00
Michael Croes
1538de148b Replace LastErrorCode and LastErrorString with exceptions 2018-07-09 20:07:47 +02:00
Michael Croes
ab11cc8e3e Add SourceLink support 2018-07-06 22:24:07 +02:00
Michael Croes
9740224966 Add NuGet tags to S7.Net.csproj 2018-07-06 22:24:07 +02:00
Raphael
2f3bbddaef Fixes invalid TPKT length in request header 2018-07-04 11:47:13 +02:00
Raphael
932433ad69 Merge branch 'master' of https://github.com/rapha-dev/s7netplus into datatype-float 2018-07-03 08:44:51 +02:00
Raphael
d37c388d20 Fixed obsolete message 2018-07-03 08:41:54 +02:00
Raphael
b8b144d7ae Add support for datatype float (Single) and obsolete double (Double) usage 2018-07-02 10:20:02 +02:00
Michael Croes
98228924ea Simplify info declaration in Struct field loops 2018-06-30 22:19:44 +02:00
Michael Croes
a1f4e44c48 R#: Cleanup usings 2018-06-30 22:19:44 +02:00
Michael Croes
7821b6b6f6 Add NetStandard 1.3 support
Supersedes UWP support since UWP 10.0 supports up to NetStandard 1.4.
2018-06-30 22:19:44 +02:00
Michael Croes
e516675a70 Replace InvalidEnumArgumentException usage
InvalidEnumArgumentException is not supported in NetStandard 1.3.
2018-06-30 22:19:44 +02:00
Michael Croes
710ab2e026 Provide a buffer to MemoryStream
NetStandard 1.3 doesn't expose .GetBuffer(), this removes the need for
having it. The support for messages that span TPKT's is quite nasty, but
probably S7 PLC's will never even use a message spanning multiple TPKT's.
2018-06-30 22:17:48 +02:00
Raul Hidalgo Caballero
66fe6750b2 Merge branch 'master' into master 2018-06-28 10:40:11 +02:00
Michael Croes
514dde365e Cleanup TSAP parameters
- Remove duplicate parameter code / length (already in initial array)
- Remove separate branch for S7-400 (same as S7-300/1200)
- Change all values to 2-character hex
2018-06-27 21:26:44 +02:00
Michael Croes
6569e5e169 Extract ConnectionRequest from PLCHelpers 2018-06-27 21:07:41 +02:00
Michael Croes
4bca9d8c19 Merge pull request #130 from mycroes/fix-communication-setup-pdu-size
Fix the PDU size in communication setup
2018-06-26 22:18:44 +02:00
Raul Hidalgo Caballero
daf0f8e0d6 Merge branch 'master' into master 2018-06-21 21:24:01 +02:00
Michael Croes
d9abebe550 Fix the PDU size in communication setup
[7, 80] resulted in 1872; [7, 128] (or [0x07, 0x80] in hex) results in
the 1920 as specified in comments.
2018-06-21 20:49:05 +02:00
Michael Croes
2083ab1501 Remove obsolete attribute and comments
References #124.
2018-06-21 20:28:22 +02:00
Michele Cattafesta
003d775228 Merge pull request #127 from mycroes/write-short-array-fix
Write short array fix
2018-06-21 13:32:44 +01:00
Michael Croes
5a82313eb1 Change order of byte assignment for uniformity
Order is now same as ToByteArray(Int16[] value), where the order is
important due to the index increment in the same line.
2018-06-19 21:26:03 +02:00
Michael Croes
8d64bd89fc Fix byte order when serializing short[] / Int16[]
Values should be written as big-endian, unfortunately the ordering for
short values in an array was little-endian.
2018-06-19 21:24:28 +02:00
Michael Croes
299918e293 Add Plc.Write/WriteAsync(params DataItem[] dataItems) 2018-06-15 21:50:41 +02:00
Michael Croes
740a47ab43 Add initial WriteMultiple protocol 2018-06-15 21:39:38 +02:00
Michael Croes
38d089e117 Add boolean support to GetPackage 2018-06-15 21:39:38 +02:00
Michael Croes
aaab24a4c2 Add and move serialization helpers
Added (Get|Set)WordAt, SetAddressAt and moved GetPackage method.
2018-06-15 21:39:38 +02:00
Raphael
1b22badea1 Fixed ErrorCode.ReadData for specific methods 2018-06-08 10:26:52 +02:00
Raphael
ddfedaa17e Typo in Exception string 2018-06-08 10:22:42 +02:00
Raul Hidalgo Caballero
2d24adc874 Port to NetStandard 2018-06-05 17:33:42 +02:00
Thomas Jäger
64e485c54a Revert "Use socket instead of TcpClient and stream."
Revert back to using Stream/TcpClient. High performance stuff is moved
to highperformancesockets branch. I think this is interesting, but i also
feel that this is premature optimization. I doubth that this will be a
performance bottleneck ofr the forseeable future.

This reverts commit 1b34716a30.
2018-05-18 08:52:19 +02:00
Thomas Jäger
219c1cc71a Revert "Use high performance wrapper"
This reverts commit a3277133af.
2018-05-18 08:43:44 +02:00
Thomas Jäger
a3277133af Use high performance wrapper 2018-05-16 16:29:11 +02:00
Thomas Jäger
00e22ee214 Incorporate fixes from #117 (moved to helpers)
fix array naming.
2018-05-16 15:50:00 +02:00
Thomas Jäger
8ac96162f9 Merge remote-tracking branch 'upstream/master' into tcpclient 2018-05-16 11:33:46 +02:00
Thomas Jäger
1b34716a30 Use socket instead of TcpClient and stream.
Async implemented with wrapper.
2018-05-16 11:24:21 +02:00
Thomas Jäger
b8b890977e Fix structured comments 2018-05-14 14:19:33 +02:00
Raphael
642cf8169e Fixed bug for reading VarType.Bit and VarType.Byte on odd number of bytes in ReadMultipleVars() 2018-05-07 11:47:52 +02:00
Raphael
cbaa8921df import killnine master 2018-05-07 09:47:20 +02:00
Raphael
0d1bc472c8 Added BitAdr to DataItem and fixed bug in ReadMultipleVars on VarType.Bit 2018-04-27 16:00:41 +02:00
Thomas Jäger
84aee0671a Only return used bytes 2018-04-19 15:39:03 +02:00
Thomas Jäger
74af1c0da7 Change project to allow testing internal classes.
Add protocol tests
Simplify async tests
2018-04-19 15:08:52 +02:00
Thomas Jäger
eb0d6a3429 Better TPKT error handling 2018-04-19 15:06:10 +02:00
Thomas Jäger
f53a3bd320 Use TcpClient and implemnt async methods
Note: This keeps the old methods to be backward compatible.
Note: Unforntunatly a lot of whitespace fixes, refactoring and other trivial stuff is
included. It was to hard to split of in a seperate commit.

Note: Async methods does not use exactly the same structure/signature as the
existing methods. "Out" parameters like ReadClass and ReadStruct instead
returns the struct in tuple. Async methods also rely on exceptions
instead of ErrorCodes to communicate exception states to calling client.

* Use TcpClient and use Async methods (ReadAsync/WriteAsync)
* Implemnt async methods for all existing methods
* Implemnt existing methods using tcpclient.
* Split Plc.cs in more files. (Common, Async, Sync, Helpers)
* Mark old methods as Obsolete
* Split tests in two files
* Implement Async tests
2018-04-19 13:13:08 +02:00
Thomas Jäger
50b026d7a5 Read TPKT/COTP packets / Read MaxPDU size from PLC
Read responses from the PLS using classes for TPKT and COPT. This
makes the communication more robust. It will now handle empty COTP
packets that SoftPLS and WinAC based PLCs send out. I use RFC names for
functions and classes.

Change logic to use COTP and S7Comm reponse codes instead of
relying on packet sizes.

Read Max PDU size from connection setup. Ref #21
Change logic to use MaxPDUSize when reading istead of hardcoded limit.

I tried using MaxPDUSize when writing data but this failed when packet size is
over 256 on snap7. So i decided to drop changes to write size.
I have done some tests against WinAC cpu and it seems to handle bigger pdu's
when writing if negotiated in the connection setup. This might just be a SNAP7 bug.

Fix MaxPDUSize for readbytes

Remove debug line

Simplify byte copy. Remove unessesarry buffer
2018-04-19 00:34:11 +02:00
Thomas Jäger
f740ba0078 Fix writing double to PLC 2018-04-19 00:34:11 +02:00
Thomas Jäger
1b4faf21d7 Code Lint: Standard dispose Pattern. /// to // comment 2018-04-19 00:34:11 +02:00
Michele Cattafesta
9fd515280a Revert "Merge pull request #107 from thoj/master"
This reverts commit d17fdf8efb, reversing
changes made to bfeacee08f.
2018-04-11 20:22:24 +01:00
Thomas Jäger
8a3db22629 Read TPKT/COTP packets / Read MaxPDU size from PLC
Read responses from the PLS using classes for TPKT and COPT. This
makes the communication more robust. It will now handle empty COTP
packets that SoftPLS and WinAC based PLCs send out. I use RFC names for
functions and classes.

Change logic to use COTP and S7Comm reponse codes instead of
relying on packet sizes.

Read Max PDU size from connection setup. Ref #21
Change logic to use MaxPDU from cpu limit instead of hardcoded limit.

Remove var count limit.
2018-04-10 15:26:04 +02:00
Thomas Jäger
6470f8d076 Document bSend1 data packet 2018-04-10 15:25:20 +02:00