Skip to content

Commit

Permalink
fix: Fixed the simulated driver by allowing to set the tag-handler wi…
Browse files Browse the repository at this point in the history
…thout providing a "protocol"
  • Loading branch information
chrisdutz committed Oct 3, 2024
1 parent 277183b commit 8572bb8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.java.simulated.tag.SimulatedTag;
import org.apache.plc4x.java.simulated.tag.SimulatedTagHandler;
import org.apache.plc4x.java.spi.ConversationContext;
import org.apache.plc4x.java.spi.Plc4xProtocolBase;
import org.apache.plc4x.java.spi.connection.AbstractPlcConnection;
import org.apache.plc4x.java.spi.connection.PlcTagHandler;
import org.apache.plc4x.java.spi.generation.Message;
import org.apache.plc4x.java.spi.messages.*;
import org.apache.plc4x.java.spi.messages.utils.DefaultPlcResponseItem;
import org.apache.plc4x.java.spi.messages.utils.PlcResponseItem;
Expand Down Expand Up @@ -66,7 +69,7 @@ public class SimulatedConnection extends AbstractPlcConnection implements PlcRea

public SimulatedConnection(SimulatedDevice device) {
super(true, true, true, true, false,
new DefaultPlcValueHandler(), null, null);
new DefaultPlcValueHandler(), new SimulatedTagHandler(), null, null);
this.device = device;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.plc4x.java.simulated;

import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.PlcDriverManager;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;

public class ManualSimulatedDriverTest {

public static void main(String[] args) throws Exception {
try (PlcConnection connection = PlcDriverManager.getDefault().getConnectionManager().getConnection("simulated:hurz")){
PlcReadRequest readRequest = connection.readRequestBuilder().addTagAddress("test", "RANDOM/dummy:UINT[100]").build();
PlcReadResponse readResponse = readRequest.execute().get();
System.out.println(readResponse);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ protected AbstractPlcConnection(boolean canPing, boolean canRead, boolean canWri
this.authentication = authentication;
}

protected AbstractPlcConnection(boolean canPing, boolean canRead, boolean canWrite,
boolean canSubscribe, boolean canBrowse,
PlcValueHandler valueHandler,
PlcTagHandler tagHandler,
BaseOptimizer optimizer, PlcAuthentication authentication) {
this.canPing = canPing;
this.canRead = canRead;
this.canWrite = canWrite;
this.canSubscribe = canSubscribe;
this.canBrowse = canBrowse;
this.valueHandler = valueHandler;
this.tagHandler = tagHandler;
this.optimizer = optimizer;
this.authentication = authentication;
}

public void setProtocol(Plc4xProtocolBase<? extends Message> protocol) {
this.protocol = protocol;
this.tagHandler = protocol.getTagHandler();
Expand Down

0 comments on commit 8572bb8

Please sign in to comment.