Fanuc Adapter

Read a Fanuc CNC directly over Ethernet with FOCAS.
MTConnect.NET Docs Menu
  • Module name — MTConnect Fanuc Adapter agent module
  • Identifier — fanuc-adapter
  • NuGet package — MTConnect.NET-AgentModule-FanucAdapter
  • Source path — agent/Modules/MTConnect.NET-AgentModule-FanucAdapter/

Purpose

Reads a Fanuc CNC (Series 0i, 16i, 18i, 21i, 30i, 31i, 32i, 35i) directly using FOCAS over Ethernet and feeds the results into the agent, so no separate adapter process is needed. When the CNC connects, the module reads its model, paths, axes and spindles; by default it adds a Device built to match, including every path of multi-path controls.

FOCAS libraries

The Fanuc FOCAS libraries are not included. Copy Fwlib64.dll (64-bit agent) or Fwlib32.dll (32-bit agent), plus the series libraries they load (ex. fwlib30i64.dll, fwlib0iD64.dll), next to the agent executable. Without them an error is logged and the Device stays UNAVAILABLE.

Configuration Schema

The module's configuration class is FanucAdapterModuleConfiguration. The keys below describe the YAML map under fanuc-adapter:.

KeyTypeDefaultPermissible valuesNotes
deviceKeystringnulldevice name or UUIDRequired. The Device observations are added to.
createDevicebooltruetrue, falseWhen true, the module adds a Device named deviceKey, updated with the structure read from the CNC. Set false to use a Device from Devices.xml.
deviceUuidstringdeviceKeyany stringUUID of the Device created when createDevice is true.
serverstringlocalhosthostname or IP addressThe CNC address.
portint81931-65535The CNC's FOCAS port.
responseTimeoutint5000millisecondsFOCAS communication timeout, rounded up to whole seconds.
readIntervalint1000millisecondsDelay between read cycles.
slowReadIntervalint10000millisecondsInterval between reads of the timers and the work offset.
workPositionsboolfalsetrue, falseAlso report absolute (work coordinate) positions.
axisLoadsbooltruetrue, falseRead the servo load of each axis.
spindleLoadbooltruetrue, falseRead the spindle load.
overridesbooltruetrue, falseRead the feedrate, rapid and spindle overrides from the CNC interface signals G0012, G0014, G0030 and G0096.
toolNumberVariableint4120macro variable, 0 = offThe variable read for the tool number. #4120 is the modal T code; many machines keep the tool in the spindle in another variable.
workOffsetbooltruetrue, falseRead the active work offset from #4014.
partCountParameterint6711parameter, 0 = offThe parameter read for the part count.

DataItems

When createDevice is false, the Device in Devices.xml needs DataItems whose id or name match these keys. Path keys are used as-is for path 1 and prefixed with p{n}_ for other paths (ex. p2_execution). Axis keys use the axis name read from the CNC, including its suffix (ex. x_act, x1_act).

Read Every Cycle

KeyDataItemFOCAS source
availAVAILABILITYAVAILABLE while connected; otherwise UNAVAILABLE (and every other DataItem is set UNAVAILABLE).
estopEMERGENCY_STOPcnc_statinfo
modeCONTROLLER_MODEcnc_statinfo — MEM / RMT = AUTOMATIC, MDI = MANUAL_DATA_INPUT, EDIT = EDIT, JOG / HANDLE / INC / REF = MANUAL.
executionEXECUTIONcnc_statinfo — reset = READY, START = ACTIVE, HOLD = FEED_HOLD, STOP = STOPPED, MSTR = INTERRUPTED; STOPPED in emergency stop.
programPROGRAMcnc_exeprgname (cnc_rdprgnum on older controls).
lineLINE_LABELcnc_rdseqnum — the sequence number (N).
partCountPART_COUNTcnc_rdparam 6711.
toolTOOL_NUMBERcnc_rdmacro 4120.
feedratePATH_FEEDRATE (ACTUAL)cnc_rdspeed — mm/s; feed per revolution is converted using the spindle speed.
feedOverridePATH_FEEDRATE_OVERRIDE (PROGRAMMED)G0012 (*FV0 - *FV7).
rapidOverridePATH_FEEDRATE_OVERRIDE (RAPID)G0014 (ROV1, ROV2), or G0096 (1% rapid override) when HROV is on.
systemSYSTEM conditioncnc_rdalmmsg2 — one FAULT per active alarm with its native code (ex. PS0010, SV0401) and message; WARNING for battery, fan and other warnings.
speedROTARY_VELOCITY (ACTUAL)cnc_rdspeed (cnc_acts on older controls) — RPM.
spindleLoadLOADcnc_rdspmeter — percent.
spindleOverrideROTARY_VELOCITY_OVERRIDEG0030 (SOV0 - SOV7).
{axis}_actPOSITION / ANGLE (ACTUAL)cnc_rdposition — machine position, mm (inch converted) or degrees.
{axis}_workPOSITION / ANGLE (ACTUAL)cnc_rdposition — absolute position, when workPositions is true; references the Device's work coordinate system (type OBJECT).
{axis}_loadLOADcnc_rdsvmeter — percent.

