Modify
- To create a subscription, see Create a Subscription.
- Subscribe or unsubscribe to the entire series / For individual subscribe/unsubscribe options, see MI SetMonitoringMode.
sub.modify(...)
Modify the publication parameters for a subscription (ModifySubscription service):
def modify(self,
publishing_interval_ms: float,
lifetime_count: int = 1200,
max_keep_alive_count: int = 50,
max_notifications_per_publish: int = 0,
priority: int = 0) -> ModifySubscriptionResult: ...
| Parameters | Meaning |
|---|---|
| publishing_interval_ms | Time Between New Releases |
| lifetime_count | PublishRequest If I haven't received anything for a certain number of publication cycles, I'll cancel the subscription. |
| max_keep_alive_count | How often should a KeepAlive be sent when there is no new data? |
| max_notifications_per_publish | What is the maximum number of notifications that can be sent in a single Publish operation? 0 = unlimited |
| priority | Priority (0–255) |
Returns ModifySubscriptionResult:
| Field | Type | Note |
|---|---|---|
| revised_publishing_interval_ms | float | Actual deployment interval on the server side |
| revised_lifetime_count | int | Actual server lifetime |
| revised_max_keep_alive_count | int | Actual server-side keepalive |
rev = sub.modify(publishing_interval_ms=1000, lifetime_count=600, max_keep_alive_count=30)
print(f"Revised publishing interval = {rev.revised_publishing_interval_ms}ms")
priority If the value exceeds 0–255, it is truncated to the lower 8 bits. A exception is thrown if the server returns a non-0 value OpcUaException. Upon success, sub.publishing_interval_ms will beServer-side revision value Overwrite; at the same time, the lifetime and keepalive values are also written back to the local storage for use in rebuilding the subscription.
sub.modify_monitored_items(requests)
Batch Edit MI Sampling Parameters (ModifyMonitoredItems Service):
def modify_monitored_items(
self,
requests: List[MonitoredItemModifyRequest]
) -> List[ModifyMonitoredItemResult]: ...
MonitoredItemModifyRequest Field:
| Field | Default | Note |
|---|---|---|
| monitored_item_handle | — | Local MI Handle |
| sampling_interval_ms | -1.0 | -1 = Follow subscription, 0 = As soon as possible |
| queue_size | 1 | Server Buffer Queue Length |
| discard_oldest | True | True = Discard the oldest, False = Discard the newest |
ModifyMonitoredItemResult:
| Field | Type | Note |
|---|---|---|
| status | StatusCode | Revision Results |
| revised_sampling_interval_ms | float | Actual sampling interval on the server side |
| revised_queue_size | int | Actual server queue size |
from darra_opcua import MonitoredItemModifyRequest
requests = [
MonitoredItemModifyRequest(
monitored_item_handle=h,
sampling_interval_ms=50,
queue_size=10,
discard_oldest=True)
for h in mi_handles
]
results = sub.modify_monitored_items(requests)
If the server returns a non-0 value, the entire call is aborted OpcUaException; if a single item fails, it is reflected only in that element status, and no exception is thrown.
sub.modify_item(...) Single MI Simplified Version
def modify_item(self,
monitored_item_handle: int,
sampling_interval_ms: float,
queue_size: int = 1,
discard_oldest: bool = True) -> ModifyMonitoredItemResult: ...
r = sub.modify_item(handle, sampling_interval_ms=50)
print(f"Revised sampling = {r.revised_sampling_interval_ms}ms")
queue_size and discard_oldest
The server MI maintains a queue for each. When the queue is full, data is discarded—and which end of the queue the data is discarded from is determined discard_oldest by:
discard_oldest = True(Default) → Discard the oldest, keep the newestdiscard_oldest = False→ Discard the newest, keep the oldest
queue_size = 1 (Default) Retains only the latest value; suitable for "real-time display"; queue_size = N (N > 1) can handle brief publish delays.
Increase the size queue_size We cannot guarantee that no data will be lost. — It simply delays the "drop" until the moment the queue actually overflows. To ensure absolutely no data is missed, use read(ua.read_history) from the history as a fallback, or adjust the publishing interval so it keeps up with the data rate.