# Haas CNC to OPC UA

> PLCGateway reads Haas machines through Machine Data Collection and offers their status, part counts, cycle times and macro variables as OPC UA nodes for MES, SCADA and historians.

Haas controls have no OPC UA server; they answer Q commands on the port set in Setting 143. PLCGateway sends those commands cyclically and maps every answer to a tag, and its OPC UA server presents each machine as a folder of variables that any OPC UA client can browse and subscribe to.

Mixed shops benefit most: Haas, FANUC and MTConnect machines sit under the same endpoint with the same naming, so the MES needs one OPC UA connection instead of one driver per machine brand.

- **Source:** [Haas machine data collection](https://plcgateway.com/protocols/haas.md) (`haas_q`)
- **Connection:** TCP · port of Setting 143
- **Target:** [OPC UA](https://plcgateway.com/connect.md)
- **Writing:** yes
- **Included in:** PLCGateway Connect, PLCGateway SCADA, PLCGateway Embedded

## Set it up in five steps

1. On the machine set Setting 143 (Machine Data Collection) to a TCP port, for example 5051.
2. Add a Haas device with the IP address and the port.
3. Create the tags for status, program, parts and spindle.
4. Open Gateway → OPC UA and choose the security modes and whether clients sign in anonymously or with user name and password.
5. Connect your OPC UA client (UaExpert, an MES, a SCADA) to opc.tcp://<gateway>:4840 and browse Objects → PLCGateway.

## Example: node ids in the OPC UA server

A device with the id vf2 and these tags appears in the address space as shown below. Names and values are examples.

| Tag | Address | Example value |
|---|---|---|
| `Running` | `running` | true |
| `Status` | `status` | BUSY |
| `Parts` | `parts` | 352 |
| `SpindleRpm` | `spindle_rpm` | 7500 rpm |
| `LastCycle` | `last_cycle` | 184 s |

**OPC UA node ids**

```
opc.tcp://<gateway>:4840
Objects / PLCGateway / vf2
ns=1;s=vf2.Running     = true
ns=1;s=vf2.Status      = "BUSY"
ns=1;s=vf2.Parts       = 352
ns=1;s=vf2.SpindleRpm  = 7500
ns=1;s=vf2.LastCycle   = 184
```

Every tag is a variable under Objects / PLCGateway / device in namespace 1; clients read it, write it and subscribe to its changes.

## The OPC UA server in PLCGateway

Every tag becomes a variable in PLCGateway's built-in OPC UA server, so MES, ERP, SCADA and historians use one standard endpoint instead of each controller's own protocol. Clients browse the devices and tags, read, write and subscribe to value changes.

The server offers the security modes None, Sign and SignAndEncrypt with automatically generated certificates; clients sign in anonymously or with user name and password.

- One endpoint (opc.tcp, port 4840) for all devices and protocols
- A folder per device and a variable per tag, with description and unit
- Subscriptions with data-change notifications; writing only where the tag allows it
- Client certificates are approved in the web interface

![OPC UA server settings: endpoint, security policies and users](https://plcgateway.com/assets/img/shots/opcua-1600.webp)

## Controllers and devices

- [Haas machine data collection](https://plcgateway.com/protocols/haas.md)
- [Haas Automation](https://plcgateway.com/controllers/haas.md)

## Questions and answers

### Can an OPC UA client write to a Haas machine?

Macro variables can be written, for example to hand a work order number to the machine, when writing is allowed in the OPC UA server settings. Programs and settings are never changed.

### Should I use MTConnect instead?

Not necessarily. Q commands work on NGC and Classic controls and give access to macro variables; MTConnect is available on NGC and is read only. PLCGateway supports both, also side by side.

### What has to be set on the machine?

Only Setting 143 (Machine Data Collection) to a TCP port such as 5051, and a network address for the control.

## Related solutions

- [Haas CNC to MQTT](https://plcgateway.com/solutions/haas-to-mqtt.md)
- [Haas CNC OEE](https://plcgateway.com/solutions/haas-oee.md)
- [FANUC FOCAS to OPC UA](https://plcgateway.com/solutions/fanuc-focas-to-opc-ua.md)
- [MTConnect to OPC UA](https://plcgateway.com/solutions/mtconnect-to-opc-ua.md)
- [Siemens S7 to OPC UA](https://plcgateway.com/solutions/siemens-s7-to-opc-ua.md)
- [Modbus to OPC UA](https://plcgateway.com/solutions/modbus-to-opc-ua.md)
- [All protocols](https://plcgateway.com/protocols.md)

_Product and model names are trademarks of their owners. They are named only to show which equipment the drivers communicate with; PLCGateway is not affiliated with these companies._

---
Source: https://plcgateway.com/solutions/haas-to-opc-ua
