---
title: "Save the mastering data ($DMR_GRP)"
description: "Read $DMR_GRP[1].$MASTER_COUN and the reference counts of every Fanuc robot from sysmast.va, and keep them with a date before a battery or a motor change."
---

# Save the mastering data ($DMR_GRP)

Before a battery change or a motor change on a Fanuc robot, you want the master counts at hand. Integrators often record them on every robot they work on, as a first step. The SDK reads them from `sysmast.va` of every robot and keeps them with a date.

This page only reads the mastering data. Mastering a robot is done on the teach pendant, by a qualified person, with the method of the FANUC manual of your robot.

## The variables

| Variable | Type | Meaning | File |
| --- | --- | --- | --- |
| `$DMR_GRP[g].$MASTER_COUN[a]` | INTEGER | Master count of axis a of group g | `sysmast.va` |
| `$DMR_GRP[g].$MASTER_DONE` | BOOLEAN | Mastering done | `sysmast.va` |
| `$DMR_GRP[g].$REF_POS[a]`, `$REF_COUNT[a]` | REAL, INTEGER | Reference position and reference count of axis a | `sysmast.va` |
| `$DMR_GRP[g].$REF_DONE` | BOOLEAN | Reference position done | `sysmast.va` |

An axis without a motor reads 0. The SDK gives these values with `GetSysmastFile().DmrGrp[g - 1]`: `MasterCoun`, `MasterDone`, `RefPos`, `RefCount`, `RefDone`.

## Keep the mastering data of a robot

The code keeps a dated copy of `sysmast.va`, as it is, then prints the counts of group 1. Run it on each robot of the plant, for example once a week, and keep the files.

**C# : MasteringData**
```csharp
using System;
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Common.Files.Variables;

public class MasteringData
{
    static void Main()
    {
        string ip = "192.168.0.1";
        FanucRobot robot = new FanucRobot();
        var parameters = new ConnectionParameters(ip);
        parameters.Ftp.Enable = true;
        robot.Connect(parameters);

        /**/
        // Keep the listing of the robot with the date, as it is
        robot.Ftp.DirectFileHandling.DownloadFileFromController($"{ip}-{DateTime.Now:yyyy-MM-dd}-sysmast.va", "md:/sysmast.va");

        // Read it: $DMR_GRP[1] is DmrGrp[0], axis 1 is index 0
        SysmastFile mastering = robot.Ftp.KnownVariableFiles.GetSysmastFile();
        DmrGrpVariableType group1 = mastering.DmrGrp[0];
        Console.WriteLine($"MASTER_DONE={group1.MasterDone} REF_DONE={group1.RefDone}");
        for (int a = 0; a < group1.MasterCoun.Length; a++)
            Console.WriteLine($"J{a + 1}: MASTER_COUN={group1.MasterCoun[a]} REF_COUNT={group1.RefCount[a]}");
        /**/
    }
}
```

**Python : MasteringData**
```python
from datetime import date

from underautomation.fanuc.fanuc_robot import FanucRobot
from underautomation.fanuc.connection_parameters import ConnectionParameters

ip = "192.168.0.1"
robot = FanucRobot()
parameters = ConnectionParameters(ip)
parameters.ftp.enable = True
robot.connect(parameters)

##
# Keep the listing of the robot with the date, as it is
robot.ftp.direct_file_handling.download_file_from_controller(f"{ip}-{date.today()}-sysmast.va", "md:/sysmast.va")

# Read it: $DMR_GRP[1] is dmr_grp[0], axis 1 is index 0
mastering = robot.ftp.known_variable_files.get_sysmast_file()
group1 = mastering.dmr_grp[0]
print(f"MASTER_DONE={group1.master_done} REF_DONE={group1.ref_done}")
for a, (count, ref) in enumerate(zip(group1.master_coun, group1.ref_count), start=1):
    print(f"J{a}: MASTER_COUN={count} REF_COUNT={ref}")
##
```

The .NET and Python arrays start at 0: `$DMR_GRP[1]` is `DmrGrp[0]` and axis J1 is index 0.

A copy taken before the intervention is the one that counts. Compare it with an older copy: when the counts differ, the robot was probably mastered again in between.

## When the old counts are useful

- The pulse coders lost their power (flat battery) and nothing moved mechanically: the technician can use the recorded counts, with the procedure of the manual.
- A motor or a pulse coder was changed: the old counts are no longer valid. The robot must be mastered again.

## Cautions

- `sysmast` belongs to one robot. Never load the `sysmast` file of another robot: the axes of this robot would lose their calibration.
- `sysmast` holds more than the counts. Keep the whole file, not only the numbers printed by the code.
- The SDK reads the `.va` listing. A pendant backup with only `.sv` files cannot be read on the PC: download `sysmast.va` by FTP, as the code does.

## Without code

[TouchUp](/touchup), the robot workbench for VS Code, keeps the mastering values of each Fanuc backup that holds a readable `sysmast.va`. The command `TouchUp: Show Mastering (Fanuc)` shows the master count, the reference position and the reference count of each axis from the last backup, with its date. TouchUp only reads them: it never writes the mastering of a robot. See [Mastering of a Fanuc robot](/touchup/documentation/backup#mastering-of-a-fanuc-robot).

## See also

- [Fanuc system variables list](/fanuc/documentation/fanuc-system-variables-list)
- [Upload, download & backup files](/fanuc/documentation/upload-download-backup-files)
- [Offline file parsing](/fanuc/documentation/offline-file-parsing)