> 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-database-import-utility/import-rtu-log.md).

# Import an XL4 Plus RTU log

Import an XL4 Plus RTU log or archive log into the DATRAN database: export the site's nodes, make a map file, import the log, then upload it.

Under normal circumstances log information is directly transferred to DATRAN via a communications link and automatically added to the SQL Database for historical data logging. If the communications link is not available, then the log can also be retrieved from the RTU and stored as a log file by using the QTech Workbench utility. This file can then be imported into DATRAN using the Database Import Utility. This provides a secondary method of capturing valuable log information in the event of extended communications outages between DATRAN and the RTU.

{% hint style="info" %}
**Applies to:** Database Import Utility V1.04. Archive logs (firmware V7.19) need V1.04.
{% endhint %}

## Log formats

| Firmware         | Log format | RTU log holds                                                        |
| ---------------- | ---------- | -------------------------------------------------------------------- |
| V7.17 or earlier | V2         | About 64,000 records (0.5 MB)                                        |
| V7.18            | V3         | About 240,000 records (1.5 MB chip) or 880,000 records (5.5 MB chip) |
| V7.19            | V3         | As V7.18, plus an archive log of about 20 million records            |

It is quite possible that the log data does not cover the time period that the customer wants to know about. This is usually because the older data has already been overwritten in the (circular) RTU log in which case there is nothing to be done because the required data might already be lost. This is more likely to happen with 1 minute logged data unless the data is retrieved from the RTU quickly after the event which precipitated the need to collect it manually. See [Data logging and the archive log](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/data-logging.md).

## Step 1: retrieve the log

* **With QTech Workbench:** You will need a type A-B USB cable. Options include retrieving the log on a USB memory stick (V7.18 and later) or via the serial USB interface. See [Recover logged data manually](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/data-logging/recover-logged-data.md).
* **With XL4-Connect:** Retrieve the RTU Log or the Archive Log using XL4-Connect. You will need a LAN patch cable to connect the PC to a LAN socket or a Crossover patch cable to connect the PC directly to the RTU.

In both cases a log file will be created and stored on the PC. Log files are typically named `Datalogging.db` or something similar.

## Step 2: connect to the DATRAN database

See [Install and connect the Database Import Utility](https://help.qtech.co.nz/datran/datran-vi-scada/datran-database-import-utility/install.md#connect-to-the-datran-database).

## Step 3: export the site's nodes from DATRAN

The RTU references data points by their Data type and index. This datapoint relates to a site name (RTU), equipment name and data point in DATRAN. For example, the RTU log contains the raw data for a data point (e.g. RDI5 for Real Digital Input 5). In addition, the RTU data point will need to be scaled according to the formula before it can be logged into the SQL database. This is typically the case for analogue inputs.

1. In DATRAN Browser, select the site name under **Data Root**. Check that the site in DATRAN Browser matches the RTU by checking the RTU address in the comms object against the RTU address reported when Workbench is connected to the RTU to retrieve the log or inspect the configuration.
2. Right click and select **Export** from the pop-up menu.
3. Provide a name for the file (or simply leave it as `export.txt`). Ensure that relative pathnames are used and that the export starts at the current node.

## Step 4: create a map file

1. From the **File** menu click **New Mapping**, or if the main menu has no map file loaded, click the **Create** button.
2. Select **DB Binary File** as source file type.
3. Browse to select the exported nodes file (e.g. `export.txt`). Click the **Load nodes file** button to load the TBD nodes into the application.
4. Browse the site (or sites) that are in the TBD nodes list and select the site that you want to import into DATRAN. When you select a site it lists the telemetry datapoints declared in the comms object that are available for importing data. If the data point is not listed (named), then the RTU does not have the data point mapped in DATRAN.
5. New versions of the Import utility include an optional setting to apply a rule for analogue value scaling. When the checkbox is ticked, then all the scaling parameters must be present (e.g. `0,65535,0,65535`). The rule is enforced to disallow implicit defaults and make them explicit, and will throw an error if an analogue value has no scaling factors or only some.
6. Click the **Save mapping** button to save the selected site (and all the nodes associated) into a "map" file saved to disk. Once the map file has been created and saved, click **Close** to return to the main window.

## Step 5: import the log

1. If it is not already listed as the current map file, then from the main window select the map file by clicking the **Browse** button and navigating to the file created in the previous step. Click **Open** to load the file into the application.
2. Click the **Browse** button to navigate to the log file saved from Workbench and open it. Only one log file can be imported at a time.
3. Click the **Import** button to commence the import process. Progress will be shown in the **Status Report** field. The importer will map the raw data in the log file to the database point identifier in the SQL database and will also scale the data according to the scaling formula.

Errors are displayed on the screen and also logged to a text log file for inspection (click the **Error Log** button). Errors or warnings may occur if there is no valid point data in the DATRAN TBD structure associated with the Raw datapoint logged by the RTU. Errors can also occur if the raw data cannot be correctly scaled. The import process can be cancelled at any time by clicking the **Cancel** button.

## Step 6: check or upload

| Option                   | What it does                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Export CSV**           | The imported data can be exported to a human readable format (CSV) which can be edited in a spreadsheet or text editor. This option is useful for inspecting the data and removing superfluous records such as records with odd timestamps or null records. Thereafter the edited file can be imported into the SQL Server database using Microsoft SQL Server Management Studio or similar tools. The CSV file lists each record on a new row. |
| **Upload to SQL Server** | Uploads the data to the DATRAN SQL Server Database                                                                                                                                                                                                                                                                                                                                                                                              |

If there are points in the log that are not named points (have an equivalent PointID) in the DatranDatabase then the user will be warned and can choose to ignore them or to create points in the Database using a generic name based on the point type (RAI, RDI etc) and the site name. Choosing **Yes** will create the file and map the points. Choosing **No** will create the file and ignore the points. When importing unconfigured points, the naming convention matches HDI.

![The prompt for logged points that aren't in the map](https://3621580088-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5hMAUl7E1cWeN5Rghg0%2Fuploads%2Fytpq1pVST1k6tw18F9mM%2Fdiu-point-mapping-error.png?alt=media)

## Step 7: check the data

* **In DATRAN Trending:** Commonly the DATRAN Trending application is used to graph the data and validate that the log was successfully imported. Create a new plot or simply add a new pen and select from the points labelled per the site. Use the time cursors to check for data in the required time period. See [Set up pens](https://help.qtech.co.nz/datran/datran-vi-scada/datran-trending/pens.md).
* **In SQL Server Management Studio:** Microsoft SQL Server Management Studio can be used to run queries to view data on the DATRAN Database (usually the `tblAnalog` table which holds the analogue data or the `tblDigital` table for discrete digital I/O). See [Check that data is being logged](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/sql-server.md#check-that-data-is-being-logged).

If the data isn't there, see [Imported data doesn't show in Trending](https://help.qtech.co.nz/datran/datran-vi-scada/datran-database-import-utility/troubleshooting/data-not-in-trending.md).