The CNC interface (G) addresses are offset by 1000 per path (ex. G1012 for path 2).

Read Every slowReadInterval

KeyDataItemFOCAS source
firmwareFIRMWARE (VERSION)cnc_sysinfo — series and version.
powerOnTimeEQUIPMENT_TIMER (POWERED)cnc_rdtimer 0 — seconds.
operatingTimeEQUIPMENT_TIMER (OPERATING)cnc_rdtimer 1 — seconds.
cuttingTimeEQUIPMENT_TIMER (WORKING)cnc_rdtimer 2 — seconds.
cycleTimePROCESS_TIMER (PROCESS)cnc_rdtimer 3 — seconds.
workOffsetWORK_OFFSETcnc_rdmacro 4014 — ex. 54.

Wire Interaction

Fanuc CNCFOCAS over Ethernet
FOCAS
fanuc-adapter moduleReads the CNC
AgentDevice and Observations
  1. Connect
  2. Module AgentAddDevice (createDevice = true)
  3. Module CNCcnc_allclibhndl3 to <server>:<port>
  4. Module CNCcnc_sysinfo, cnc_getpath, cnc_rdaxisname, cnc_rdspdlname
  5. Module AgentAddDevice with the paths, axes, and spindles
  6. Every readInterval ms, for each path
  7. Module CNCcnc_setpath, cnc_statinfo, cnc_exeprgname, cnc_rdposition, cnc_rdspeed, ...
  8. Module CNCcnc_rdalmmsg2, when there is an alarm
  9. Module CNCcnc_rdtimer, cnc_rdmacro 4014, every slowReadInterval ms
  10. Module AgentAddObservation(...)
  11. Socket or handle error
  12. Module Agentavail and every DataItem set to UNAVAILABLE
The FOCAS libraries aren't included: copy them next to the Agent executable.

All FOCAS calls run on a dedicated thread, because a FOCAS library handle is only valid in the thread that opened it.

Example Configuration

modules:
  - fanuc-adapter:
      deviceKey: M1
      server: 192.168.1.70
      port: 8193

With work positions and a machine-specific tool variable:

modules:
  - fanuc-adapter:
      deviceKey: VMC-1
      server: 192.168.1.71
      workPositions: true
      toolNumberVariable: 500

For multiple machines, declare the module once per machine. Created DataItem IDs are prefixed with the Device name, so they do not collide.

Troubleshooting

  • FOCAS library not found — copy Fwlib64.dll / Fwlib32.dll and the series libraries next to the agent; the library bitness must match the agent process.
  • Always UNAVAILABLE with return code -16 — the CNC is not reachable on port, or FOCAS is not enabled on its Ethernet port.
  • A value never appears — the CNC may not support that FOCAS function or option (logged once as "not supported"); check the agent log at Information level.
  • Wrong tool number — #4120 is the commanded T code; on machining centers the tool in the spindle is often kept in a machine-specific macro variable. Set toolNumberVariable.
  • Override values look wrong — the overrides come from the standard CNC interface signals; check them against the PMC signal status screen.
  • Observations dropped with createDevice: false — the Device's DataItem id or name must match the keys above; verify against /probe.

Classes

The main classes in the MTConnect.NET-AgentModule-FanucAdapter package:

  • FanucAdapterModuleConfiguration — the module's configuration class.
  • IFocasClient — the FOCAS functions used by the module.