Adding a node to server's address space in OPC UA ANSI C stack - opc

I have a problem with OPC UA ANSI C stack, a very simple project for a subject: simply add a node to the server's address space, so that a client can then read it.
I know there is the open source ANSI C stack (open62541), but I need to use the official one.
I found these two objects inside the stack: the struct OpcUa_AddNodesItem (stackcore/opcua_types.h) and the function OpcUa_ServerApi_AddNodes (proxystub/serverstub/opcua_serverapi.c).
I think that this struct must be inserted inside the function, but I have some problems to set these two object's parameters.
Inside ansicservermain.c, how have I fill this two objects to add a node on the fly (for example, an integer variable)?

The OPC Foundation is only releasing the OPC UA Stack in ANSI C. This only allow you to have the communication layer. To have a fully functionnal OPC UA Server you need to develop your own Server on top of it, that will manage stuff like the AddressSpace (where you have the Node), the Session, the Subscription,...
You can try and buy some OPC UA Server SDK that have everything implemented or develop you own.
If you basically want to add some Nodes with the OPC UA Stack "Demo Server" there is 2 possibilites.
Add a static nodes by adding nodes in the addressspace_init.h files
Implement the OpcUa_ServerApi_AddNodes() which will be called by the OPC UA AddNodes Service, allowing an OPC UA Client to add some new nodes on the fly in an OPC UA Server (there is currently not so many OPC UA Client nor Server supporting this features as far as I know)

Related

Mapping of C# objects to OPCUA

I am new to OPC UA,
Our requirement is that the OPC UA Client app will do the reads/write data from/to a backend system (which is the system of record) via a OPC UA server. How can we represent the backend system C# objects in an OPC UA Server? So that the data gets directly updated in the backend system rather being on nodes(nodes object), we are more concerned on the duplicate data in both places (OPC UA server and Backed system) and also the data need to be UPTODATE on both the OPCUA server and backend system
I know this is not exactly an answer but maybe it can help you.
Look in the https://github.com/OPCFoundation/UA-.NETStandard-Samples with the Quickstarts and especially AlarmCondition Server. There you see a simple implementation of an "Underlying System".
Maybe this can be of help?

What is the difference between the OPC-Router and Kepserverex?

What is the difference between the OPC-Router and Kepserverex? I have seen a solution where both of them were used - Kepserverex connecting to machines and sending data to the OPC-Router which then sends data to IT Applications. Couldn't one of them do both tasks together?
I did compare the features of both products, but couldn't figure out why you would use one or the other - or both together. Both products seem to support data exchange between different protocols and platforms.
The KepServerEX is an OPC Server. Connecting over 150 different kinds of machines and providing their data as OPC UA data for OPC Clients.
The OPC Router is an OPC Client and is a tool for system integration. With the OPC Router it is possible to transfer data between systems whenever the data is needed (triggered). So the OPC Router connects systems like SAP, databases, label printers and a lot more and moves data between them. This also includes workflow-like data transfers, like calling a Stored Procedure in a database with a defined set of input parameters and transferring the returned values back to another system (maybe to the PLC over OPC UA => over the KepServerEX). In general you enable systems to interact with each other by the OPC Router. And this is where Industry 4.0 starts.
Greetings from the inray-Team

Is OPC UA Read and Write operations atomic?

