> For the complete documentation index, see [llms.txt](https://help.qtech.co.nz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.qtech.co.nz/datran/datran-vi-scada/datran-opc-ua-server/install.md).

# Install and configure the OPC UA Server

Install the DATRAN OPC UA Server, set its connection to DATRAN in the XML settings file, run it as a Windows service, and set up certificates.

The DATRAN VI OPC UA Server is used as an interface for 3rd party applications using OPC UA clients to communicate with DATRAN VI.

{% hint style="info" %}
**Applies to:** DATRAN OPC UA Server V1.4 and V1.5. Please read this page fully before commencing installation.
{% endhint %}

## Install

1. Please log in to the Software Maintenance Agreement (SMA) holder section of the QTech website to download this software.
2. Run the installer; it will be similar to `DATRAN OPC UA Server Setup – v1.5.exe`. It adds a Start Menu shortcut in the Datran VI folder.

## Set the connection to DATRAN

Open the configuration file `OpcUAServer.exe.config`. This is an XML text file and will be in the installed directory. By default this is `C:\Program Files\QTech\DATRAN OPC UA Server`. Find the `<applicationSettings>` section and set:

| Setting                | What to enter                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `server`               | Set the IP address of the Datran computer the OPC UA Server is going to connect to. If Datran and OPC UA server are running on the same computer then the local host address of `127.0.0.1` can be used.                                                                                                                                                                                                          |
| `port`                 | Set the port to be used for communication with Datran TCPServer service, for example 13001 (this is the default setting). This port number must be the same as the port number used in Datran. You find it in the Datran configuration under the computer's **TCP Server > Properties > TCP Port**. If Datran has the default port of 13001 then this property will appear under **Properties > Default**.        |
| `username`, `password` | Set the username and password to be used to logon to the Datran TCPServer service. However this logon is currently not enforced, normally this would be any Operator logon as specified in the DATRAN VI Operator list. You may wish to create one specifically for OPCUA. Credentials used to connect to DATRAN TCP Server are only required by OPC UA Server to write data to the TreeBase, not for connecting. |

Each setting looks like this:

```xml
<setting name="server" serializeAs="String">
  <value>127.0.0.1</value>
</setting>
```

Optionally set the port for the OPC UA server to connect to clients, for example 48030 (this is the default setting, only change it if you need to). Find the section with the tag `<UaApplicationConfiguration>` then further down `<BaseAddresses>`. The default is `opc.tcp://localhost:48030`.

Save the file. If the configuration of the DATRAN VI connection is changed (address, port, etc.) the OPC-UA Server must be restarted to make the changes effective.

## Run it as a Windows service

The proper way to run the OPC UA Server is as a Windows Service; it is possible to install the server as a service by specifying the /install parameter from a command line prompt:

```
OpcUAServer.exe /install
```

What this invocation does is:

* Stops any existing Datran OPC-UA service (uses the name DATRAN-OPC-UA, which is specified in the .config file, parameter ServiceName)
* Eventually creates a new service
* Configures the Windows Firewall exceptions (allows incoming packet to the inbound port for the application specified on the command line -- that is OpcUAServer.exe)

It is also possible to uninstall the service specifying the /uninstall parameter from a command line prompt: `OpcUAServer.exe /uninstall`. This invocation stops any existing Datran OPC-UA service and removes it from the Windows Services.

For systems using QTech OPC UA Server with HMIs such as Intouch we recommend restarting DATRAN services in the following order: DATRAN > OPC UA Server > OI Gateway > Intouch. See [Backup, restart and disaster recovery](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/backup-and-restart.md).

## Run it as a program for testing

The server can be run as an application, especially for testing and debugging purposes, by just double clicking the `.exe` file. In this case a GUI (Graphical User Interface) comes up with a "tabbed" view; the most interesting tabs are:

* **Endpoints:** lists the endpoints (listening sockets) of the server with all their attributes: url (that is protocol, address and port number), status (Good or not), Security Policy (secure or plain connections available) etc.
* **Datran:** lists the attributes (address, port, login credentials) and the status of the connection to the Datran TCP Server

## Test with an OPC UA client

If UAExpert is running on the same machine as OPCUA server then the server endpoint can be defined as localhost (not a full URL). Otherwise you can use the computername e.g. `opc.tcp://<computer name>:48030`.

It is important that the credentials are verified after the installation by performing some dummy writes to DATRAN TreeBase – e.g. change a node value from an OPC UA Client and verify that such change is retained, if the credentials are wrong the node retains its original value. See [User does not exist, or writes from the client don't stick](https://help.qtech.co.nz/datran/datran-vi-scada/datran-opc-ua-server/troubleshooting/user-does-not-exist.md).

## Certificates

It is possible to work without certificates; certificates are needed, though, to create secure connections between clients and the OPC UA Server.

The OPC-UA Server can create its own certificates (self-signed) if the OPC Foundation tool `Opc.Ua.CertificateGenerator.exe` is available somewhere in the system path or in the same folder as the executable or some system path. QTech provides such tool with the release and installing it in the same folder as the OPC-UA server executable file.

The location of the stored certificates is specified in the configuration file; the typical location is under the folder `%CommonApplicationData%\QTech Data Systems Ltd\OPC-UA Server\pkiserver` and the certificates are sorted into different folders according to their origin (own, trusted, etc.). The actual location depends on some system settings; as an example, in recent versions of Windows the %CommonApplicationData% folder maps to `C:\ProgramData`.

## Logs

The log file is located at `C:\ProgramData\QTech\DATRAN OPC UA Server\logs\OPCUAServer.txt`. Note that timestamps in the log file are UTC.
