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 2019/05/04 19:32:53 UTC
[plc4x] 03/07: [PLC4X-110] Implemented messages and builders
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 70cffb1f7e18a6e850f73971f8eda1caaa578ec7
Author: Björn Höper <ho...@ltsoft.de>
AuthorDate: Mon Apr 22 19:48:39 2019 +0200
[PLC4X-110] Implemented messages and builders
For implementation of the C# API the interfaces for messages and
builders
---
plc4net/plc4net/api/IPlcConnection.cs | 41 ++++++-
plc4net/plc4net/api/IPlcDriver.cs | 3 +-
.../plc4net/exceptions/PlcInvalidFieldException.cs | 46 +++++++
.../IPlcFieldRequest.cs} | 34 +++---
.../IPlcFieldResponse.cs} | 31 +++--
plc4net/plc4net/messages/IPlcMessage.cs | 29 +++++
plc4net/plc4net/messages/IPlcReadRequest.cs | 29 +++++
.../IPlcReadRequestBuilder.cs} | 31 ++---
plc4net/plc4net/messages/IPlcReadResponse.cs | 29 +++++
.../IPlcConnection.cs => messages/IPlcRequest.cs} | 28 ++---
.../IPlcRequestBuilder.cs} | 30 ++---
.../IPlcConnection.cs => messages/IPlcResponse.cs} | 29 +----
.../IPlcSubscriptionEventArgs.cs} | 27 +----
.../plc4net/messages/IPlcSubscriptionRequest.cs | 29 +++++
.../messages/IPlcSubscriptionRequestBuilder.cs | 54 +++++++++
.../IPlcSubscriptionResponse.cs} | 30 ++---
.../plc4net/messages/IPlcUnsubscriptionRequest.cs | 29 +++++
.../messages/IPlcUnsubscriptionRequestBuilder.cs | 45 +++++++
.../plc4net/messages/IPlcUnsubscriptionResponse.cs | 29 +++++
.../IPlcWriteRequest.cs} | 28 +----
.../plc4net/messages/IPlcWriteRequestBuilder.cs | 134 +++++++++++++++++++++
plc4net/plc4net/model/IPlcField.cs | 39 ++++++
.../IPlcSubscriptionHandle.cs} | 27 +----
plc4net/plc4net/plc4net.csproj | 2 +
plc4net/plc4net/types/PlcResponseCode.cs | 35 ++++++
25 files changed, 660 insertions(+), 208 deletions(-)
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/api/IPlcConnection.cs
index 63be8dc..0b4ad43 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/api/IPlcConnection.cs
@@ -19,10 +19,12 @@ under the License.
using System;
using System.Threading.Tasks;
+using org.apache.plc4net.api.metadata;
+using org.apache.plc4net.messages;
+using org.apache.plc4net.model;
namespace org.apache.plc4net.api
{
- /// <inheritdoc />
/// <summary>
/// Interface for generalized PLC connections providing
/// functionality for basic operations like connect / disconnect etc.
@@ -46,5 +48,42 @@ namespace org.apache.plc4net.api
/// </summary>
/// <returns>Awaitable task</returns>
Task CloseAsync();
+
+ /// <summary>
+ /// Get the metadata for the connection
+ /// </summary>
+ IPlcConnectionMetadata PlcConnectionMetadata { get; }
+
+ /// <summary>
+ /// Parse the given field query
+ /// </summary>
+ /// <param name="fieldQuery">Query for the field</param>
+ /// <returns>Field parsed from the query string</returns>
+ /// <exception cref="org.apache.plc4net.exceptions.PlcInvalidFieldException">Thrown when the query can not be parsed</exception>
+ IPlcField Parse(string fieldQuery);
+
+ /// <summary>
+ /// Request builder for constructing read requests
+ /// </summary>
+ /// <returns>null if the connection does not support reading</returns>
+ IPlcReadRequestBuilder? ReadRequestBuilder { get; }
+
+ /// <summary>
+ /// Request builder for constructing write requests
+ /// </summary>
+ /// <returns>null if the connection does not support writing</returns>
+ IPlcWriteRequestBuilder? WriteRequestBuilder { get; }
+
+ /// <summary>
+ /// Request builder for constructing subscription requests
+ /// </summary>
+ /// <returns>null if the connection does not support subscriptions</returns>
+ IPlcSubscriptionRequestBuilder? SubscriptionRequestBuilder { get; }
+
+ /// <summary>
+ /// Request builder for unsubscribing
+ /// </summary>
+ /// <returns>null if the connection does not support subscriptions</returns>
+ IPlcUnsubscriptionRequestBuilder? UnsubscriptionRequestBuilder { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcDriver.cs b/plc4net/plc4net/api/IPlcDriver.cs
index 6a969d9..40aff40 100644
--- a/plc4net/plc4net/api/IPlcDriver.cs
+++ b/plc4net/plc4net/api/IPlcDriver.cs
@@ -50,7 +50,8 @@ namespace org.apache.plc4net.api
/// </summary>
/// <param name="connectionString"></param>
/// <param name="authentication"></param>
- /// <returns></returns>
+ /// <returns>Awaitable task returning the <see cref="IPlcConnection"/> to which the connection was established</returns>
+ /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown on connection failure</exception>
Task<IPlcConnection> ConnectAsync(string connectionString, IPlcAuthentication authentication);
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/exceptions/PlcInvalidFieldException.cs b/plc4net/plc4net/exceptions/PlcInvalidFieldException.cs
new file mode 100644
index 0000000..b3c4aa9
--- /dev/null
+++ b/plc4net/plc4net/exceptions/PlcInvalidFieldException.cs
@@ -0,0 +1,46 @@
+/*
+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.
+*/
+
+using System;
+using System.Runtime.Serialization;
+
+namespace org.apache.plc4net.exceptions
+{
+ [Serializable]
+ public class PlcInvalidFieldException : PlcException
+ {
+ public PlcInvalidFieldException()
+ {
+ }
+
+ public PlcInvalidFieldException(string message) : base(message)
+ {
+ }
+
+ public PlcInvalidFieldException(string message, Exception inner) : base(message, inner)
+ {
+ }
+
+ protected PlcInvalidFieldException(
+ SerializationInfo info,
+ StreamingContext context) : base(info, context)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcFieldRequest.cs
similarity index 56%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcFieldRequest.cs
index 63be8dc..d66b9b1 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcFieldRequest.cs
@@ -17,34 +17,36 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
+using System.Collections.Generic;
+using org.apache.plc4net.model;
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Request for certain fields inside the PLC
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcFieldRequest: IPlcRequest
{
/// <summary>
- /// Connect to the PLC asynchronously
+ /// Number of fields in the request
/// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
+ int FieldCount { get; }
/// <summary>
- /// Indicates the connection state
+ /// Enumeration of field names
/// </summary>
- bool IsConnected { get; }
+ IEnumerable<string> FieldNames { get; }
/// <summary>
- /// Close the PLC connection asynchronously
+ /// Get a field inside the request by its name
/// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ /// <param name="name">Name of the PLC field to return</param>
+ /// <returns></returns>
+ IPlcField GetFieldByName(string name);
+
+ /// <summary>
+ /// Returns all fields inside the request
+ /// </summary>
+ IEnumerable<IPlcField> Fields { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcFieldResponse.cs
similarity index 56%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcFieldResponse.cs
index 63be8dc..b418ad8 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcFieldResponse.cs
@@ -17,34 +17,33 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
+using System.Collections.Generic;
+using org.apache.plc4net.model;
+using org.apache.plc4net.types;
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Interface for responses to requests realted to
+ /// a specific PLC field
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcFieldResponse: IPlcResponse
{
/// <summary>
- /// Connect to the PLC asynchronously
+ /// Enumeration of fields in the response
/// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
+ IEnumerable<string> FieldNames { get; }
/// <summary>
- /// Indicates the connection state
+ /// Get a field by name
/// </summary>
- bool IsConnected { get; }
+ /// <param name="name">Name of the field to retrieve</param>
+ /// <returns>Field with the given name</returns>
+ IPlcField GetFieldByName(string name);
/// <summary>
- /// Close the PLC connection asynchronously
+ /// Get the response code from the PLC
/// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ PlcResponseCode ResponseCode { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcMessage.cs b/plc4net/plc4net/messages/IPlcMessage.cs
new file mode 100644
index 0000000..e7af221
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcMessage.cs
@@ -0,0 +1,29 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Base interface for PLC messages
+ /// </summary>
+ public interface IPlcMessage
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcReadRequest.cs b/plc4net/plc4net/messages/IPlcReadRequest.cs
new file mode 100644
index 0000000..17182ca
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcReadRequest.cs
@@ -0,0 +1,29 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Interface for requests reading data from a PLC
+ /// </summary>
+ public interface IPlcReadRequest: IPlcRequest
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcReadRequestBuilder.cs
similarity index 50%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcReadRequestBuilder.cs
index 63be8dc..79ff783 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcReadRequestBuilder.cs
@@ -17,34 +17,19 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
-
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Builds requests for reading values from a PLC
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcReadRequestBuilder: IPlcRequestBuilder<IPlcReadRequest>
{
/// <summary>
- /// Connect to the PLC asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
+ /// Add an item to the request
/// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ /// <param name="name">Name of the field to add</param>
+ /// <param name="fieldQuery">Query string for the field parameter</param>
+ /// <returns>Request builder to allow fluent API calls</returns>
+ IPlcReadRequestBuilder AddItem(string name, string fieldQuery);
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcReadResponse.cs b/plc4net/plc4net/messages/IPlcReadResponse.cs
new file mode 100644
index 0000000..66fc79b
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcReadResponse.cs
@@ -0,0 +1,29 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Response for read requests <see cref="IPlcReadRequest"/>
+ /// </summary>
+ public interface IPlcReadResponse : IPlcResponse
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcRequest.cs
similarity index 52%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcRequest.cs
index 63be8dc..174d506 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcRequest.cs
@@ -17,34 +17,20 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
using System.Threading.Tasks;
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Base interface for PLC requests that can be executed
+ /// and receive responses
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcRequest : IPlcMessage
{
/// <summary>
- /// Connect to the PLC asynchronously
+ /// Execute the request asynchronously
/// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ /// <returns>Awaitable task returning the response from the PLC</returns>
+ Task<IPlcResponse> ExecuteAsync();
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcRequestBuilder.cs
similarity index 50%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcRequestBuilder.cs
index 63be8dc..44e25d9 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcRequestBuilder.cs
@@ -17,34 +17,18 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
-
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Base interface for request builders
/// </summary>
- public interface IPlcConnection: IDisposable
+ /// <typeparam name="TRequest">Type of request returned when building the request</typeparam>
+ public interface IPlcRequestBuilder<out TRequest> where TRequest : IPlcRequest
{
/// <summary>
- /// Connect to the PLC asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
+ /// Builds the defined request
/// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ /// <returns>Request built from the definition</returns>
+ TRequest Build();
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcResponse.cs
similarity index 50%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcResponse.cs
index 63be8dc..616a380 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcResponse.cs
@@ -17,34 +17,17 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
-
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Interface for responses received from
+ /// PLCs
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcResponse: IPlcMessage
{
/// <summary>
- /// Connect to the PLC asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
+ /// Get the request that generated the response
/// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ IPlcRequest Request { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcSubscriptionEventArgs.cs
similarity index 51%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcSubscriptionEventArgs.cs
index 63be8dc..0b7c447 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcSubscriptionEventArgs.cs
@@ -18,33 +18,18 @@ under the License.
*/
using System;
-using System.Threading.Tasks;
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Base interface for event data associated with
+ /// subscription events
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcSubscriptionEventArgs
{
/// <summary>
- /// Connect to the PLC asynchronously
+ /// Timestamp of the event that occured
/// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ DateTime Timestamp { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcSubscriptionRequest.cs b/plc4net/plc4net/messages/IPlcSubscriptionRequest.cs
new file mode 100644
index 0000000..7fcaf3b
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcSubscriptionRequest.cs
@@ -0,0 +1,29 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Interface for requests to subscribe to value changes
+ /// </summary>
+ public interface IPlcSubscriptionRequest: IPlcFieldRequest
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcSubscriptionRequestBuilder.cs b/plc4net/plc4net/messages/IPlcSubscriptionRequestBuilder.cs
new file mode 100644
index 0000000..773f8ed
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcSubscriptionRequestBuilder.cs
@@ -0,0 +1,54 @@
+/*
+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.
+*/
+
+using System;
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Interface for classes building requests for subscriptions
+ /// </summary>
+ public interface IPlcSubscriptionRequestBuilder: IPlcRequestBuilder<IPlcSubscriptionRequest>
+ {
+ /// <summary>
+ /// Add a field that gets polled cyclically
+ /// </summary>
+ /// <param name="name">Alias for the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="pollingInterval">Time Interval at which the field should be polled</param>
+ /// <returns>Builder instance for Fluid API requests</returns>
+ IPlcSubscriptionRequestBuilder AddCyclicField(string name, string fieldQuery, TimeSpan pollingInterval);
+
+ /// <summary>
+ /// Add a field that sends an update when its value is changed
+ /// </summary>
+ /// <param name="name">Alias for the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <returns>Builder instance for Fluid API requests</returns>
+ IPlcSubscriptionRequestBuilder AddChangeOfStateField(string name, string fieldQuery);
+
+ /// <summary>
+ /// Add a field that sends an update when an event occurs
+ /// </summary>
+ /// <param name="name">Alias for the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <returns>Builder instance for Fluid API requests</returns>
+ IPlcSubscriptionRequestBuilder AddEventField(string name, string fieldQuery);
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcSubscriptionResponse.cs
similarity index 53%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcSubscriptionResponse.cs
index 63be8dc..25e0fcd 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcSubscriptionResponse.cs
@@ -17,34 +17,26 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
+using System.Collections.Generic;
+using org.apache.plc4net.model;
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Response to a <see cref="IPlcSubscriptionRequest"/>
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcSubscriptionResponse: IPlcFieldResponse
{
/// <summary>
- /// Connect to the PLC asynchronously
+ /// Get the handle for the subscription with the given name
/// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
+ /// <param name="name">Name of the subscription</param>
+ /// <returns>Subscription handle</returns>
+ IPlcSubscriptionHandle GetSubscriptionHandle(string name);
/// <summary>
- /// Indicates the connection state
+ /// Get all subscription handles
/// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ IEnumerable<IPlcSubscriptionHandle> SubscriptionHandles { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcUnsubscriptionRequest.cs b/plc4net/plc4net/messages/IPlcUnsubscriptionRequest.cs
new file mode 100644
index 0000000..0d0bd1f
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcUnsubscriptionRequest.cs
@@ -0,0 +1,29 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Request for releasing a subscription
+ /// </summary>
+ public interface IPlcUnsubscriptionRequest: IPlcRequest
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcUnsubscriptionRequestBuilder.cs b/plc4net/plc4net/messages/IPlcUnsubscriptionRequestBuilder.cs
new file mode 100644
index 0000000..a5752f8
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcUnsubscriptionRequestBuilder.cs
@@ -0,0 +1,45 @@
+/*
+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.
+*/
+
+using System.Collections.Generic;
+using org.apache.plc4net.model;
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Constructs requests for unsubscribing from PLC fields
+ /// </summary>
+ public interface IPlcUnsubscriptionRequestBuilder:
+ IPlcRequestBuilder<IPlcUnsubscriptionRequest>
+ {
+ /// <summary>
+ /// Add the given handles to the unsubscription request
+ /// </summary>
+ /// <param name="subscriptionHandles">Handles to unsubscribe</param>
+ /// <returns>Builder for chaining requests as Fluid API</returns>
+ IPlcUnsubscriptionRequestBuilder AddHandles(params IPlcSubscriptionHandle[] subscriptionHandles);
+
+ /// <summary>
+ /// Add the given handles to the unsubscription request
+ /// </summary>
+ /// <param name="subscriptionHandles">Handles to unsubscribe</param>
+ /// <returns>Builder for chaining requests as Fluid API</returns>
+ IPlcUnsubscriptionRequestBuilder AddHandles(IEnumerable<IPlcSubscriptionHandle> subscriptionHandles);
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcUnsubscriptionResponse.cs b/plc4net/plc4net/messages/IPlcUnsubscriptionResponse.cs
new file mode 100644
index 0000000..0b5e8f9
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcUnsubscriptionResponse.cs
@@ -0,0 +1,29 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Interface for requests to release a subscription
+ /// </summary>
+ public interface IPlcUnsubscriptionResponse: IPlcResponse
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/messages/IPlcWriteRequest.cs
similarity index 50%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/messages/IPlcWriteRequest.cs
index 63be8dc..13e617a 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/messages/IPlcWriteRequest.cs
@@ -17,34 +17,16 @@ specific language governing permissions and limitations
under the License.
*/
-using System;
-using System.Threading.Tasks;
-
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.messages
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Interface for writing values to PLCs
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcWriteRequest: IPlcRequest
{
/// <summary>
- /// Connect to the PLC asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
+ /// Number of values in the request
/// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ int NumberOfValues { get; }
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/messages/IPlcWriteRequestBuilder.cs b/plc4net/plc4net/messages/IPlcWriteRequestBuilder.cs
new file mode 100644
index 0000000..4e24554
--- /dev/null
+++ b/plc4net/plc4net/messages/IPlcWriteRequestBuilder.cs
@@ -0,0 +1,134 @@
+/*
+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.
+*/
+
+/*
+ * TODO: Decide if distinguishment between date, time and datetime are needed (see plc4j)
+ * TODO: Decide if implementation of byte[] and Byte[] as in plc4j are needed
+ * TODO: Check type compatibility between Java BigDecimal and Decimal
+ */
+
+using System;
+
+namespace org.apache.plc4net.messages
+{
+ /// <summary>
+ /// Interface for a builder that constructs write requests
+ /// </summary>
+ public interface IPlcWriteRequestBuilder: IPlcRequestBuilder<IPlcWriteRequest>
+ {
+ /// <summary>
+ /// Add item with bool value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params bool[] values);
+
+ /// <summary>
+ /// Add item with byte value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params byte[] values);
+
+ /// <summary>
+ /// Add item with short value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params short[] values);
+
+ /// <summary>
+ /// Add item with int value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params int[] values);
+
+ /// <summary>
+ /// Add item with long value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params long[] values);
+
+ /// <summary>
+ /// Add item with float value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params float[] values);
+
+ /// <summary>
+ /// Add item with double value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params double[] values);
+
+ /// <summary>
+ /// Add item with Decimal value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params Decimal[] values);
+
+ /// <summary>
+ /// Add item with string value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params string[] values);
+
+ /// <summary>
+ /// Add item with DateTime value
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem(string name, string fieldQuery, params DateTime[] values);
+
+ /// <summary>
+ /// Add item with value of generic type
+ /// </summary>
+ /// <param name="name">Identifying name of the field</param>
+ /// <param name="fieldQuery">Query string for the field</param>
+ /// <param name="values">Values to set</param>
+ /// <returns>Own instance to allow Fluid API calls</returns>
+ IPlcWriteRequestBuilder AddItem<T>(string name, string fieldQuery, params T[] values);
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/model/IPlcField.cs b/plc4net/plc4net/model/IPlcField.cs
new file mode 100644
index 0000000..098baf3
--- /dev/null
+++ b/plc4net/plc4net/model/IPlcField.cs
@@ -0,0 +1,39 @@
+/*
+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.
+*/
+
+
+namespace org.apache.plc4net.model
+{
+ /// <summary>
+ /// Base type for all field types.
+ /// Typically every driver provides an implementation of this interface in order
+ /// to be able to describe the fields of a resource.As this is completely tied to
+ /// the implemented protocol, this base interface makes absolutely no assumption to
+ /// any information it should provide.
+
+ /// In order to stay platform and protocol independent every driver connection implementation
+ /// provides a prepareField(String) method that is able to parse a string representation of
+ /// a resource into it's individual field type. Manually constructing PlcField objects
+ /// manually makes the solution less independent from the protocol, but might be faster.
+ /// </summary>
+ public interface IPlcField
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/plc4net/plc4net/api/IPlcConnection.cs b/plc4net/plc4net/model/IPlcSubscriptionHandle.cs
similarity index 51%
copy from plc4net/plc4net/api/IPlcConnection.cs
copy to plc4net/plc4net/model/IPlcSubscriptionHandle.cs
index 63be8dc..c2c1d54 100644
--- a/plc4net/plc4net/api/IPlcConnection.cs
+++ b/plc4net/plc4net/model/IPlcSubscriptionHandle.cs
@@ -18,33 +18,18 @@ under the License.
*/
using System;
-using System.Threading.Tasks;
+using org.apache.plc4net.messages;
-namespace org.apache.plc4net.api
+namespace org.apache.plc4net.model
{
- /// <inheritdoc />
/// <summary>
- /// Interface for generalized PLC connections providing
- /// functionality for basic operations like connect / disconnect etc.
+ /// Handle to a subscription
/// </summary>
- public interface IPlcConnection: IDisposable
+ public interface IPlcSubscriptionHandle
{
/// <summary>
- /// Connect to the PLC asynchronously
+ /// Event that can be subscribed to handle events raised by the subscription
/// </summary>
- /// <returns>Awaitable task</returns>
- /// <exception cref="org.apache.plc4net.exceptions.PlcConnectionException">Thrown if the connection to the PLC fails</exception>
- Task ConnectAsync();
-
- /// <summary>
- /// Indicates the connection state
- /// </summary>
- bool IsConnected { get; }
-
- /// <summary>
- /// Close the PLC connection asynchronously
- /// </summary>
- /// <returns>Awaitable task</returns>
- Task CloseAsync();
+ event EventHandler<IPlcSubscriptionEventArgs> PlcSubscriptionEvent;
}
}
\ No newline at end of file
diff --git a/plc4net/plc4net/plc4net.csproj b/plc4net/plc4net/plc4net.csproj
index 0c5a8bf..5d10bac 100644
--- a/plc4net/plc4net/plc4net.csproj
+++ b/plc4net/plc4net/plc4net.csproj
@@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>org.apache.plc4net</RootNamespace>
+ <LangVersion>8.0</LangVersion>
+ <NullableContextOptions>enable</NullableContextOptions>
</PropertyGroup>
</Project>
diff --git a/plc4net/plc4net/types/PlcResponseCode.cs b/plc4net/plc4net/types/PlcResponseCode.cs
new file mode 100644
index 0000000..7b9d0f8
--- /dev/null
+++ b/plc4net/plc4net/types/PlcResponseCode.cs
@@ -0,0 +1,35 @@
+/*
+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.
+*/
+
+namespace org.apache.plc4net.types
+{
+ /// <summary>
+ /// Possible responses
+ /// </summary>
+ public enum PlcResponseCode
+ {
+ Ok,
+ NotFound,
+ AccessDenied,
+ InvalidAddress,
+ InvalidDatatype,
+ InternalError,
+ ResponsePending
+ }
+}
\ No newline at end of file