メインコンテンツまでスキップ

サブスクリプションの作成 (C)

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Subscription_Create(
DarraUa_SessionHandle session,
const DarraUa_SubscriptionConfig* cfg,
DarraUa_SubscriptionHandle* out_sub);
事前学習 / 関連教材

DarraUa_SubscriptionConfig フィールド​

typedef struct {
double publishing_interval_ms; /* デフォルト 500 */
uint32_t lifetime_count; /* デフォルト 2400 */
uint32_t max_keep_alive_count; /* デフォルト 10 */
uint32_t max_notifications; /* 0 = 無限大 */
uint8_t priority; /* 0-255 */
int32_t publishing_enabled; /* 1 = 有効 */
} DarraUa_SubscriptionConfig;

OPCUA_API void OPCUA_CALL
DarraUa_SubscriptionConfig_Init(DarraUa_SubscriptionConfig* cfg);
カテゴリプロパティ型アクセス説明
パブリッシュpublishing_interval_msdoubleinサーバーがデータを送信する最小間隔。サーバー側で調整される場合があります。デフォルトは 500
publishing_enabledint32_tin1 = パブリッシュを有効化、0 = サンプリングのみ、プッシュは行わない
ライフサイクルlifetime_countuint32_tinPublishRequest を何 publish サイクル連続で受信しなければサブスクリプションを削除するか。デフォルトは 2400
max_keep_alive_countuint32_tin新しいデータがない場合に、空のKeepAliveをどのくらいの間隔で送信するか。デフォルトは10
max_notificationsuint32_tin1回のパブリッシュで送信できる通知の最大数。0 = 制限なし
スケジューリングpriorityuint8_tinサブスクリプションの優先度 0~255

必ず最初に DarraUa_SubscriptionConfig_Init(&cfg) でデフォルト値を設定してから、上書きしてください。

使用方法​

DarraUa_SubscriptionConfig sc;
DarraUa_SubscriptionConfig_Init(&sc);
sc.publishing_interval_ms = 500.0;
sc.publishing_enabled = 1;

DarraUa_SubscriptionHandle sub = UA_INVALID_SUBSCRIPTION_HANDLE;
DarraUa_Status st = DarraUa_Subscription_Create(h, &sc, &sub);
if (!UA_STATUS_IS_GOOD(st) || sub == UA_INVALID_SUBSCRIPTION_HANDLE) {
fprintf(stderr, "Subscription_Create failed: %s\n", DarraUa_StatusName(st));
return -1;
}

購読の分散​

あるアプリケーションで、高頻度 100 ms サブスクリプション(運動データ)と低頻度 5000 ms サブスクリプション(環境温度)の両方を扱う場合は、2つのサブスクリプションに分けて作成し、一つにまとめないようにしてください:

DarraUa_SubscriptionConfig fast_cfg;
DarraUa_SubscriptionConfig_Init(&fast_cfg);
fast_cfg.publishing_interval_ms = 100.0;
fast_cfg.publishing_enabled = 1;

DarraUa_SubscriptionConfig slow_cfg;
DarraUa_SubscriptionConfig_Init(&slow_cfg);
slow_cfg.publishing_interval_ms = 5000.0;
slow_cfg.publishing_enabled = 1;

DarraUa_SubscriptionHandle fast = 0, slow = 0;
DarraUa_Subscription_Create(h, &fast_cfg, &fast);
DarraUa_Subscription_Create(h, &slow_cfg, &slow);

DarraUa_MonitoredItemHandle mi_fast = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_MonitoredItemHandle mi_slow = UA_INVALID_MONITORED_ITEM_HANDLE;

DarraUa_Subscription_AddNode(fast, "ns=2;s=AxisPosition", UA_ATTR_VALUE,
-1.0, on_change, NULL, &mi_fast);
DarraUa_Subscription_AddNode(slow, "ns=2;s=AmbientTemperature", UA_ATTR_VALUE,
-1.0, on_change, NULL, &mi_slow);

各サブスクリプションは独立したパブリッシュサイクルを持っており、互いに影響し合うことはありません。

解放​

DarraUa_Subscription_Delete(sub);

サブスクリプションの削除後は MI をまとめて破棄し、サーバー側に DeleteSubscription を送信してリソースを解放します。

次のステップ​