# FOCAS

The FOCAS connector connects to FANUC CNC machines using FANUC's FOCAS protocol, allowing you to collect machine data by creating subscribe and read endpoints.

For a full list of connection and endpoint properties, see:

* [Connection Properties](/2-4-0/connectors/shop-floor-connectors/focas/focasconnection.md)
* [Endpoint Properties](/2-4-0/connectors/shop-floor-connectors/focas/focasendpoint.md)

## FOCAS Methods

The following methods are available. For full details of each method, consult the FANUC FOCAS documentation.

### Subscribe Methods

Define endpoints using these methods with the `subscribe` operation. Output is returned as a JSON object.

#### `cnc_exeprgname`

Reads the full path name of the program which is currently being executed in CNC.

**Example output:**

{% code lineNumbers="true" %}

```json
{ "id": 1, "timestamp": 1637339279827, "value": { "name": "SAMPLE", "o_num": 0 } }
```

{% endcode %}

#### `cnc_rdgcode`

Reads the information of CNC about the commanded G code.

**Required properties:**

* `type`
* `block`
* `numGcd`

**Example output:**

{% code lineNumbers="true" %}

```json
{ "id": 1, "timestamp": 1637339824109, "value": { "code": "G01", "flag": 0, "group": 0 } }
```

{% endcode %}

#### `cnc_rdopnlsgnl`

Reads the output signal image of software operator’s panel.

**Required properties:**

* `slctData`

**Example output:**

{% code lineNumbers="true" %}

```json
{
  "id": 1,
  "timestamp": 1637339309823,
  "value": {
    "blck_del": 0,
    "datano": 16723,
    "dry_run": 0,
    "feed_hold": 0,
    "feed_ovrd": 0,
    "hndl_ax": -1,
    "hndl_mv": 0,
    "jog_ovrd": 0,
    "machn_lock": 0,
    "mem_prtct": 0,
    "mode": 2,
    "rpd_ovrd": 0,
    "sngl_blck": 0,
    "spdl_ovrd": 0,
    "type": 32767
  }
}
```

{% endcode %}

#### `cnc_rdprgnum`

Reads the program number (modal O number) of the program which is currently selected in CNC.

**Example output:**

{% code lineNumbers="true" %}

```json
{ "id": 1, "timestamp": 1637339187748, "value": { "data": 0, "mdata": 0 } }
```

{% endcode %}

#### `cnc_rdspeed`

Reads the actual feed rate and the actual rotational speed of the main spindle.

**Required properties:**

* `dataType`

**Example output:**

{% code lineNumbers="true" %}

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

{% endcode %}

#### `cnc_rdspload`

Reads the load information of the serial spindle.

**Required properties:**

* `spindleNumber`

**Example output:**

{% code lineNumbers="true" %}

```json
{ "id": 1, "timestamp": 1637339785074, "value": { "data": [820, 19744, 12615, 23089, 14129, 12590, 13104, 0], "datano": 1, "type": 32 } }
```

{% endcode %}

#### `cnc_statinfo2`

Reads the status information of CNC.

**Example output:**

{% code lineNumbers="true" %}

```json
{
  "id": 1,
  "timestamp": 1637339042705,
  "value": {
    "alarm": 0,
    "aut": 1,
    "edit": 0,
    "emergency": 0,
    "ext_opt": 0,
    "hdck": 0,
    "motion": 1,
    "mstb": 0,
    "o3dchk": 0,
    "restart": 0,
    "run": 3,
    "tmmode": 0,
    "warning": 0
  }
}
```

{% endcode %}

#### `cnc_sysinfo`

Reads system information such as the CNC system type, Machining (M) or Turning (T), the series and version of the CNC system software, and the number of controlled axes.

**Example output:**

{% code lineNumbers="true" %}

```json
{
  "id": 1,
  "timestamp": 1637339898044,
  "value": { "addinfo": 2, "axes": "03", "cnc_type": "31", "max_axis": 32, "mt_type": " M", "series": "G11Z", "version": "17.1" }
}
```

{% endcode %}

#### `pmc_rdpmcrng`

Reads the PMC data of the specified PMC address/range.

**Required properties:**

* `addressType`
* `dataType`
* `addressStart`
* `addressEnd`
* `dataLength`

**Example output:**

{% code lineNumbers="true" %}

```json
{ "id": 1, "timestamp": 1637341486343, "value": { "cdata": [100, 51, 34, 44, 34], "datano_e": 30, "datano_s": 30, "type_a": 0, "type_d": 0 } }
```

{% endcode %}

### Read Methods

Define endpoints using these methods with the `read` operation. These methods require input on the request topic (`req`) and return output as a JSON object.

You can include a correlation `id` in the request payload to match responses to specific requests.

#### `program_download`

Downloads the specified NC data to the controller. Publish a valid G-code program (see [G-code on Wikipedia](https://en.wikipedia.org/wiki/G-code)) as the string value of the `value` key on the endpoint's request topic (`req`).

Format the program code string as follows before publishing:

1. Insert a leading line break `\n`. All data before it is ignored.
2. Replace all line breaks with `\n`.
3. Remove all space characters.
4. Remove all semicolons.

**Example: Raw G-code program**

{% code lineNumbers="true" %}

```gcode
O1234 ;
G1 F0.3 W10. ;
M30 ;
%
```

{% endcode %}

**Example: Formatted string to publish**

{% code lineNumbers="true" %}

```
\nO1234\nG1F0.3W10.\nM30\n%
```

{% endcode %}

The program is downloaded to the directory set as “Background Folder” in the FANUC controller.

**Example response**

{% code lineNumbers="true" %}

```json
{ "id": 1, "timestamp": 1637340781387 }
```

{% endcode %}

## Service Commissioning File Example

{% file src="/files/58IquuV3UErcgHnjGMLx" %}

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

```yaml
description: >
  Sample FOCAS service commissioning file

metadata:
  name: Sample FOCAS service
  icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom1.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  focasHost:
    type: string
    default: 192.168.2.170

  focasPort:
    type: integer
    default: 8193

  initialReconnectDelay:
    type: integer
    default: 1000

  maxReconnectDelay:
    type: integer
    default: 30000

  factorReconnectDelay:
    type: integer
    default: 2

resources:
  focasConnection:
    type: Cybus::Connection
    properties:
      protocol: Focas
      connection:
        host: !ref focasHost
        port: !ref focasPort
        connectionStrategy:
          initialDelay: !ref initialReconnectDelay
          maxDelay: !ref maxReconnectDelay
          incrementFactor: !ref factorReconnectDelay

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

  readExample1:
    type: Cybus::Endpoint
    properties:
      protocol: Focas
      connection: !ref focasConnection
      read:
        method: 'cnc_sysinfo'
```

{% endcode %}


---

# Agent Instructions: 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:

```
GET https://docs.cybus.io/2-4-0/connectors/shop-floor-connectors/focas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