In other words, is it possible for a server or a client to receive partial data before the transmission is finished?
I am sure this information is written somewhere in the extensive documentation of the OPC Foundation, but I think this is essential.
I am using the "atomic" phrase as used for database writes. When a programmer updates a table, the update is always atomic in the sense that it is either done or not done. We rely on the DB software for guaranteeing against the operation being only partially successful.
In the case of a PLC acting as an OPC UA server; when the client writes say 1 KByte data, are we sure that the program running on the PLC, on any instant read a part of this data while it is still being communicated and written? Since we are dealing with a very fast reading entity (the PLC) on the other side of the communication, is it possible that the PLC gets the first 100 bytes before the rest is received?
In the case of a PLC acting as an OPC UA server; when the client writes say 1 KByte data, are we sure that the program running on the PLC, on any instant read a part of this data while it is still being communicated and written?
You can be certain that any server will not be processing any read or write until the request has been fully transmitted by the client. There is no facility in OPC UA for dealing with streaming/partial requests from clients.
That said, how the server handles that 1KB of data it just received as a write is not covered by spec. There is no guarantee that it is written atomically to whatever the backing/underlying datasource may be (in memory, shared memory, a file, another device on the network, etc...).
I do believe that most OPC UA servers built in to PLCs are probably doing the right thing to ensure atomicity but there is nothing in the spec that guarantees it and no way to be sure other than contacting that vendor or consulting documentation.
Beckhoff OPC-UA Server communicates with the Beckhoff PLC through the ADS protocol.
The default Max Size of the consistent data sent with the help of the ads router is 16 kByte although it can be changed if needed.
This is important to understand, because the OPC-UA Server is not part of the PLC runtime environment.
When an OPC-UA client writes a node of an OPC-UA Server, the OPC-UA Server sends this data to the PLC.
In the Twincat development environment you have the option to declare a special attribute for structured types:
{attribute 'OPC.UA.DA.StructuredType' := '1'}
This tells the Beckhoff OPC-UA Server to send the data concerning that specific data structure in a consistent way to the PLC when it receives it from a client.
The Beckhoff OPC-UA documentation states:
"StructuredTypes allow you to read or write structures without interpreting each byte, because the UA Server
returns the information type of each element of the structure. Based on complex functions in modern
OPC UA SDKs, OPC UA Clients can search and interpret this structural information."
Therefor, regarding data consistency, it is also important that your OPC-UA SDK (client) is modern enough to be able to "search and interpret this structural information".
The answer is provided by Flippo & Kevin in the above comments. So this will be a recap for everyone to quickly spot:
OPC UA guarantees atomicity only for simple types (Integer, Double Integer etc)
Longer structures' atomicity depends on the specific manufacturer.

how S7-1500 OPC UA server communicates with custom client

