You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Julian Feinauer <j....@pragmaticminds.de> on 2018/09/18 06:01:15 UTC
Question regarding arrays in new API
Hi all,
I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
The current code is
PlcReadRequest plcReadRequest1 = new PlcReadRequest();
ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
plcReadRequest1.addItem(readRequestItem1);
So we fetch 2 bytes from Modbus.
How do I tell him to fetch an array of length 2 in the new API?
Thanks!
Julian
Re: Question regarding arrays in new API
Posted by Christofer Dutz <ch...@c-ware.de>.
Hi all,
well I only tried to fix compilation errors and fix things broken in the tests after the API changes. I did add several TODOs in the code where I noticed that the driver never supported some things (such as reading multiple items).
Chris
Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
Sebastian
> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>
> I just looked at our test code from marcel and its like
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
> // plcReadRequest1.addItem(readRequestItem1);
> //
> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
> //
> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
> // return byteBuffer.getInt();
> // } else {
> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
> // }
>
> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>
> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>
> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
> return byteBuffer.getInt();
>
> Or is there any simpler approach to this?
>
> Best
> Julian
>
> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Two bytes would be a register so you could read it like that („register:7"):
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>
> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>
> Sebastian
>
>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi all,
>>
>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>> The current code is
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>> plcReadRequest1.addItem(readRequestItem1);
>>
>> So we fetch 2 bytes from Modbus.
>> How do I tell him to fetch an array of length 2 in the new API?
>>
>> Thanks!
>> Julian
>
>
>
Re: Question regarding arrays in new API
Posted by Christofer Dutz <ch...@c-ware.de>.
Agreed,
just wanted to make sure we not create the abstraction and then lay back and implement drivers the easy way __
Chris
Am 18.09.18, 09:02 schrieb "Julian Feinauer" <j....@pragmaticminds.de>:
Hey,
if the protocol supports that we should definetly do it "native".
But if not (I can imagine such protocols), we should emulate it.
Julian
Am 18.09.18, 08:54 schrieb "Christofer Dutz" <ch...@c-ware.de>:
Öhm ... well I think that reading multiple items is ESSENTIAL and all drivers should be able to do this. Especially if the protocol generally allows it.
So instead of hiding these shortcomings behind an abstraction layer that adds performance penalties, I think we should fix the drivers. Especially as I already did the hard architectural work in the S7 driver already.
Chris
Am 18.09.18, 08:32 schrieb "Julian Feinauer" <j....@pragmaticminds.de>:
Hi Sebastian,
ah, okay, THIS is a valuable information __
Perhaps we should think (aside from modbus) more and more about wrappers that add the "full" functionality to partialy implemented drivers.
In this case for me as the user I do not care if theres one or two roundtrips to the plc, I only care about the API.
Perhaps this is another interesting topic for Thursday.
Best
Julian
Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
Sebastian
> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>
> I just looked at our test code from marcel and its like
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
> // plcReadRequest1.addItem(readRequestItem1);
> //
> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
> //
> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
> // return byteBuffer.getInt();
> // } else {
> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
> // }
>
> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>
> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>
> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
> return byteBuffer.getInt();
>
> Or is there any simpler approach to this?
>
> Best
> Julian
>
> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Two bytes would be a register so you could read it like that („register:7"):
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>
> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>
> Sebastian
>
>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi all,
>>
>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>> The current code is
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>> plcReadRequest1.addItem(readRequestItem1);
>>
>> So we fetch 2 bytes from Modbus.
>> How do I tell him to fetch an array of length 2 in the new API?
>>
>> Thanks!
>> Julian
>
>
>
Re: Question regarding arrays in new API
Posted by Julian Feinauer <j....@pragmaticminds.de>.
Hey,
if the protocol supports that we should definetly do it "native".
But if not (I can imagine such protocols), we should emulate it.
Julian
Am 18.09.18, 08:54 schrieb "Christofer Dutz" <ch...@c-ware.de>:
Öhm ... well I think that reading multiple items is ESSENTIAL and all drivers should be able to do this. Especially if the protocol generally allows it.
So instead of hiding these shortcomings behind an abstraction layer that adds performance penalties, I think we should fix the drivers. Especially as I already did the hard architectural work in the S7 driver already.
Chris
Am 18.09.18, 08:32 schrieb "Julian Feinauer" <j....@pragmaticminds.de>:
Hi Sebastian,
ah, okay, THIS is a valuable information __
Perhaps we should think (aside from modbus) more and more about wrappers that add the "full" functionality to partialy implemented drivers.
In this case for me as the user I do not care if theres one or two roundtrips to the plc, I only care about the API.
Perhaps this is another interesting topic for Thursday.
Best
Julian
Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
Sebastian
> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>
> I just looked at our test code from marcel and its like
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
> // plcReadRequest1.addItem(readRequestItem1);
> //
> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
> //
> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
> // return byteBuffer.getInt();
> // } else {
> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
> // }
>
> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>
> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>
> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
> return byteBuffer.getInt();
>
> Or is there any simpler approach to this?
>
> Best
> Julian
>
> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Two bytes would be a register so you could read it like that („register:7"):
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>
> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>
> Sebastian
>
>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi all,
>>
>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>> The current code is
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>> plcReadRequest1.addItem(readRequestItem1);
>>
>> So we fetch 2 bytes from Modbus.
>> How do I tell him to fetch an array of length 2 in the new API?
>>
>> Thanks!
>> Julian
>
>
>
Re: Question regarding arrays in new API
Posted by Christofer Dutz <ch...@c-ware.de>.
Öhm ... well I think that reading multiple items is ESSENTIAL and all drivers should be able to do this. Especially if the protocol generally allows it.
So instead of hiding these shortcomings behind an abstraction layer that adds performance penalties, I think we should fix the drivers. Especially as I already did the hard architectural work in the S7 driver already.
Chris
Am 18.09.18, 08:32 schrieb "Julian Feinauer" <j....@pragmaticminds.de>:
Hi Sebastian,
ah, okay, THIS is a valuable information __
Perhaps we should think (aside from modbus) more and more about wrappers that add the "full" functionality to partialy implemented drivers.
In this case for me as the user I do not care if theres one or two roundtrips to the plc, I only care about the API.
Perhaps this is another interesting topic for Thursday.
Best
Julian
Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
Sebastian
> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>
> I just looked at our test code from marcel and its like
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
> // plcReadRequest1.addItem(readRequestItem1);
> //
> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
> //
> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
> // return byteBuffer.getInt();
> // } else {
> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
> // }
>
> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>
> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>
> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
> return byteBuffer.getInt();
>
> Or is there any simpler approach to this?
>
> Best
> Julian
>
> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Two bytes would be a register so you could read it like that („register:7"):
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>
> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>
> Sebastian
>
>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi all,
>>
>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>> The current code is
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>> plcReadRequest1.addItem(readRequestItem1);
>>
>> So we fetch 2 bytes from Modbus.
>> How do I tell him to fetch an array of length 2 in the new API?
>>
>> Thanks!
>> Julian
>
>
>
Re: Question regarding arrays in new API
Posted by Julian Feinauer <j....@pragmaticminds.de>.
Hey Sebastian,
thats good to hear. Perhaps we should do a list of things that the interface "expects" from drivers and to write the code to emulate all these features (also, e.g., the subscriber discussion).
Currently I am a bit feared of having the log full of "UnsupportedOperationExceptions" (in the best case) or even some random NPEs due to something not being implemented somewhere :-O
Julian
Am 18.09.18, 08:36 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Agreed, regarding an abstract support I started a branch way back ago to solve this issue in a generic protocol layer:
https://github.com/apache/incubator-plc4x/tree/feature/TopLevelItemSpliting <https://github.com/apache/incubator-plc4x/tree/feature/TopLevelItemSpliting>
Going this way drivers could keep simple like modbus and ads but the thing that stopped me back then was the issue of correlation.
As far as I remember you can’t use the MessageToMessageEncoder anymore as protocol layer.
Sebastian
> Am 18.09.2018 um 08:32 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> ah, okay, THIS is a valuable information __
> Perhaps we should think (aside from modbus) more and more about wrappers that add the "full" functionality to partialy implemented drivers.
> In this case for me as the user I do not care if theres one or two roundtrips to the plc, I only care about the API.
>
> Perhaps this is another interesting topic for Thursday.
>
> Best
> Julian
>
> Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
> Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
>
> Sebastian
>
>> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi Sebastian,
>>
>> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
>> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>>
>> I just looked at our test code from marcel and its like
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
>> // plcReadRequest1.addItem(readRequestItem1);
>> //
>> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
>> //
>> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
>> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
>> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
>> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
>> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
>> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
>> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
>> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
>> // return byteBuffer.getInt();
>> // } else {
>> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
>> // }
>>
>> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>>
>> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>>
>> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
>> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
>> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
>> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
>> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
>> return byteBuffer.getInt();
>>
>> Or is there any simpler approach to this?
>>
>> Best
>> Julian
>>
>> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>>
>> Hi Julian,
>>
>> Two bytes would be a register so you could read it like that („register:7"):
>> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>>
>> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
>> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>>
>> Sebastian
>>
>>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>>
>>> Hi all,
>>>
>>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>>> The current code is
>>>
>>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>>> plcReadRequest1.addItem(readRequestItem1);
>>>
>>> So we fetch 2 bytes from Modbus.
>>> How do I tell him to fetch an array of length 2 in the new API?
>>>
>>> Thanks!
>>> Julian
>>
>>
>>
>
>
>
Re: Question regarding arrays in new API
Posted by Sebastian Rühl <se...@googlemail.com.INVALID>.
Hi Julian,
Agreed, regarding an abstract support I started a branch way back ago to solve this issue in a generic protocol layer:
https://github.com/apache/incubator-plc4x/tree/feature/TopLevelItemSpliting <https://github.com/apache/incubator-plc4x/tree/feature/TopLevelItemSpliting>
Going this way drivers could keep simple like modbus and ads but the thing that stopped me back then was the issue of correlation.
As far as I remember you can’t use the MessageToMessageEncoder anymore as protocol layer.
Sebastian
> Am 18.09.2018 um 08:32 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> ah, okay, THIS is a valuable information __
> Perhaps we should think (aside from modbus) more and more about wrappers that add the "full" functionality to partialy implemented drivers.
> In this case for me as the user I do not care if theres one or two roundtrips to the plc, I only care about the API.
>
> Perhaps this is another interesting topic for Thursday.
>
> Best
> Julian
>
> Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
> Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
>
> Sebastian
>
>> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi Sebastian,
>>
>> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
>> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>>
>> I just looked at our test code from marcel and its like
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
>> // plcReadRequest1.addItem(readRequestItem1);
>> //
>> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
>> //
>> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
>> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
>> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
>> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
>> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
>> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
>> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
>> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
>> // return byteBuffer.getInt();
>> // } else {
>> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
>> // }
>>
>> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>>
>> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>>
>> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
>> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
>> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
>> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
>> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
>> return byteBuffer.getInt();
>>
>> Or is there any simpler approach to this?
>>
>> Best
>> Julian
>>
>> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>>
>> Hi Julian,
>>
>> Two bytes would be a register so you could read it like that („register:7"):
>> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>>
>> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
>> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>>
>> Sebastian
>>
>>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>>
>>> Hi all,
>>>
>>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>>> The current code is
>>>
>>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>>> plcReadRequest1.addItem(readRequestItem1);
>>>
>>> So we fetch 2 bytes from Modbus.
>>> How do I tell him to fetch an array of length 2 in the new API?
>>>
>>> Thanks!
>>> Julian
>>
>>
>>
>
>
>
Re: Question regarding arrays in new API
Posted by Julian Feinauer <j....@pragmaticminds.de>.
Hi Sebastian,
ah, okay, THIS is a valuable information __
Perhaps we should think (aside from modbus) more and more about wrappers that add the "full" functionality to partialy implemented drivers.
In this case for me as the user I do not care if theres one or two roundtrips to the plc, I only care about the API.
Perhaps this is another interesting topic for Thursday.
Best
Julian
Am 18.09.18, 08:29 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
Sebastian
> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>
> I just looked at our test code from marcel and its like
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
> // plcReadRequest1.addItem(readRequestItem1);
> //
> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
> //
> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
> // return byteBuffer.getInt();
> // } else {
> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
> // }
>
> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>
> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>
> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
> return byteBuffer.getInt();
>
> Or is there any simpler approach to this?
>
> Best
> Julian
>
> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Two bytes would be a register so you could read it like that („register:7"):
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>
> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>
> Sebastian
>
>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi all,
>>
>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>> The current code is
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>> plcReadRequest1.addItem(readRequestItem1);
>>
>> So we fetch 2 bytes from Modbus.
>> How do I tell him to fetch an array of length 2 in the new API?
>>
>> Thanks!
>> Julian
>
>
>
Re: Question regarding arrays in new API
Posted by Sebastian Rühl <se...@googlemail.com.INVALID>.
Hi Julian,
Currently I have no idea if the modbus part still works after the refactoring (maybe Chris can help here) [might be disabled at all at time]. Before the register got mapped into the requested java type.
Regarding multiple items: like in ads the support for multiple items is currently not implemented so you would require to send a new request:
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79 <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java#L79>
Sebastian
> Am 18.09.2018 um 08:21 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi Sebastian,
>
> thanks for the fast reply, so the 16 bit register can be fetched as byte array?
> And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
>
> I just looked at our test code from marcel and its like
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> // ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
> // plcReadRequest1.addItem(readRequestItem1);
> //
> // CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
> //
> // PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
> // Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
> // if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
> // ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> // byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
> // byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
> // byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
> // byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
> // return byteBuffer.getInt();
> // } else {
> // throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
> // }
>
> And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
>
> So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
>
> ByteBuffer byteBuffer = ByteBuffer.allocate(4);
> byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
> byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
> byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
> byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
> return byteBuffer.getInt();
>
> Or is there any simpler approach to this?
>
> Best
> Julian
>
> Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
>
> Hi Julian,
>
> Two bytes would be a register so you could read it like that („register:7"):
> https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
>
> All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
> Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
>
> Sebastian
>
>> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>>
>> Hi all,
>>
>> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
>> The current code is
>>
>> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
>> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
>> plcReadRequest1.addItem(readRequestItem1);
>>
>> So we fetch 2 bytes from Modbus.
>> How do I tell him to fetch an array of length 2 in the new API?
>>
>> Thanks!
>> Julian
>
>
>
Re: Question regarding arrays in new API
Posted by Julian Feinauer <j....@pragmaticminds.de>.
Hi Sebastian,
thanks for the fast reply, so the 16 bit register can be fetched as byte array?
And if I need two registers (should be a 32 bit value altogether) I put two items in the builder?
I just looked at our test code from marcel and its like
PlcReadRequest plcReadRequest1 = new PlcReadRequest();
// ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, ReadInputRegistersModbusAddress.of(ADDRESS_PREFIX + modbusAddressToKafka.getAddress()), 2);
// plcReadRequest1.addItem(readRequestItem1);
//
// CompletableFuture<PlcReadResponse> completableFuture1 = plcConnection.read(plcReadRequest1);
//
// PlcReadResponse plcReadResponse = completableFuture1.get(TIMEOUT, TimeUnit.MILLISECONDS);
// Optional<ReadResponseItem<byte[]>> ret1 = plcReadResponse.getValue(readRequestItem1);
// if (ret1.isPresent() && ret1.get().getValues().size() == 2) {
// ByteBuffer byteBuffer = ByteBuffer.allocate(4);
// byteBuffer.put(0, ret1.get().getValues().get(0)[0]);
// byteBuffer.put(1, ret1.get().getValues().get(0)[1]);
// byteBuffer.put(2, ret1.get().getValues().get(1)[0]);
// byteBuffer.put(3, ret1.get().getValues().get(1)[1]);
// return byteBuffer.getInt();
// } else {
// throw new ModbusReadException(TIMEOUT_ERROR_MSG + " " + modbusAddressToKafka.getAddress());
// }
And I don’t like the byteBuffer part as we as client in this case should not bother with stuff like that.
So after changing to the new API I build to requests for two subsequent addresses (named with their address) and do:
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
byteBuffer.put(0, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[0]);
byteBuffer.put(1, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress()))[1]);
byteBuffer.put(2, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[0]);
byteBuffer.put(3, response.getByteArray(Integer.toString(modbusAddressToKafka.getAddress() + 1))[1]);
return byteBuffer.getInt();
Or is there any simpler approach to this?
Best
Julian
Am 18.09.18, 08:08 schrieb "Sebastian Rühl" <se...@googlemail.com.INVALID>:
Hi Julian,
Two bytes would be a register so you could read it like that („register:7"):
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
Sebastian
> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi all,
>
> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
> The current code is
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
> plcReadRequest1.addItem(readRequestItem1);
>
> So we fetch 2 bytes from Modbus.
> How do I tell him to fetch an array of length 2 in the new API?
>
> Thanks!
> Julian
Re: Question regarding arrays in new API
Posted by Sebastian Rühl <se...@googlemail.com.INVALID>.
Hi Julian,
Two bytes would be a register so you could read it like that („register:7"):
https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java <https://github.com/apache/incubator-plc4x/blob/master/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java>
All in all it seems that this driver is only able to read one register/coil at a time a would need some work after the refactoring.
Types of addresses can be found here: https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model <https://github.com/apache/incubator-plc4x/tree/master/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/model>
Sebastian
> Am 18.09.2018 um 08:01 schrieb Julian Feinauer <j....@pragmaticminds.de>:
>
> Hi all,
>
> I am currently migrating some code to the new plc4j API and are a bit unsure what to do.
> The current code is
>
> PlcReadRequest plcReadRequest1 = new PlcReadRequest();
> ReadRequestItem<byte[]> readRequestItem1 = new ReadRequestItem<>(byte[].class, plcConnection.parseAddress(someAddressStringHere), 2);
> plcReadRequest1.addItem(readRequestItem1);
>
> So we fetch 2 bytes from Modbus.
> How do I tell him to fetch an array of length 2 in the new API?
>
> Thanks!
> Julian