> For the complete documentation index, see [llms.txt](https://docs.cybus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cybus.io/2-4-2/guides/machine-connectivity/cnc-machine-tools/connecting-a-sinumerik-cnc-control.md).

# Connecting a SINUMERIK CNC Control

This guide shows you how to read machine, spindle, and tool data from a Siemens SINUMERIK CNC control with the Connectware [SINUMERIK connector](/2-4-2/connectors/shop-floor-connectors/sinumerik.md) and map it into an ISA-95 style MQTT topic hierarchy. The connector supports SINUMERIK 840D sl and 828D CNC systems and acts as a client for the SINUMERIK "Access MyMachine / OPC UA" machine interface. The data collected here (program name and status, spindle speed and feed, and the tools loaded in the magazines) is the typical input for machine monitoring, OEE dashboards, and tool management applications. In more detail, the following topics are covered:

* Understanding how the SINUMERIK connector addresses data through driver methods
* Preparing the OPC UA interface on the SINUMERIK
* Choosing the driver methods and polling intervals
* Creating the [service commissioning file](/2-4-2/data-flows/service-commissioning-files.md)
* Mapping the data into an ISA-95 style MQTT topic hierarchy
* Reading tool details on demand with the request/response pattern
* Verifying data in the [Data Explorer](/2-4-2/monitoring/data-explorer.md)

This guide focuses on reading data from the machine. For the complete method catalog, including tool creation, magazine management, and file system access, see the [SINUMERIK connector reference](/2-4-2/connectors/shop-floor-connectors/sinumerik.md#sinumerik-methods).

A complete example file is available at the end of this guide.

## Prerequisites

To follow this guide, you will need the following:

* A running instance of Cybus Connectware.
* A Siemens SINUMERIK 840D sl or 828D CNC system that is reachable over Ethernet from Connectware. The machine requires SINUMERIK Operate, a SINUMERIK OPC UA license, and a compatible OPC UA server version. For the machine-side prerequisites, compatibility, and setup, see the [SINUMERIK Access MyMachine / OPC UA Configuration Manual](https://cache.industry.siemens.com/dl/files/643/109772643/att_1001368/v1/840Dsl_828D_OPCUA_config_man_0819_en-US.pdf).
* The username and password of an OPC UA user configured on the SINUMERIK.
* Access to the [Admin UI](/2-4-2/access/admin-ui.md) with sufficient [user permissions](/2-4-2/access/user-management.md).
* Basic knowledge of MQTT and the Connectware [services](/2-4-2/data-flows/services.md) concept (for example, [service commissioning files](/2-4-2/data-flows/service-commissioning-files.md), [connections](/2-4-2/data-flows/service-commissioning-files/resources/cybus-connection.md), and [endpoints](/2-4-2/data-flows/service-commissioning-files/resources/cybus-endpoint.md)).

## How the SINUMERIK Connector Addresses Data

Connectors such as Modbus/TCP or S7 address individual registers or variables. The SINUMERIK connector works differently: it provides a set of driver methods, and each method is a remote procedure call that bundles related NC data into one structured result. For example, `getMachineState` returns the active program name, the program status, and the machine runtime in a single object, and `getTool` returns the complete essential configuration of one tool. You do not assemble NC variable addresses yourself; the driver maps each method to the underlying SINUMERIK data internally.

An endpoint combines one method with one mode of operation:

* **Polling subscription** (`subscribe` with type `poll`): Connectware calls the method in a fixed interval and publishes the result. This is the right mode for continuous monitoring and is the main pattern in this guide.
* **Read and write** (`read` or `write`): Connectware exposes a request/response pattern over MQTT, following the JSON-RPC 2.0 specification. This is the right mode for methods that take parameters, such as reading one specific tool.
* **Notify subscription** (`subscribe` with type `notify`): the driver fires an event when something changes on the machine, for example `onNcProgramChanged`.

{% hint style="warning" %}
The notify subscription is highly unstable and can crash the OPC UA server on the machine. Use polling subscriptions instead, as this guide does. For details, see [Notify Subscription](/2-4-2/connectors/shop-floor-connectors/sinumerik.md#notify-subscription).
{% endhint %}

Each driver method requires certain access rights on the SINUMERIK. The driver automatically sets the required OPC UA access rights for the connected OPC UA user, so the user must be allowed to change its own access rights. You can inspect the current rights with the `getMyAccessRights` method.

## Choosing the Driver Methods

This guide polls a set of methods that cover the most common machine monitoring needs. The polling interval is a trade-off between data freshness and load on the machine's OPC UA server: fast-changing process values get short intervals, while static information and slowly changing lists get long ones.

| Method                | Data                                                       | Poll interval |
| --------------------- | ---------------------------------------------------------- | ------------: |
| `getMachineInfo`      | Static machine information such as the NC type and version |      60000 ms |
| `getMachineState`     | Program name, program status, power-on state, and runtime  |       5000 ms |
| `getSpindleSpeed`     | Actual and commanded spindle speed                         |       2000 ms |
| `getSpindleFeed`      | Actual and commanded constant cutting rate                 |       2000 ms |
| `getToolsInMagazines` | Tool numbers in all magazine places of all magazines       |      10000 ms |

The minimum polling interval is 1000 ms. For all endpoint properties, see [Sinumerik Endpoint Properties](/2-4-2/connectors/shop-floor-connectors/sinumerik/sinumerikendpoint.md).

## Writing the Service Commissioning File

The service commissioning file contains all connection and mapping details. Do not worry about copying the snippets together into one file, the complete example file is available at the end of this guide.

### Description and Metadata

These sections contain general information about the service commissioning file. Only the metadata name is required.

{% code lineNumbers="true" %}

```yaml
description: >
  Service commissioning file that reads machine, spindle, and tool data from
  a Siemens SINUMERIK CNC control with the SINUMERIK connector and maps it
  into an ISA-95 style MQTT topic hierarchy (Example)

metadata:
  name: SINUMERIK CNC Control Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0
```

{% endcode %}

### Parameters and Definitions

We define the network address and the credentials of the machine as parameters, so you can set them when you install the service. The default OPC UA port is 4840.

The MQTT topics in this guide follow an ISA-95 style equipment hierarchy (`<enterprise>/<site>/<area>/<line>/<work-cell>`). We define the prefix once in the `definitions` section and reuse it in every mapping with `!sub`.

{% code lineNumbers="true" %}

```yaml
parameters:
  sinumerikHost:
    description: Hostname or IP address of the SINUMERIK OPC UA server
    type: string
    default: 192.168.1.100

  sinumerikPort:
    description: Port of the SINUMERIK OPC UA server
    type: integer
    default: 4840

  sinumerikUsername:
    description: Username of the SINUMERIK OPC UA user
    type: string
    default: ''

  sinumerikPassword:
    description: Password of the SINUMERIK OPC UA user
    type: string
    default: ''

definitions:
  MQTT_TOPIC_PREFIX: enterprise/hamburg/machining/line-1/cnc-01
```

{% endcode %}

### Cybus::Connection

The connection resource establishes the connection to the "Access MyMachine / OPC UA" interface of the machine. The SINUMERIK driver uses the Connectware OPC UA driver implementation, so the OPC UA connection settings, including security options and the `connectionStrategy` retry behavior, apply here as well. For all connection properties, see [Sinumerik Connection Properties](/2-4-2/connectors/shop-floor-connectors/sinumerik/sinumerikconnection.md).

{% code lineNumbers="true" %}

```yaml
resources:
  sinumerikConnection:
    type: Cybus::Connection
    properties:
      protocol: Sinumerik
      targetState: connected
      connection:
        host: !ref sinumerikHost
        port: !ref sinumerikPort
        username: !ref sinumerikUsername
        password: !ref sinumerikPassword
```

{% endcode %}

### Cybus::Endpoint

Each endpoint polls one driver method. The `method` property selects the driver method, and `pollInterval` sets the polling frequency in milliseconds according to the table in [Choosing the Driver Methods](#choosing-the-driver-methods).

{% code lineNumbers="true" %}

```yaml
machineInfo:
  type: Cybus::Endpoint
  properties:
    protocol: Sinumerik
    connection: !ref sinumerikConnection
    subscribe:
      type: poll
      method: getMachineInfo
      pollInterval: 60000

machineState:
  type: Cybus::Endpoint
  properties:
    protocol: Sinumerik
    connection: !ref sinumerikConnection
    subscribe:
      type: poll
      method: getMachineState
      pollInterval: 5000

spindleSpeed:
  type: Cybus::Endpoint
  properties:
    protocol: Sinumerik
    connection: !ref sinumerikConnection
    subscribe:
      type: poll
      method: getSpindleSpeed
      pollInterval: 2000

spindleFeed:
  type: Cybus::Endpoint
  properties:
    protocol: Sinumerik
    connection: !ref sinumerikConnection
    subscribe:
      type: poll
      method: getSpindleFeed
      pollInterval: 2000

toolsInMagazines:
  type: Cybus::Endpoint
  properties:
    protocol: Sinumerik
    connection: !ref sinumerikConnection
    subscribe:
      type: poll
      method: getToolsInMagazines
      pollInterval: 10000
```

{% endcode %}

### Cybus::Mapping

The mapping publishes each endpoint on a topic of the ISA-95 hierarchy.

{% code lineNumbers="true" %}

```yaml
mapping:
  type: Cybus::Mapping
  properties:
    mappings:
      - subscribe:
          endpoint: !ref machineInfo
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/machine/info'
      - subscribe:
          endpoint: !ref machineState
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/machine/state'
      - subscribe:
          endpoint: !ref spindleSpeed
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/spindle/speed'
      - subscribe:
          endpoint: !ref spindleFeed
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/spindle/feed'
      - subscribe:
          endpoint: !ref toolsInMagazines
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/tools/magazines'
```

{% endcode %}

With this mapping, the machine state is published on the topic `enterprise/hamburg/machining/line-1/cnc-01/machine/state`, and every other method result follows the same pattern.

## Reading Tool Details on Demand

Methods that take parameters, such as `getTool` with a tool number, fit the request/response pattern better than polling. An endpoint with the `read` operation subscribes to a request topic ending in `req` and publishes the result on the corresponding response topic ending in `res`:

{% code lineNumbers="true" %}

```yaml
getTool:
  type: Cybus::Endpoint
  properties:
    protocol: Sinumerik
    connection: !ref sinumerikConnection
    read:
      method: getTool
```

{% endcode %}

To read tool number 1, publish the following payload on the request topic. The `id` is a user-defined correlation ID that identifies the response, and `params` holds the method parameters in order:

{% code lineNumbers="true" %}

```json
{ "id": 1, "params": ["1"] }
```

{% endcode %}

The response on the `res` topic contains the essential tool configuration under the `result` key, including the tool identifier, tool type, lengths, radius, and the magazine and place where the tool is loaded. If the call fails, the response carries an `error` key instead. For a complete request/response walkthrough with example payloads, see the [Examples](/2-4-2/connectors/shop-floor-connectors/sinumerik.md#examples) section of the connector reference.

## Installing the Service Commissioning File

1. Install the service commissioning file. See [Installing Services](/2-4-2/data-flows/services/managing/installing.md).
2. Enable the service. See [Enabling Services](/2-4-2/data-flows/services/managing/enabling.md).

**Result:** The service is enabled. Connectware connects to the OPC UA interface of the SINUMERIK and starts polling the configured methods.

## Verifying the Data

Open the [Data Explorer](/2-4-2/monitoring/data-explorer.md) and subscribe to `enterprise/hamburg/machining/line-1/cnc-01/#`. Each topic carries a JSON object with the keys `timestamp` and `value`, where the value holds the return object of the driver method. For example, the spindle speed:

{% code lineNumbers="true" %}

```json
{
  "timestamp": 1784194200354,
  "value": {
    "actualSpeed": "1200",
    "commandSpeed": "1200"
  }
}
```

{% endcode %}

A few plausibility checks for the first readings:

* The `progName` on the `machine/state` topic matches the NC program selected on the SINUMERIK Operate HMI.
* The `actualSpeed` on the `spindle/speed` topic is 0 while the spindle is stopped and follows the commanded value while machining.
* The `poweronTime` on the `machine/state` topic (machine runtime in minutes) only increases over time.
* The tool numbers on the `tools/magazines` topic match the tool list on the HMI, with 0 for empty magazine places.

If the connection does not reach the **Connected** state, verify that the OPC UA server on the SINUMERIK is running and licensed, that the port is reachable from Connectware, and that the username and password match the OPC UA user on the machine. If the connection is established but method calls fail, check that the OPC UA user is allowed to change its own access rights, because the driver sets the required access rights for each method automatically. The `getMyAccessRights` method shows the rights currently granted to the user.

## Service Commissioning File Example

{% file src="/files/WuOJz3QgiP8OewYd4iCi" %}

{% code title="sinumerik-example.yml" lineNumbers="true" expandable="true" %}

```yaml
---
# ----------------------------------------------------------------------------
# Service Commissioning File
# ----------------------------------------------------------------------------
# Copyright: Cybus GmbH
# Contact: support@cybus.io
# ----------------------------------------------------------------------------
# Connecting a SINUMERIK CNC Control (Example)
# ----------------------------------------------------------------------------

description: >
  Service commissioning file that reads machine, spindle, and tool data from
  a Siemens SINUMERIK CNC control with the SINUMERIK connector and maps it
  into an ISA-95 style MQTT topic hierarchy (Example)

metadata:
  name: SINUMERIK CNC Control Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  sinumerikHost:
    description: Hostname or IP address of the SINUMERIK OPC UA server
    type: string
    default: 192.168.1.100

  sinumerikPort:
    description: Port of the SINUMERIK OPC UA server
    type: integer
    default: 4840

  sinumerikUsername:
    description: Username of the SINUMERIK OPC UA user
    type: string
    default: ''

  sinumerikPassword:
    description: Password of the SINUMERIK OPC UA user
    type: string
    default: ''

definitions:
  # ISA-95 style topic prefix: <enterprise>/<site>/<area>/<line>/<work-cell>
  MQTT_TOPIC_PREFIX: enterprise/hamburg/machining/line-1/cnc-01

resources:
  # Connection to the SINUMERIK "Access MyMachine / OPC UA" interface
  sinumerikConnection:
    type: Cybus::Connection
    properties:
      protocol: Sinumerik
      targetState: connected
      connection:
        host: !ref sinumerikHost
        port: !ref sinumerikPort
        username: !ref sinumerikUsername
        password: !ref sinumerikPassword

  # Static machine information: NC type, NC version, HMI language
  machineInfo:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: getMachineInfo
        pollInterval: 60000

  # Machine state: program name, program status, power-on state, runtime
  machineState:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: getMachineState
        pollInterval: 5000

  # Actual and commanded spindle speed
  spindleSpeed:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: getSpindleSpeed
        pollInterval: 2000

  # Actual and commanded constant cutting rate
  spindleFeed:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: getSpindleFeed
        pollInterval: 2000

  # Tool numbers in all magazine places (0 = no tool loaded)
  toolsInMagazines:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: getToolsInMagazines
        pollInterval: 10000

  # On-demand tool read with the request/response pattern:
  # tool = getTool(toolNo)
  getTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getTool

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref machineInfo
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/machine/info'
        - subscribe:
            endpoint: !ref machineState
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/machine/state'
        - subscribe:
            endpoint: !ref spindleSpeed
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/spindle/speed'
        - subscribe:
            endpoint: !ref spindleFeed
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/spindle/feed'
        - subscribe:
            endpoint: !ref toolsInMagazines
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/tools/magazines'
```

{% endcode %}

{% hint style="info" %}
Disclaimer: SINUMERIK and SINUMERIK Operate are trademarks of Siemens AG.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cybus.io/2-4-2/guides/machine-connectivity/cnc-machine-tools/connecting-a-sinumerik-cnc-control.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
