You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2023/01/17 10:55:54 UTC

[plc4x] branch feature/cdutz/connection-cache-and-scraper-ng updated (edd1243120 -> 08421d3e49)

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a change to branch feature/cdutz/connection-cache-and-scraper-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git


    from edd1243120 refactor(plc4j/api): Updated the PlcDriverManager API
     new 00b989bae2 feat(ads): Added additional Known Group Index for ADS over EtherCAT
     new 08421d3e49 feat(plc4j/ads): Added a new example for reading data via AoE

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../telemetry/HelloAdsEtherCatTelemetry.java       | 113 +++++++++++++++++++++
 .../ads/src/main/resources/protocols/ads/ads.mspec |  75 +++++++-------
 2 files changed, 153 insertions(+), 35 deletions(-)
 create mode 100644 plc4j/examples/hello-ads-telemetry/src/main/java/org/apache/plc4x/java/examples/helloads/telemetry/HelloAdsEtherCatTelemetry.java


[plc4x] 02/02: feat(plc4j/ads): Added a new example for reading data via AoE

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/cdutz/connection-cache-and-scraper-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 08421d3e49179c4894c1ac1fd26f541832df1eb3
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Jan 17 11:55:45 2023 +0100

    feat(plc4j/ads): Added a new example for reading data via AoE
---
 .../telemetry/HelloAdsEtherCatTelemetry.java       | 113 +++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/plc4j/examples/hello-ads-telemetry/src/main/java/org/apache/plc4x/java/examples/helloads/telemetry/HelloAdsEtherCatTelemetry.java b/plc4j/examples/hello-ads-telemetry/src/main/java/org/apache/plc4x/java/examples/helloads/telemetry/HelloAdsEtherCatTelemetry.java
