Skip to content

Commit

Permalink
docs: Updated the general concepts and plc4j getting started guides.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdutz committed Sep 5, 2023
1 parent a05857e commit 66649d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Expand Up @@ -98,7 +98,7 @@ Then this shorter version can be used. Please inspect the `Protocol Documentatio
{driver code}://{transport config}?{options}
----

=== Individual Resource Addresses
=== Individual Resource Addresses (Tags)

Addresses for individual tags on a PLC are extremely dependent on the used protocol.
As we usually decided to stick to the address formats that are used in those particular environments.
Expand Down
32 changes: 17 additions & 15 deletions src/site/asciidoc/users/getting-started/plc4j.adoc
Expand Up @@ -63,21 +63,21 @@ PLC4X generally supports a very limited set of functions, which is not due to th

The basic functions supported by PLCs and therefore supported by PLC4X are:

* Discover Devices
* List resources in the PLC
* Read data
* Write data
* Subscribe for data
* Execute functions in the PLC
* List resources in the PLC

In general we will try to offer as many features as possible.
So if a protocol doesn't support subscription based communication it is our goal to simulate this by polling in the background so it is transparent for the users.
In general, we will try to offer as many features as possible.
So if a protocol doesn't support subscription based communication it is our goal to simulate this by polling in the background, so it is transparent for the users (This simulation feature hasn't been implemented yet though, but it's on our roadmap).

But there are some cases in which we can't simulate or features are simply disabled intentionally:

* If a PLC and/or protocol don't support executing of functions, we simply can't provide this functionality.
* We will be providing stripped down versions of drivers, that for example intentionally don't support any writing of data and executing of functions.
* If a PLC and/or protocol don't support writing or browsing, we simply can't provide this functionality.
* Also do we plan on providing stripped down versions of drivers, that for example intentionally don't support any writing of data.

Therefore we use metadata to check programmatically, if a given feature is available.
Therefore, we use metadata to check programmatically, if a given feature is available.

==== Reading Data

Expand Down Expand Up @@ -119,15 +119,16 @@ asyncResponse.whenComplete((response, throwable) -> {
----

In general all requests are executed asynchronously.
So as soon as the request is fully processed, the callback gets called and will contain a `readResponse`, if everything went right or a `throwable` if there were problems.
As soon as the request is fully processed, the callback gets called and will contain a `readResponse`, if everything went right or a `throwable` if there were problems.

However, if you want to write your code in a more synchronous fashion, the following alternative will provide this:

----
PlcReadResponse response = readRequest.execute().get(5000, TimeUnit.MILLISECONDS);
----

Processing of the responses is identical in both cases.
Processing of the responses is identical in both cases in the synchronous approach you however need to catch any exceptions.

The following example will demonstrate some of the options you have:

.Up to version 0.10.0
Expand All @@ -154,7 +155,7 @@ for (String fieldName : response.getFieldNames()) {
}
----

.SNAPSHOT version
.SNAPSHOT version (The general process is still the same we however cleaned up some naming)
----
for (String tagName : response.getTagNames()) {
if(response.getResponseCode(tagName) == PlcResponseCode.OK) {
Expand All @@ -178,7 +179,7 @@ for (String tagName : response.getTagNames()) {
}
----

In the for loop, we are demonstrating how the user can iterate over the address aliases in the response.
In the for-loop, we are demonstrating how the user can iterate over the tag aliases in the response.
In case of an ordinary read request, this will be predefined by the items in the request, however in case of a subscription response, the response might only contain some of the items that were subscribed.

Before accessing the data, it is advisable to check if an item was correctly returned.
Expand All @@ -194,7 +195,7 @@ If this is `PlcResponseCode.OK`, everything is ok, however it could be one of th

Assuming the return code was `OK`, we can continue accessing the data.

As some addresses support reading arrays, with the method `getNumberOfValues` the user can check how many items of a given type are returned.
As some tags support reading arrays, with the method `getNumberOfValues` the user can check how many items of a given type are returned.
For convenience the response object has single-argument methods for accessing the data, which default to returning the first element.

response.getObject(fieldName)
Expand Down Expand Up @@ -277,7 +278,7 @@ for (String fieldName : response.getFieldNames()) {
}
----

.SNAPSHOT version
.SNAPSHOT version (The general process is still the same we however cleaned up some naming)
----
for (String tagName : response.getTagNames()) {
if(response.getResponseCode(tagName) == PlcResponseCode.OK) {
Expand Down Expand Up @@ -312,7 +313,7 @@ The main difference is that while reading there is only one form how you could r
- Cyclic (The Event is sent in regular cyclic intervals)
- Event (The Event is usually explicitly sent form the PLC as a signal)

Therefore instead of using a normal `addItem`, there are tree different methods as you can see in the following examples.
Therefore instead of using a normal `addItem` or `addTag` in newer versions, there are tree different methods as you can see in the following examples.

.Up to version 0.10.0
----
Expand Down Expand Up @@ -346,7 +347,8 @@ PlcSubscriptionResponse response = subscriptionRequest.execute().get();

Now comes the little more tricky part, as subscriptions are always asynchronous, we have to register a callback for the connection to call as soon as there is news available:

In general you can't say how many of your subscribed fields will be available in every callback so it is double important to check or iterate over the field names.
In general, you can't say how many of your subscribed fields will be available in every callback.
So it is double important to check or iterate over the field names.

.Up to version 0.10.0
----
Expand Down

0 comments on commit 66649d4

Please sign in to comment.