API Overview
The Client is the entry point to the SDK. It owns one gRPC channel to the
server and creates a service client for each gRPC service the first time you
use it. Each service client exposes a stub on which you call RPCs.
client.<service>.stub.<Rpc>(request) # Python
client.<service>().stub-><Rpc>(&ctx, req, &res); // C++
Python
from flexiv.pdk import Client
client = Client(target="localhost:50052") # default target
try:
...
finally:
client.close()
# or, preferably, as a context manager:
with Client("192.168.1.100:50052") as client:
...
Client(target: str = "localhost:50052")creates an insecure gRPC channel totarget. No network traffic happens until the first RPC.Service attributes are created lazily and cached.
client.channelis the underlyinggrpc.Channel; you can use it to make stubs for any service yourself.client.check_version()asks the server whether this client works with it and returns(compatible, message).compatibleis False when the server cannot be reached. See Environment Compatibility.client.license.install_file(path)installs a.licfile. See Activate Licenses.close()closes the channel. Exiting thewithblock calls it for you.
C++
#include <flexiv/pdk/client.hpp>
flexiv::pdk::Client client("localhost:50052"); // insecure channel
// or bring your own channel (TLS, custom arguments, ...):
flexiv::pdk::Client client2(grpc::CreateChannel(target, creds));
Clientis neither copyable nor movable. Share it withstd::shared_ptr<Client>when several components need it.Accessors such as
client.workcell()return a reference to aServiceClient<ServiceT>whose public memberstubis the generatedServiceT::Stub. Accessors are thread-safe.channel()returns the sharedgrpc::Channel.client.license().InstallFile(path, &response)installs a.licfile. See Activate Licenses.CheckVersion(&message)returns whether this client works with the server; message says why not, or gives the server version.close()releases the channel. Any accessor called afterwards throwsstd::runtime_error("PDK client channel is closed"). Do not keep using service client references or stubs obtained beforeclose().gRPC requires a fresh
grpc::ClientContextfor every call.
Session (C++)
flexiv::pdk::Session (<flexiv/pdk/session.hpp>) bundles a
std::shared_ptr<Client> with a watch::Subscriber so that GUI editors and
viewers can share one handle for both RPCs and streamed events:
auto client = std::make_shared<flexiv::pdk::Client>();
flexiv::pdk::Session session(client);
session.client()->frame().stub->...; // RPCs
auto sub = session.watch().Subscribe<SceneEvent>(...); // events
The Session must outlive everything it is passed to. Destroying it stops every
subscription it handed out. client() may be null when the Session was built
without a client (for example, offline tests).
Service map
The table maps each Client member to its gRPC service. Services marked
licensed need a license on the server machine (Activate Licenses).
Services marked no workcell needed work without an active workcell. Every
other service acts on the scene of the active workcell, so create or load one
first (Workcells). ConfigService rejects every call without one with
FAILED_PRECONDITION; the others report the missing workcell or item in
status.
Python attribute |
C++ accessor |
gRPC service |
Notes |
|---|---|---|---|
|
|
|
no workcell needed |
|
|
|
|
|
|
|
|
|
|
|
streaming |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
licensed |
|
|
|
licensed |
|
|
|
licensed |
|
|
|
|
|
|
|
|
|
|
|
no workcell needed |
|
|
|
no workcell needed |
|
|
|
streaming; no workcell needed |
Finding message types
Request and response messages live in the module generated from the service’s
.proto file. The Python module path mirrors the proto path, with _pb2
appended (_pb2_grpc for stubs):
Proto file |
Python module |
C++ header |
|---|---|---|
|
|
|
|
|
|
The C++ namespace follows the proto package, for example
flexiv::pdk::workcell::CreateRequest; see C++ API for the two
services whose package differs from their folder. See Services for the
full list.