> 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-fanuc-cnc-via-focas.md).

# Connecting a FANUC CNC via FOCAS

This guide shows you how to read machine status, program, spindle, and feed data from a FANUC CNC control with the Connectware [FOCAS connector](/2-4-2/connectors/shop-floor-connectors/focas.md) and map it into an ISA-95 style MQTT topic hierarchy. FOCAS is FANUC's library-based interface for accessing CNC data over Ethernet (FOCAS1/FOCAS2) and is available for common FANUC series such as the 30i/31i/32i and 0i series. The data collected here (run state, executed program, feed rate, spindle speed, and spindle load) is the typical input for machine monitoring, OEE dashboards, and condition monitoring applications. In more detail, the following topics are covered:

* Understanding how the FOCAS connector addresses data through driver methods
* 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 data 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. The connector can also write NC programs to the controller with the `program_download` method. For the complete method catalog, see the [FOCAS connector reference](/2-4-2/connectors/shop-floor-connectors/focas.md#focas-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 FANUC CNC control that is reachable over Ethernet from Connectware. The machine requires the FOCAS Ethernet function, which is an option on many machines. Your machine tool builder or FANUC can confirm whether it is installed on your control and provide the FANUC FOCAS documentation. The FOCAS interface listens on TCP port 8193 by default.
* 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 FOCAS Connector Addresses Data

Connectors such as Modbus/TCP or S7 address individual registers or variables. The FOCAS connector works differently: it provides a set of driver methods, and each method corresponds to a function of the FOCAS library that returns related CNC data as one structured JSON object. For example, `cnc_statinfo2` returns the automatic mode, run state, motion, alarm, and emergency stop information in a single result, and `cnc_rdspeed` returns the actual feed rate and the actual spindle speed together. You do not assemble memory addresses yourself; the driver maps each method to the underlying CNC data internally. The exception is `pmc_rdpmcrng`, which reads a Programmable Machine Controller (PMC) address range that you specify.

An endpoint combines one method with one mode of operation:

* **Subscribe**: Connectware calls the method in a fixed interval, or on a cron schedule, and publishes the result. This is the right mode for continuous monitoring and is the main pattern in this guide.
* **Read**: Connectware exposes a request/response pattern over MQTT. A message on the endpoint's request topic triggers one method call, and the result is published on the response topic. This is the right mode for data that you only need on demand.

Some methods require additional properties on the endpoint, for example the spindle number for `cnc_rdspload` or the data type selection for `cnc_rdspeed`. For all endpoint properties, see [Focas Endpoint Properties](/2-4-2/connectors/shop-floor-connectors/focas/focasendpoint.md).

## Choosing the FOCAS 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 control: fast-changing process values get short intervals, while static information gets long ones. The minimum polling interval is 500 ms.

| Method           | Data                                                                            | Poll interval |
| ---------------- | ------------------------------------------------------------------------------- | ------------: |
| `cnc_sysinfo`    | Static system information such as the CNC type, series, version, and axis count |      60000 ms |
| `cnc_statinfo2`  | Status information such as mode, run state, motion, alarm, and emergency stop   |       3000 ms |
| `cnc_exeprgname` | Full path name of the program which is currently being executed                 |       5000 ms |
| `cnc_rdspeed`    | Actual feed rate and actual rotational speed of the main spindle                |       2000 ms |
| `cnc_rdspload`   | Load information of the serial spindle                                          |       2000 ms |

The connector provides further methods, for example `cnc_rdprgnum` for the selected program number, `cnc_rdgcode` for the commanded G code, `cnc_rdopnlsgnl` for the signals of the software operator's panel, and `pmc_rdpmcrng` for PMC data. For the full list with example outputs, see [FOCAS Methods](/2-4-2/connectors/shop-floor-connectors/focas.md#focas-methods).

## 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 status, program, spindle, and feed
  data from a FANUC CNC control with the FOCAS connector and maps it into
  an ISA-95 style MQTT topic hierarchy (Example)

metadata:
  name: FANUC FOCAS Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0
```

{% endcode %}

### Parameters and Definitions

We define the network address of the machine as parameters, so you can set them when you install the service. The default FOCAS port is 8193.

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:
  focasHost:
    description: Hostname or IP address of the FANUC CNC
    type: string
    default: 192.168.1.100

  focasPort:
    description: TCP port of the FOCAS Ethernet interface
    type: integer
    default: 8193

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

{% endcode %}

### Cybus::Connection

The connection resource establishes the connection to the FOCAS Ethernet interface of the CNC. FOCAS does not use a username or password; the host and port are sufficient. If a connection attempt fails, the connector retries with an increasing delay that you can tune with the `connectionStrategy` property. For all connection properties, see [Focas Connection Properties](/2-4-2/connectors/shop-floor-connectors/focas/focasconnection.md).

{% code lineNumbers="true" %}

```yaml
resources:
  focasConnection:
    type: Cybus::Connection
    properties:
      protocol: Focas
      targetState: connected
      connection:
        host: !ref focasHost
        port: !ref focasPort
```

{% endcode %}

### Cybus::Endpoint

Each endpoint polls one driver method. The `method` property selects the driver method, and `interval` sets the polling frequency in milliseconds according to the table in [Choosing the FOCAS Methods](#choosing-the-focas-methods). Two of the endpoints carry method-specific properties: `dataType: -1` makes `cnc_rdspeed` return the feed rate and the spindle speed in one call, and `spindleNumber` selects the spindle that `cnc_rdspload` reads.

{% code lineNumbers="true" %}

```yaml
systemInfo:
  type: Cybus::Endpoint
  properties:
    protocol: Focas
    connection: !ref focasConnection
    subscribe:
      method: cnc_sysinfo
      interval: 60000

statusInfo:
  type: Cybus::Endpoint
  properties:
    protocol: Focas
    connection: !ref focasConnection
    subscribe:
      method: cnc_statinfo2
      interval: 3000

executedProgramName:
  type: Cybus::Endpoint
  properties:
    protocol: Focas
    connection: !ref focasConnection
    subscribe:
      method: cnc_exeprgname
      interval: 5000

feedAndSpindleSpeed:
  type: Cybus::Endpoint
  properties:
    protocol: Focas
    connection: !ref focasConnection
    subscribe:
      method: cnc_rdspeed
      dataType: -1
      interval: 2000

spindleLoad:
  type: Cybus::Endpoint
  properties:
    protocol: Focas
    connection: !ref focasConnection
    subscribe:
      method: cnc_rdspload
      spindleNumber: 1
      interval: 2000
```

{% 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 systemInfo
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/machine/info'
      - subscribe:
          endpoint: !ref statusInfo
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/machine/status'
      - subscribe:
          endpoint: !ref executedProgramName
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/program/name'
      - subscribe:
          endpoint: !ref feedAndSpindleSpeed
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/process/speed'
      - subscribe:
          endpoint: !ref spindleLoad
        publish:
          topic: !sub '${MQTT_TOPIC_PREFIX}/spindle/load'
```

{% endcode %}

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

## Reading Data on Demand

Data that you only need occasionally does not have to be polled. 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
systemInfoOnDemand:
  type: Cybus::Endpoint
  properties:
    protocol: Focas
    connection: !ref focasConnection
    read:
      method: cnc_sysinfo
```

{% endcode %}

Publish a message on the request topic to trigger one method call. You can include a correlation `id` in the request payload to match responses to specific requests; the response carries the same `id`.

## 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 FOCAS interface of the CNC 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-02/#`. Each topic carries a JSON object with a `timestamp` and a `value` key, where the value holds the result object of the driver method. For example, the feed rate and spindle speed:

{% code lineNumbers="true" %}

```json
{
  "id": 1,
  "timestamp": 1784194200354,
  "value": {
    "actf": { "data": 1600, "dec": 0, "disp": 0, "name": "F", "suff": "�", "unit": 0 },
    "acts": { "data": 751, "dec": 0, "disp": 1, "name": "S", "suff": " ", "unit": 2 }
  }
}
```

{% endcode %}

A few plausibility checks for the first readings:

* The `name` on the `program/name` topic matches the program shown on the CNC display.
* On the `machine/status` topic, the `run` value changes when you start or stop a program, and `alarm` and `emergency` are 0 during normal operation.
* On the `process/speed` topic, the `acts.data` value (spindle speed S) is 0 while the spindle is stopped, and the `actf.data` value (feed rate F) follows the commanded feed while machining.

If the connection does not reach the **Connected** state, verify that the FOCAS Ethernet function is installed and configured on the CNC, that the host address is correct, and that the port (8193 by default) is reachable from Connectware. The connector retries failed connection attempts automatically according to its `connectionStrategy` settings.

## Service Commissioning File Example

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

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

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

description: >
  Service commissioning file that reads status, program, spindle, and feed
  data from a FANUC CNC control with the FOCAS connector and maps it into
  an ISA-95 style MQTT topic hierarchy (Example)

metadata:
  name: FANUC FOCAS Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  focasHost:
    description: Hostname or IP address of the FANUC CNC
    type: string
    default: 192.168.1.100

  focasPort:
    description: TCP port of the FOCAS Ethernet interface
    type: integer
    default: 8193

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

resources:
  # Connection to the FOCAS Ethernet interface of the CNC
  focasConnection:
    type: Cybus::Connection
    properties:
      protocol: Focas
      targetState: connected
      connection:
        host: !ref focasHost
        port: !ref focasPort

  # Static system information: CNC type, series and version, controlled axes
  systemInfo:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      subscribe:
        method: cnc_sysinfo
        interval: 60000

  # Status information: mode, run state, motion, alarm, emergency stop
  statusInfo:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      subscribe:
        method: cnc_statinfo2
        interval: 3000

  # Full path name of the program currently being executed
  executedProgramName:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      subscribe:
        method: cnc_exeprgname
        interval: 5000

  # Actual feed rate (F) and actual speed of the main spindle (S)
  # dataType -1 reads both values in one call
  feedAndSpindleSpeed:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      subscribe:
        method: cnc_rdspeed
        dataType: -1
        interval: 2000

  # Load information of the serial spindle
  spindleLoad:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      subscribe:
        method: cnc_rdspload
        spindleNumber: 1
        interval: 2000

  # On-demand read with the request/response pattern:
  # publish a message on the "req" topic, receive the result on "res"
  systemInfoOnDemand:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      read:
        method: cnc_sysinfo

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref systemInfo
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/machine/info'
        - subscribe:
            endpoint: !ref statusInfo
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/machine/status'
        - subscribe:
            endpoint: !ref executedProgramName
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/program/name'
        - subscribe:
            endpoint: !ref feedAndSpindleSpeed
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/process/speed'
        - subscribe:
            endpoint: !ref spindleLoad
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/spindle/load'
```

{% endcode %}

{% hint style="info" %}
Disclaimer: FANUC and FOCAS are trademarks or registered trademarks of FANUC Corporation.
{% 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-fanuc-cnc-via-focas.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.
