You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Christofer Dutz <ch...@c-ware.de> on 2017/12/27 13:16:22 UTC

Some more info on read and write requests

Hi all,

I think I should provide you with some more information on the changes I did recently. I thought I had left them in a separate branch to allow others to have a look and comment, but I guess not all had a chance to do so.

Initially we had these SimpleRead/WriteRequest items, that allowed to read and write a single item to or from a PLC. In general, it is also possible to read and write arrays of one type in one request. So, I was thinking of adding “ArrayRead/WriteRequest” items that allow reading and writing of multiple items. As I know that it is also possible to send multiple different read/write items just thinking about adding 1000 new classes didn’t seem right. So, I did what I knew we had to add in the future and change the Read/WriteRequests to be a container for one or more read/write items. So, in general now you create a ReadRequest and add as much items to that as you want. Items are generally Arrays in the simple case they just contain a one-element array. In the constructor of the Read/WriteRequest I added convenience constructors, that allow creating the request and one item immediately … this is now the replacement for the SimpleRead/WriteRequest.

So now we have multiple items (getNumItems) tells us how many, and the Item also has a size, which tells us how many consecutive elements of the given datatype are read. I guess the naming of the “size” attribute is simple due to its naming in the S7 world. But you think we should name it differently, I have no problem with that.

One thing I did notice however: S7 seems to support reading multiple elements of multiple items in one request, but not writing. It does accept requests without any general error when writing multiple, the PLC however only seems to accept the first element (Only one value … not even multiple values in a n array for one address). Also, while you can read the values of the 8 digital inputs by reading one byte, you have to set them one by one or the PLC will not accept the request.

I think we will have to start going down a similar path as SWT did it for UIs in Java. Implement what the PLC supports directly and simulate what it doesn’t. I think we should keep the API the way it is now (supporting multiple read/writes in one request) and handle the details behind the scenes. So, if we write an array, this is automatically mapped to multiple single value writes by the driver and if we write multiple items, this too is handled by the driver … I think the client application shouldn’t have to bother implementing such features.

What do you think?