new file mode 100644
index 0000000000..f828486d3f
--- /dev/null
+++ b/plc4j/examples/hello-ads-telemetry/src/main/java/org/apache/plc4x/java/examples/helloads/telemetry/HelloAdsEtherCatTelemetry.java
@@ -0,0 +1,113 @@
+/*
+ * 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.examples.helloads.telemetry;
+
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.PlcDriverManager;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.api.types.PlcValueType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+// Extracted from https://infosys.beckhoff.com/index.php?content=../content/1031/devicemanager/262982923.html
+
+enum EtherCatConstants {
+    DeviceType(0x10000000, PlcValueType.UDINT),
+    ManufacturerDeviceName(0x10080000, PlcValueType.STRING),
+    //HardwareVersion(0x10090000, PlcValueType.),
+    //SoftwareVersion(0x100A0000, PlcValueType.),
+    //IdentityObjectNum(0x10180000, PlcValueType.),
+    IdentityObjectVendorId(0x10180000, PlcValueType.UDINT),
+    IdentityObjectProductCode(0x10180000, PlcValueType.UDINT),
+    IdentityObjectRevisionNumber(0x10180000, PlcValueType.UDINT),
+    IdentityObjectSoftwareVersion(0x10180000, PlcValueType.UDINT),
+    //ConfigurationDataNum(0x80000000, PlcValueType.), // 0x8xxx0000 xxx = device index (starting with 0)
+    ConfigurationDataAddress(0x80000001, PlcValueType.UINT),
+    ConfigurationDataType(0x8000000, PlcValueType.STRING), // Not sure ...
+    ConfigurationDataName(0x8000000, PlcValueType.STRING),
+    ConfigurationDataDeviceType(0x8000000, PlcValueType.UDINT),
+    ConfigurationDataVendorId(0x8000000, PlcValueType.UDINT),
+    ConfigurationDataProductCode(0x8000000, PlcValueType.UDINT),
+    ConfigurationDataRevisionNumber(0x8000000, PlcValueType.UDINT),
+    ConfigurationDataSerialNumber(0x8000000, PlcValueType.UDINT),
+    ConfigurationDataMailboxOutSize(0x8000000, PlcValueType.UINT),
+    ConfigurationDataMailboxInSize(0x8000000, PlcValueType.UINT),
+    ConfigurationDataLinkStatus(0x8000000, PlcValueType.USINT),
+    ConfigurationDataLinkPreset(0x8000000, PlcValueType.USINT),
+    ConfigurationDataFlags(0x8000000, PlcValueType.UINT),
+//    StateMachine(0xA0000000, PlcValueType.),      // 0xAxxx0000 xxx = device index (starting with 0)
+//    ScanSlaves(0xF002000, PlcValueType.),
+    ConfiguredSlavesNum(0xF0200000, PlcValueType.USINT);
+//    FrameStatistics(0xF1200000, PlcValueType.);
+
+    final int typeNumber;
+    final PlcValueType plcValueType;
+    EtherCatConstants(int typeNumber, PlcValueType plcValueType) {
+        this.typeNumber = typeNumber;
+        this.plcValueType = plcValueType;
+    }
+}
+public class HelloAdsEtherCatTelemetry {
+
+    private static final Logger logger = LoggerFactory.getLogger(HelloAdsTelemetry.class);
+    public static void main(String[] args) {
+        if(args.length != 2) {
+            logger.error("Usage: HelloAdsTelemetry {ip-address of PLC} {local ip-address}");
+            System.exit(1);
+        }
+
+        String remoteIp = args[0];
+        String localIp = args[1];
+        // The AmsNetId of the PLC usually is {ip}.1.1 and that of the EtherCAT master is {ip}.3.1
+        // The port number equals the EtherCAT address. For the EtherCAT master, this port is 0xFFFF = 65535
+        try (PlcConnection connection = PlcDriverManager.getDefault().getConnectionManager().getConnection(String.format("ads:tcp://%s?targetAmsNetId=%s.3.1&targetAmsPort=65535&sourceAmsNetId=%s.1.1&sourceAmsPort=65534&load-symbol-and-data-type-tables=false", remoteIp, remoteIp, localIp))) {
+            int vendorId = connection.readRequestBuilder().addTagAddress("vendorId", "0x0000F302/0x10180001:UDINT").build().execute().get().getInteger("vendorId");
+            int productCode = connection.readRequestBuilder().addTagAddress("productCode", "0x0000F302/0x10180002:UDINT").build().execute().get().getInteger("productCode");
+            int revisionNumber = connection.readRequestBuilder().addTagAddress("revisionNumber", "0x0000F302/0x10180003:UDINT").build().execute().get().getInteger("revisionNumber");
+            int serialNumber = connection.readRequestBuilder().addTagAddress("serialNumber", "0x0000F302/0x10180004:UDINT").build().execute().get().getInteger("serialNumber");
+            logger.info("EtherCAT Master: Vendor Id: {}, Product Code: {}, Revision Number: {}, Serial Number {}", vendorId, productCode, revisionNumber, serialNumber);
+
+            // Load the number of EtherCAT slaves:
+            int numSlaves = connection.readRequestBuilder().addTagAddress("numberOfSlaves", "0x0000F302/0xF0200000:USINT").build().execute().get().getInteger("numberOfSlaves");
+
+            // Load the number of slaves and their etherCatAddresses
+            // NOTE: We need to do this without using multi-item-requests as it seems that this part of the system doesn't support this.
+            Map<Integer, Integer> etherCatAddresses = new HashMap<>();
+            for(int i = 1; i < numSlaves; i++) {
+                String name = "slave-" + i;
+                String address = String.format("0x0000F302/0xF020%04X:UINT", i);
+                PlcReadResponse plcReadResponse = connection.readRequestBuilder().addTagAddress(name, address).build().execute().get();
+                if (plcReadResponse.getResponseCode(name) == PlcResponseCode.OK) {
+                    int etherCatAddress = plcReadResponse.getInteger(name);
+                    logger.info("Slave {} has EtherCAT address {}", i, etherCatAddress);
+                    etherCatAddresses.put(i, etherCatAddress);
+
+                }
+            }
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}


[plc4x] 01/02: feat(ads): Added additional Known Group Index for ADS over EtherCAT

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/cdutz/connection-cache-and-scraper-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 00b989bae25ed46f535a2626919cb9a4b2b3dbb5
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Jan 17 11:54:19 2023 +0100

    feat(ads): Added additional Known Group Index for ADS over EtherCAT
---
 .../ads/src/main/resources/protocols/ads/ads.mspec | 75 ++++++++++++----------
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/protocols/ads/src/main/resources/protocols/ads/ads.mspec b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
index a7e5a3b699..5ee6f8d9ea 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
@@ -634,54 +634,59 @@
 // Especially interesting for the sum add/delete notification requests
 // https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_ads_intro/117463563.html&id=
 [enum uint 32 ReservedIndexGroups
-    ['0x0000F000' ADSIGRP_SYMTAB]
-    ['0x0000F001' ADSIGRP_SYMNAME]
-    ['0x0000F002' ADSIGRP_SYMVAL]
-    ['0x0000F003' ADSIGRP_SYM_HNDBYNAME]
-    ['0x0000F004' ADSIGRP_SYM_VALBYNAME]
-    ['0x0000F005' ADSIGRP_SYM_VALBYHND]
-    ['0x0000F006' ADSIGRP_SYM_RELEASEHND]
-    ['0x0000F007' ADSIGRP_SYM_INFOBYNAME]
-    ['0x0000F008' ADSIGRP_SYM_VERSION]
+    ['0x0000F000' ADSIGRP_SYMTAB                              ]
+    ['0x0000F001' ADSIGRP_SYMNAME                             ]
+    ['0x0000F002' ADSIGRP_SYMVAL                              ]
+    ['0x0000F003' ADSIGRP_SYM_HNDBYNAME                       ]
+    ['0x0000F004' ADSIGRP_SYM_VALBYNAME                       ]
+    ['0x0000F005' ADSIGRP_SYM_VALBYHND                        ]
+    ['0x0000F006' ADSIGRP_SYM_RELEASEHND                      ]
+    ['0x0000F007' ADSIGRP_SYM_INFOBYNAME                      ]
+    ['0x0000F008' ADSIGRP_SYM_VERSION                         ]
     // We can use this GID to read the type information of a given variable
     // in the operation mode in which we don't read the entire structures on
     // connection start.
-    ['0x0000F009' ADSIGRP_SYM_INFOBYNAMEEX]
-    ['0x0000F00A' ADSIGRP_SYM_DOWNLOAD]
+    ['0x0000F009' ADSIGRP_SYM_INFOBYNAMEEX                    ]
+    ['0x0000F00A' ADSIGRP_SYM_DOWNLOAD                        ]
     // Read the symbol-table (All variables defined in the PLC)
-    ['0x0000F00B' ADSIGRP_SYM_UPLOAD]
-    ['0x0000F00C' ADSIGRP_SYM_UPLOADINFO]
+    ['0x0000F00B' ADSIGRP_SYM_UPLOAD                          ]
+    ['0x0000F00C' ADSIGRP_SYM_UPLOADINFO                      ]
     // Read the data-type-table (All data-types defined in the PLC)
-    ['0x0000F00E' ADSIGRP_DATA_TYPE_TABLE_UPLOAD]
+    ['0x0000F00E' ADSIGRP_DATA_TYPE_TABLE_UPLOAD              ]
     // Read the sizes of the symbol and data-type-tables
-    ['0x0000F00F' ADSIGRP_SYMBOL_AND_DATA_TYPE_SIZES]
-    ['0x0000F010' ADSIGRP_SYMNOTE]
+    ['0x0000F00F' ADSIGRP_SYMBOL_AND_DATA_TYPE_SIZES          ]
+    ['0x0000F010' ADSIGRP_SYMNOTE                             ]
     // We can use this GIT to read the data-type information for a given
     // data type name in the operation mode in which we don't read the
     // entire structures on connection start.
-    ['0x0000F011' ADSIGRP_DT_INFOBYNAMEEX]
+    ['0x0000F011' ADSIGRP_DT_INFOBYNAMEEX                     ]
     // Access to the %I fields
-    ['0x0000F020' ADSIGRP_IOIMAGE_RWIB]
-    ['0x0000F021' ADSIGRP_IOIMAGE_RWIX]
-    ['0x0000F025' ADSIGRP_IOIMAGE_RISIZE]
+    ['0x0000F020' ADSIGRP_IOIMAGE_RWIB                        ]
+    ['0x0000F021' ADSIGRP_IOIMAGE_RWIX                        ]
+    ['0x0000F025' ADSIGRP_IOIMAGE_RISIZE                      ]
     // Access to the %Q fields
-    ['0x0000F030' ADSIGRP_IOIMAGE_RWOB]
-    ['0x0000F031' ADSIGRP_IOIMAGE_RWOX]
-    ['0x0000F035' ADSIGRP_IOIMAGE_RWOSIZE]
-    ['0x0000F040' ADSIGRP_IOIMAGE_CLEARI]
-    ['0x0000F050' ADSIGRP_IOIMAGE_CLEARO]
-    ['0x0000F060' ADSIGRP_IOIMAGE_RWIOB]
+    ['0x0000F030' ADSIGRP_IOIMAGE_RWOB                        ]
+    ['0x0000F031' ADSIGRP_IOIMAGE_RWOX                        ]
+    ['0x0000F035' ADSIGRP_IOIMAGE_RWOSIZE                     ]
+    ['0x0000F040' ADSIGRP_IOIMAGE_CLEARI                      ]
+    ['0x0000F050' ADSIGRP_IOIMAGE_CLEARO                      ]
+    ['0x0000F060' ADSIGRP_IOIMAGE_RWIOB                       ]
     // Sum Requests
-    ['0x0000F080' ADSIGRP_MULTIPLE_READ]
-    ['0x0000F081' ADSIGRP_MULTIPLE_WRITE]
-    ['0x0000F082' ADSIGRP_MULTIPLE_READ_WRITE]
-    ['0x0000F083' ADSIGRP_MULTIPLE_RELEASE_HANDLE]
-    ['0x0000F084' ADSIGRP_SUMUP_READEX2]
-    ['0x0000F085' ADSIGRP_MULTIPLE_ADD_DEVICE_NOTIFICATIONS]
+    ['0x0000F080' ADSIGRP_MULTIPLE_READ                       ]
+    ['0x0000F081' ADSIGRP_MULTIPLE_WRITE                      ]
+    ['0x0000F082' ADSIGRP_MULTIPLE_READ_WRITE                 ]
+    ['0x0000F083' ADSIGRP_MULTIPLE_RELEASE_HANDLE             ]
+    ['0x0000F084' ADSIGRP_SUMUP_READEX2                       ]
+    ['0x0000F085' ADSIGRP_MULTIPLE_ADD_DEVICE_NOTIFICATIONS   ]
     ['0x0000F086' ADSIGRP_MULTIPLE_DELETE_DEVICE_NOTIFICATIONS]
-    ['0x0000F100' ADSIGRP_DEVICE_DATA]
-    ['0x00000000' ADSIOFFS_DEVDATA_ADSSTATE]
-    ['0x00000002' ADSIOFFS_DEVDATA_DEVSTATE]
+    ['0x0000F100' ADSIGRP_DEVICE_DATA                         ]
+    // This Group Index makes ADS access data via AoE (ADS over EtherCAT) and
+    // can be used to access telemetry data on the DeviceManager or from attached
+    // EtherCAT devices.
+    // https://infosys.beckhoff.com/index.php?content=../content/1031/eap/1521731467.html
+    ['0x0000F302' ADS_OVER_ETHERCAT                           ]
+    ['0x00000000' ADSIOFFS_DEVDATA_ADSSTATE                   ]
+    ['0x00000002' ADSIOFFS_DEVDATA_DEVSTATE                   ]
 ]
 
 [enum uint 32 ReturnCode