Create a Subscription
Subscription CreateSubscription(double publishing_interval_ms = 500.0);
Prerequisite Reading / Supplementary Materials
- Add MonitoredItem Please see Add MonitoredItem.
- Please see the data callback fields Data Callback.
Parameters
| Parameters | Default | Note |
|---|---|---|
| publishing_interval_ms | 500.0 | The interval at which the server pushes data (ms). The server may revise the value; revised values are not sent back. PublishingIntervalMs() After this CreateSubscription, the server still returns the requested value; to obtain the revised value, you must make another call. Modify |
Examples
auto sub = s.CreateSubscription(500.0);
std::cout << "Subscription handle = " << sub.Handle() << "\n";
std::cout << "Initial interval = " << sub.PublishingIntervalMs() << " ms\n";
Multiple Subscription Channels
If an app requires both a 100 ms high-frequency subscription (motion data) and a 5000 ms low-frequency subscription (ambient temperature), create 2 Subscriptions to split the load; do not mix them into one:
auto fast = s.CreateSubscription(100.0);
fast.AddNode("ns=2;s=AxisPosition", [](DataValue const& dv) { /* ... */ });
auto slow = s.CreateSubscription(5000.0);
slow.AddNode("ns=2;s=AmbientTemperature", [](DataValue const& dv) { /* ... */ });
Each subscription has its own release schedule, and they do not affect one another.
Subscription Public Properties (Accessors)
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Identifiers | Handle() | DarraUa_SubscriptionHandle | R | Layer C handle (associated with server-side subscription ID) |
| Configuration | PublishingIntervalMs() | double | R | Current publishing interval (ms). After `CreateSubscription` it is the requested value, updated to the server's revised value by [Modify](./modify) |
Subscription Public Methods
| Methods | Note |
|---|---|
| AddNode(node_id, cb, attr = Value, sampling_ms = -1) | Add Order MI |
| AddMany(node_ids, cb, attr = Value) | Bulk Add, returns a list of (handle, status) |
| Remove(mi_handle) | Removal Order MI |
| RemoveByNodeId(node_id) | Press NodeId to remove all matching items MI |
| SetPublishingEnabled(bool) | Enable or disable publishing for the entire subscription |
| Pump(timeout_ms = 2000) | Manually trigger a Publish once (AutoPublish no manual action required when enabled) |
| Modify(publishing_interval_ms, lifetime, keep_alive, ...) | Change Subscription Settings |
| SetMonitoringMode(mode, mi_handles) | Batch Cut Mode |
| SetMode(handle, mode) | Slice individually MI mode |
| ModifyMonitoredItems(requests) | Batch Change Sampling |
| ModifyItem(handle, sampling_ms, queue_size, discard_oldest) | Amendment MI |
| Republish(seq_no) | Request Resend |
| ~Subscription() | RAII Destructor → DarraUa_Subscription_Delete |
RAII
Subscription This is a "move-only" stack object; it is automatically called when it leaves the scope DarraUa_Subscription_Delete:
{
auto sub = s.CreateSubscription(500.0);
sub.AddNode("ns=2;s=Counter", [](DataValue const& dv) { /* ... */ });
std::this_thread::sleep_for(std::chrono::seconds(10));
} // sub Destructor → DarraUa_Subscription_Delete