Quick start
Connect, load Robotics, read OperationalMode — the auto-cast turns the raw integer the server sent into a typed PHP enum. Three lines past connect().
This page wires a complete integration: install the package, connect through the OPC UA client, load the Robotics registrar, read a value that the auto-cast turns into a typed PHP enum.
The whole thing
<?php
require __DIR__ . '/vendor/autoload.php';
use PhpOpcua\Client\ClientBuilder;
use PhpOpcua\Client\Types\StatusCode;
use PhpOpcua\Nodeset\Robotics\RoboticsRegistrar;
use PhpOpcua\Nodeset\Robotics\RoboticsNodeIds;
use PhpOpcua\Nodeset\Robotics\Enums\OperationalModeEnumeration;
$client = ClientBuilder::create()
->loadGeneratedTypes(new RoboticsRegistrar()) // Robotics + DI + IA
->connect('opc.tcp://192.168.1.100:4840');
$dv = $client->read(RoboticsNodeIds::OperationalMode);
if (StatusCode::isGood($dv->statusCode)) {
/** @var OperationalModeEnumeration $mode */
$mode = $dv->getValue(); // typed enum, not int
if ($mode === OperationalModeEnumeration::MANUAL_HIGH_SPEED) {
echo "Robot in manual high speed mode\n";
}
}
$client->disconnect();
Three things happened that the package made possible:
-
01
`new RoboticsRegistrar()` plus `loadGeneratedTypes()`
registered the Robotics enum mappings and (in other specs) codecs onto the client. The client knows about Robotics types from this point onward.
-
02
`RoboticsRegistrar` dependencies loaded automatically.
Robotics depends on DI and IA — both registered as part of the call. No need to wire them explicitly.
-
03
`RoboticsNodeIds::OperationalMode` is a string constant.
The client accepts it as a
NodeId|stringargument and resolves it internally. Same effect asread('ns=N;i=...')but with a name that survives refactoring. -
04
`$dv->getValue()` returned a `BackedEnum`, not an `int`.
Without the registrar, the same call would have returned
1(the raw integer the server sent). With the registrar'sgetEnumMappings()table loaded, the client looks up the DataType NodeId and casts the value to the matching PHP enum.
Without the registrar — what changes
Drop loadGeneratedTypes() and the same code returns a raw int:
$client = ClientBuilder::create()
->connect('opc.tcp://192.168.1.100:4840');
$dv = $client->read('ns=N;i=...'); // string NodeId, by hand
$mode = $dv->getValue(); // → 2 (int)
if ($mode === 2) { // magic number, no autocomplete
echo "Manual high speed\n";
}
It works — the application functions. But:
'ns=N;i=...'is a magic string; typos surface at runtime.1is a magic number; downstream code has no autocomplete or type info.- A future enum value change in the spec breaks code silently.
loadGeneratedTypes() exchanges those for compile-time names and
typed enums. The runtime cost is one-time at boot — see
Concepts · Codecs and registrars.
NodeIds are strings, not NodeId objects
Every constant on <Spec>NodeIds is a string — the canonical
NodeId encoding (ns=N;i=... or ns=N;s=...):
use PhpOpcua\Nodeset\Robotics\RoboticsNodeIds;
var_dump(RoboticsNodeIds::OperationalMode);
// → string(11) "ns=3;i=18961"
opcua-client's read(), write(), browse() all accept
NodeId|string, so the string form works directly. Wrap with
NodeId::parse() if you need a NodeId instance for further
manipulation. See Concepts · NodeId constants.
What about codecs?
Robotics is enum-only — no Codecs/ directory, no Types/
directory. The auto-cast you saw above is the enum mappings doing
their job; codecs are not involved.
For specs that include structured data — AutoID, BACnet,
MachineVision, TMC, Scheduler — the registrar also installs
ExtensionObjectCodec implementations that decode binary
structures into readonly DTOs. See
Concepts · Typed DTOs and
Concepts · Codecs and registrars.
Where to go next
- What gets generated — the five artefact types you may encounter.
- Usage · Loading registrars — loading multiple specs, deduplication, opting out of dependencies.
- Recipes · Robotics walkthrough — the same example fleshed out with browse, write, structured data.
Tip
The Robotics example above assumes a robot exposed on
opc.tcp://192.168.1.100:4840. For local development, the
UA-.NETStandard test suite
ships a Docker image with several companion specs loaded.