diff --git a/plc4j/drivers/knxnetip/src/main/generated/org/apache/plc4x/java/knxnetip/readwrite/KnxManufacturer.java b/plc4j/drivers/knxnetip/src/main/generated/org/apache/plc4x/java/knxnetip/readwrite/KnxManufacturer.java index 7df49b8722f..01fa99e2fd8 100644 --- a/plc4j/drivers/knxnetip/src/main/generated/org/apache/plc4x/java/knxnetip/readwrite/KnxManufacturer.java +++ b/plc4j/drivers/knxnetip/src/main/generated/org/apache/plc4x/java/knxnetip/readwrite/KnxManufacturer.java @@ -802,9 +802,10 @@ public enum KnxManufacturer { M_XIAMEN_LEELEN_TECHNOLOGY_CO__LTD_( (int) 689, (int) 747, (String) "Xiamen Leelen Technology Co.,Ltd."), M_LEDNX((int) 690, (int) 748, (String) "LedNX"), - M_ABB___RESERVED((int) 691, (int) 43954, (String) "ABB - reserved"), + M_EBELONG((int) 691, (int) 749, (String) "ebelong"), + M_ABB___RESERVED((int) 692, (int) 43954, (String) "ABB - reserved"), M_BUSCH_JAEGER_ELEKTRO___RESERVED( - (int) 692, (int) 43959, (String) "Busch-Jaeger Elektro - reserved"); + (int) 693, (int) 43959, (String) "Busch-Jaeger Elektro - reserved"); private static final Map map; static { diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java index 61f68f789c9..dcbc23bb284 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java @@ -195,6 +195,19 @@ public enum TransportSize { DataTransportSize.BYTE_WORD_DWORD, (String) "IEC61131_ULINT", TransportSize.INT), + COUNTER( + (short) 0x1C, + (boolean) true, + (boolean) false, + (short) 0x1C, + (short) 2, + (boolean) true, + (boolean) true, + (short) 'X', + (boolean) true, + DataTransportSize.OCTET_STRING, + (String) "IEC61131_INT", + null), REAL( (short) 0x0E, (boolean) true, diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/tag/S7Tag.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/tag/S7Tag.java index 5b8e1328e8d..0019e61aa6b 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/tag/S7Tag.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/tag/S7Tag.java @@ -77,9 +77,22 @@ public S7Tag(TransportSize dataType, MemoryArea memoryArea, this.dataType = dataType; this.memoryArea = memoryArea; this.blockNumber = blockNumber; - this.byteOffset = byteOffset; - this.bitOffset = bitOffset; this.numElements = numElements; + + //TODO: Should this address conversion be done in the mspec? + switch (dataType) { + case COUNTER: { + this.bitOffset = (byte) ((byteOffset) & 0x0007); + this.byteOffset = (byteOffset >> 3); + break; + } + default :{ + this.byteOffset = byteOffset; + this.bitOffset = bitOffset; + } + + } + } @Override @@ -97,6 +110,8 @@ public PlcValueType getPlcValueType() { return PlcValueType.DATE_AND_LTIME; case "DTL": return PlcValueType.DATE_AND_LTIME; + case "COUNTER": + return PlcValueType.WORD; default: return PlcValueType.valueOf(dataType.name()); } diff --git a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/DatatypesTest.java b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/DatatypesTest.java index 45d58e33091..d17a163c4a1 100644 --- a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/DatatypesTest.java +++ b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/DatatypesTest.java @@ -27,7 +27,17 @@ public class DatatypesTest { public static void main(String[] args) throws Exception { //try (PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://192.168.24.83")) { - try (PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://192.168.23.30")) { + // + String URL1 = "s7://192.168.23.30"; + + // + String URL2 = "s7://192.168.0.47?remote-rack=0&" + + "remote-slot=3&" + + "controller-type=S7_400&read-timeout=8&" + + "ping=false&ping-time=2&retry-time=3"; + + + try (PlcConnection connection = new DefaultPlcDriverManager().getConnection(URL1)) { final PlcReadRequest.Builder builder = connection.readRequestBuilder(); builder.addTagAddress("bool-value-1", "%DB2:0.0:BOOL"); // true builder.addTagAddress("bool-value-2", "%DB2:2.1:BOOL"); // false @@ -53,9 +63,12 @@ public static void main(String[] args) throws Exception { builder.addTagAddress("udint-array", "%DB2:50:UDINT[2]"); // 12345, 23456 builder.addTagAddress("real-value", "%DB2:58:REAL"); // 3.14159 builder.addTagAddress("real-array", "%DB2:62:REAL[2]"); // 12.345, 12.345 - builder.addTagAddress("lreal-value", "%DB2:70:LREAL"); // 3.14159265358979 - builder.addTagAddress("lreal-array", "%DB2:78:LREAL[2]"); // 1.2345, -1.2345 + +// builder.addTagAddress("lreal-value", "%DB2:70:LREAL"); // 3.14159265358979 +// builder.addTagAddress("lreal-array", "%DB2:78:LREAL[2]"); // 1.2345, -1.2345 + builder.addTagAddress("string-value", "%DB2:94:STRING(10)"); // "Hurz" + // When reading a sized STRING array, this has to be translated into multiple items //builder.addField("string-array", "%DB2:350:STRING(10)[2]"); // "Wolf", "Lamm" builder.addTagAddress("time-value", "%DB2:862:TIME"); // 1234ms diff --git a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualS7CounterTest.java b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualS7CounterTest.java new file mode 100644 index 00000000000..1ebadc9c77d --- /dev/null +++ b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualS7CounterTest.java @@ -0,0 +1,108 @@ +/* + * 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 + * + * https://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.s7.readwrite; + +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.messages.PlcReadRequest; +import org.apache.plc4x.java.api.messages.PlcReadResponse; +import org.apache.plc4x.java.api.messages.PlcWriteRequest; +import org.apache.plc4x.java.api.messages.PlcWriteResponse; +import org.apache.plc4x.java.api.types.PlcResponseCode; +import org.apache.plc4x.java.api.value.PlcValue; + +public class ManualS7CounterTest { + + public static void main(String[] args) throws Exception { + + //Maybe a S7-1200 + String URL1 = "s7://192.168.23.30"; + + //S7-400 + String URL2 = "s7://192.168.0.47?remote-rack=0&" + + "remote-slot=3&" + + "controller-type=S7_400&read-timeout=8&" + + "ping=false&ping-time=2&retry-time=3"; + + + try (PlcConnection connection = new DefaultPlcDriverManager().getConnection(URL2)) { + final PlcReadRequest.Builder readBuilder = connection.readRequestBuilder(); + + final PlcWriteRequest.Builder writeBuilder = connection.writeRequestBuilder(); + + writeBuilder.addTagAddress("counter-0", "%C0:COUNTER", Integer.decode("0x0123")); + writeBuilder.addTagAddress("counter-1", "%C9:COUNTER", Integer.decode("0x0456")); + writeBuilder.addTagAddress("counter-2", "%C12:COUNTER", Integer.decode("0x0789")); + writeBuilder.addTagAddress("counter-3", "%C18:COUNTER", Integer.decode("0x0012")); + + final PlcWriteRequest writeRequest = writeBuilder.build(); + final PlcWriteResponse writeResposne = writeRequest.execute().get(); + + if ( writeResposne.getResponseCode("counter-3") == PlcResponseCode.OK ){ + System.out.println("Write the counter"); + } else { + System.out.println("Problems...."); + } + + readBuilder.addTagAddress("counter-0", "%C0:COUNTER"); // Set this counter to 123 + readBuilder.addTagAddress("counter-1", "%C9:COUNTER"); // Set this counter to 456 + readBuilder.addTagAddress("counter-2", "%C12:COUNTER"); // Set this counter to 789 + readBuilder.addTagAddress("counter-3", "%C18:COUNTER"); // Set this counter to 012 + readBuilder.addTagAddress("counters", "%C0:COUNTER[20]"); // Set this counter to 000 + + final PlcReadRequest readRequest = readBuilder.build(); + + final PlcReadResponse readResponse = readRequest.execute().get(); + + System.out.println(readResponse); + + byte[] responseBytes = readResponse.getPlcValue("counter-0").getRaw(); + + short bcd_0 = readResponse.getShort("counter-0"); + short bcd_1 = readResponse.getShort("counter-1"); + short bcd_2 = readResponse.getShort("counter-2"); + short bcd_3 = readResponse.getShort("counter-3"); + System.out.println("counter-0 = " + convertShortToBcd(bcd_0)); + System.out.println("counter-1 = " + convertShortToBcd(bcd_1)); + System.out.println("counter-2 = " + convertShortToBcd(bcd_2)); + System.out.println("counter-3 = " + convertShortToBcd(bcd_3)); + + PlcValue plcValues = readResponse.getPlcValue("counters"); + + System.out.println(plcValues.toString()); + + if (plcValues.isList()) { + System.out.println(plcValues.getIndex(0).getShort() == bcd_0); + System.out.println(plcValues.getIndex(9).getShort() == bcd_1); + System.out.println(plcValues.getIndex(12).getShort() == bcd_2); + System.out.println(plcValues.getIndex(18).getShort() == bcd_3); + } + + + } + } + + + private static short convertShortToBcd(short incomingShort) { + return (short) (((incomingShort >> 8) & 0x0F) * 100 + + ((incomingShort >> 4) & 0x0F) * 10 + + (incomingShort & 0x000f)); + } + +} diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec index 5e7ef2888b0..c7faf3f891b 100644 --- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec +++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec @@ -897,6 +897,7 @@ ['0x0B' UDINT ['0x07' , 'D' , '4' , 'INT' , 'INTEGER' , 'IEC61131_UDINT' , 'false' , 'false' , 'true' , 'true' , 'true' ]] ['0x0C' LINT ['0x00' , 'X' , '8' , 'INT' , 'BYTE_WORD_DWORD' , 'IEC61131_LINT' , 'false' , 'false' , 'false' , 'true' , 'false' ]] ['0x0D' ULINT ['0x00' , 'X' , '8' , 'INT' , 'BYTE_WORD_DWORD' , 'IEC61131_ULINT' , 'false' , 'false' , 'false' , 'true' , 'false' ]] + ['0x1C' COUNTER ['0x1C' , 'X' , '2' , 'null' , 'OCTET_STRING' , 'IEC61131_INT' , 'true' , 'true' , 'true' , 'true' , 'false' ]] // Floating point values ['0x0E' REAL ['0x08' , 'D' , '4' , 'null' , 'REAL' , 'IEC61131_REAL' , 'true' , 'true' , 'true' , 'true' , 'true' ]]