I'm little bit confused regarding how S7-1500 embeded OPC UA server communication works in case of a custom client installed on PC since all examples I've seen so far include a Simatic PC Station as OPC server!!!
On PLC side, I have S7-1511-1PN with OPC UA server activated. This PLC is connected over PROFINET to ET200SP+several AI modules.
On PC side (not Simatic PC Station), I have an application in which there is some kind of OPC UA client functionnality that reads inputs from AI modules, writes some tags on PLC and if necessary sends reconfiguration records of AI modules to PLC (reconfiguration via user program).
What I can't understand, is:
Why the Simatic PC station is always added as OPC server if the PLC already has this feature?
Does/How PLC OPC server communicates directly to my custom client? (Any programming needed on PLC)
For the certificates limitations as defined in "Function Manual, 10/2018, A5E03735815-AG (page 222)", what means "Max number of implementable server methods", "Max number of arguments", "Max number of server interfaces", "Max number of nodes in user-defined server interface", "Max size of loadable server interfaces"?
How can I estimated these numbers from my application?
(Yes/No) Do I need a second communication (TCP for example) between my PC application and PLC to send/receive reconfiguration data?
Why the Simatic PC station is always added as OPC server if the PLC already has this feature?
The SIMATIC PC station is not required. In the days before the S7-1500 PLC had a built in OPC UA server the only way to have an OPC UA server with data from the PLC was to use a SIMATIC PC station. A SIMATIC PC station is a computer running the SIMATIC NET software. The SIMATIC NET software can talk to the S7-1500 via an S7-Connection, the data it reads can be served to OPC UA/DA servers which are also part of the SIMATIC NET software.
Does/How PLC OPC server communicates directly to my custom client? (Any programming needed on PLC)
The OPC UA client must be on the same IP range as the PLC network interface. In the hardware configuration of the S7-1500 the OPC UA server is enabled. The OPC UA client is then pointed to the IP address of the S7-1500 PLC and using the OPC UA discovery will be able to read all the marker memory area, input and output memory area and data blocks. The OPC UA client will be able to subscribe to tags and write values if required.
EDIT: A router address can be set in PLC, so the client needs to be able to route to the PLC if on another subnet.
No programming is required in the S7-1500. In TIA Portal simply access the hardware configuration of the PLC and in the hardware settings there are options to enable the OPC UA server.
For the certificates limitations as defined in "Function Manual, 10/2018, A5E03735815-AG (page 222)", what means "Max number of implementable server methods", "Max number of arguments", "Max number of server interfaces", "Max number of nodes in user-defined server interface", "Max size of loadable server interfaces"?
In OPC UA it is possible to call methods. Methods can call function code from within the PLC logic. A method can be passed parameters and can return values. This is what the spec is refering to when it dicusses methods and maximum number of arguments. Each data point is considered to be a node in OPC UA, so this is explaining the maximum data points which can be read. As different PLC tags take up different amounts of memory the max size is the total size of all the nodes.
How can I estimated these numbers from my application?
This will be depending on the number of tags you wish to share from the OPC UA server. The update speed on the subscription and the amount of subscriptions allowed. There is no hard and fast method for calulcating this, it is very application dependant.
Do I need a second communication (TCP for example) between my PC application and PLC to send/receive reconfiguration data?
The OPC UA server can be configured to listen on any network interface of the S7-1500. There is no need for extra communication it is all part of the OPC UA protocol.
Siemens provide a nice application example with accompanying documentation which may help you get started. Download the documentation PDF from the link below.
https://support.industry.siemens.com/cs/us/en/view/109737901
Why the Simatic PC station is always added as OPC server if the PLC
already has this feature?
OPC UA has quite few advantages over other industrial communication protocol. The communication is/can be secure, the project is Open (Source available on GitHub, Specification are free), ...
Does/How PLC OPC server communicates directly to my custom client?
(Any programming needed on PLC)
The communication between your S7-1500 and your computer is an OPC UA End-to-End communication. I don't know the specification of the S7-1500 OPC UA Server neither your OPC UA Client but I guess they use OPC UA Binary over TCP
For the certificates limitations as defined in "Function Manual,
10/2018, A5E03735815-AG (page 222)", what means "Max number of
implementable server methods", "Max number of arguments", "Max number
of server interfaces", "Max number of nodes in user-defined server
interface", "Max size of loadable server interfaces"?
Your Configuration can contains OPC UA Methods. I guess there is some limit given by Siemens for the number of Methods. Same for the number of Arguments available in each Methods. There shall also be some limitation for the number of available Server interface in your controller.
How can I estimated these numbers from my application?
I am pretty sure you can find those limitation in your Siemens's PLC Manual ;)

OPC UA Historical Data Access - Event History

I would like to know if there is some currently available OPC UA Client supporting Historical Data Access, more precisely for Data AND Event History.
UA Expert from Unified Automation seems like to be one of the most advanced OPC UA Client, but it only supports historizing Data not Event.
I wonder if there is a better OPC UA Client that will do both.
You can use the SampleConsoleClient that comes as a sample with the Prosys OPC UA Java SDK (free evaluation version available) to read the data history of a variable (with HistoryRead in AccessLevel) and event history of an object node (with HistoryRead in EventNotifier).
The sample application comes with source so you can also modify the client to your needs.
Prosys OPC UA Java Client does not provide event history quite yet.
UPDATE: Prosys OPC UA Client provides an Event History view, too.
Actually UA Expert does show historical events. From the top menu go to Document -> Add -> Event View. And then drag and drop the Server node (for all events on the server) or any other node (for subset of events) from the Address space explorer into the configuration window of the event view. Then in the event history tab you'll be able to specify start and end date and retrieve the events.
Use Kepware KepServer EX V5 Simulation for the getting the live data on to the Client.
Just create the group and add the items.
If you are good in programming , connect it to OPC Server and get the live tag data