[ 
https://issues.apache.org/jira/browse/PLC4X-333?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17491384#comment-17491384
 ] 

Christofer Dutz commented on PLC4X-333:
---------------------------------------

Hi Thijs,

in PLC4X we have a mechanism to rewrite user requests to better suit the 
protocol. We call these "Optimizers".

As only few protocols actually have multi-item requests, we have a default 
component called: SingleFieldOptimizer. This takes a multi-item request, and 
transforms that to multiple single item requests. 

Usually it's an all-or-nothing thing ... so if you have a look at the 
plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/ModbusDriver.java,
 it has a "getOptimizer()" method in which it returns that.

You could first try adding exactly this to the 
plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/ADSPlcDriver.java. 
This would make it only use single item requests. 

With this you could test if this would fix your problem ... however this 
woudln't be a full solution.

A full solution would be to create an ADS Optimizer, that simply extends the 
SingleFieldOptimizer, but it would check the "DriverContext" if it should be 
enabled. If it's disabled, it would just pass through the incoming requests, if 
it's enabled it would do a "super.processReadRequest" or 
"super.processWriteRequest" ...

Let me know if you need any help.

 

Chris

> Multiple Items in ADS Read
> --------------------------
>
>                 Key: PLC4X-333
>                 URL: https://issues.apache.org/jira/browse/PLC4X-333
>             Project: Apache PLC4X
>          Issue Type: Bug
>          Components: Driver-ADS
>    Affects Versions: 0.10.0
>            Reporter: Thijs M
>            Priority: Major
>
> Hi,
> For a POC I'am testing PLC4X with ADS/AMS PLC.  the PLC is a CX with twincat 
> V2.11.0 (Build 2216) on it.
> So I made this test program with PLC4j (0.10.0_SNAPSHOT) to read 1 variable 
> (BOOL).  This seems to work fine.  When I add a second variable (also BOOL) 
> to the same request, I get an exception :
> Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds 
> for length 0
>     at com.github.jinahya.bit.io.ArrayByteInput.read(ArrayByteInput.java:106)
>     at com.github.jinahya.bit.io.DefaultBitInput.read(DefaultBitInput.java:57)
>     at 
> com.github.jinahya.bit.io.AbstractBitInput.unsigned8(AbstractBitInput.java:63)
>     at 
> com.github.jinahya.bit.io.AbstractBitInput.unsigned16(AbstractBitInput.java:92)
>     at 
> com.github.jinahya.bit.io.AbstractBitInput.readInt(AbstractBitInput.java:135)
>     at 
> com.github.jinahya.bit.io.AbstractBitInput.readInt(AbstractBitInput.java:118)
>     at 
> com.github.jinahya.bit.io.AbstractBitInput.readLong(AbstractBitInput.java:156)
>     at 
> org.apache.plc4x.java.spi.generation.ReadBufferByteBased.readUnsignedLong(ReadBufferByteBased.java:190)
>     at 
> org.apache.plc4x.java.spi.generation.ReadBuffer.readUnsignedLong(ReadBuffer.java:74)
>     at 
> org.apache.plc4x.java.ads.protocol.AdsProtocolLogic.lambda$resolveMultipleSymbolicAddresses$65(AdsProtocolLogic.java:975)
>     at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
>     at 
> org.apache.plc4x.java.ads.protocol.AdsProtocolLogic.lambda$resolveMultipleSymbolicAddresses$67(AdsProtocolLogic.java:972)
>     at 
> org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>     at 
> io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>     at 
> io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>  
> Here is my code:
> String clientIp = "192.168.0.192";
> String sourceAmsNetId = "172.16.13.147.1.1";
> int sourceAmsPort = 65534;
> String targetAmsNetId = "192.168.0.184.1.1";
> int targetAmsPort = 801;
> String connectionString = 
> String.format("ads:tcp://%s?sourceAmsNetId=%s&sourceAmsPort=%d&targetAmsNetId=%s&targetAmsPort=%d",
>  plcIp, sourceAmsNetId, sourceAmsPort, targetAmsNetId, targetAmsPort);
> try (PlcConnection plcConnection = new 
> PlcDriverManager().getConnection(connectionString)){
> if (!plcConnection.getMetadata().canSubscribe()) {
> logger.error("This connection doesn't support subscribing.");
> return;
> }
> // Send Read Request
> CompletableFuture<? extends PlcReadResponse> requestFuture = 
> plcConnection.readRequestBuilder()
> .addItem("value-1", ".OPC_bAuto_:BOOL")
> .addItem("value-2", ".OPC_bAuto_2:BOOL")
> .build()
> .execute();
> PlcReadResponse response = requestFuture.get();
>  
>   Any help would greatly be appreciated.  Thank you !



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to