> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/workflows/ja/chtoriaru/integrate-with-ignition/live-data/read-the-roboflow-opc-ua-server.md).

# Roboflow OPC UA Serverを読み取る

Ignition を Roboflow エッジデバイス上の OPC UA Server に接続し、Workflow が書き込むタグを読み取ります。

Ignition または PLC が書き込みを受信するのではなく、デバイス上のタグをポーリングする場合は、この方法を使用します。OPC UA Server は Roboflow デバイス上で動作するサービスです。Workflow がタグを書き込み、Ignition はクライアントとしてそれらを読み取ります。

{% hint style="info" %}
OPC UA Writer Sink、OPC UA Reader、OPC UA Server は、Enterprise のお客様のみご利用いただけます。 [Roboflow の営業チームにお問い合わせください](https://roboflow.com/sales) 詳細をご案内します。
{% endhint %}

{% hint style="info" %}
以下の手順とスクリーンショットは、Ignition 8.1（Designer 8.1.55）のものです。メニュー名、ダイアログ、プロパティ名は、8.3 を含む他のバージョンでは異なる場合があります。
{% endhint %}

## タグの例

このページでは、パターンを示すために3つのタグを使用しています。これらは説明用の例です。ラインに合わせて独自のフォルダー、名前、データ型を定義し、Workflow でも同じ名前を使用してください。

<table data-search="false"><thead><tr><th>タグ</th><th>データ型</th><th>意味</th></tr></thead><tbody><tr><td><code>Line1/DefectFound</code></td><td>Boolean</td><td><code>true</code> 直近のケースが検査に不合格だった場合</td></tr><tr><td><code>Line1/PassCount</code></td><td>Int32</td><td>このシフトで合格したケース数</td></tr><tr><td><code>Line1/LastResult</code></td><td>String</td><td><code>pass</code> または <code>fail</code> 直近のケースの結果</td></tr></tbody></table>

## デバイスに OPC UA Server を追加する

1. Deployment Manager でデバイスを開き、「Services」タブに移動して、「Add Service」をクリックします。「OPC UA Server」を選択します。
2. 「Configure OPC UA Server」で、「Server Settings」の既定値をそのまま使用するか、変更します。「Namespace URI」（既定値は `http://opcua.roboflow.run`）を控えておいてください。Workflow で必要になります。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-898a7744caff2ff953cc53f33178b90e5b9619dd%2Fignition-dm-opcua-server-settings.png?alt=media" alt="The Configure OPC UA Server modal in Deployment Manager with Server Name Roboflow OPC UA Server, Namespace URI http://opcua.roboflow.run, Max Sessions 200, and Require Authentication off" width="500"><figcaption><p>サーバー設定。</p></figcaption></figure>
3. 「Folders」で「+ Add Folder」をクリックし、次を追加します。 `Line1`.
4. 「Tags」で、タグごとに「+ Add Tag」をクリックします。「Display Name」、「Browse Name」、「Data Type」、「Folder」を設定し、Workflow が書き込めるよう「Access Level」は「ReadWrite」のままにします。クライアントは「Browse Name」でタグを検索します。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-9afd0521b6166357fe38494be7b685e258c2cd31%2Fignition-dm-opcua-server-add-tag.png?alt=media" alt="The Add Tag dialog with Display Name Defect Found, Browse Name DefectFound, Data Type Boolean, Access Level ReadWrite, Folder Line1, and Initial Value false" width="500"><figcaption><p>例の <code>DefectFound</code> タグ。</p></figcaption></figure>
5. フォルダーとタグを確認し、「Add Service」をクリックします。タグリストが空の場合、サーバーは起動しないため、少なくとも1つのタグを追加してください。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-32b4c65491f93811c09e604ac025f88c1ebdbea4%2Fignition-dm-opcua-server-tags.png?alt=media" alt="The Configure OPC UA Server modal with a Line1 folder and three tags: Defect Found Boolean, Pass Count Int32, and Last Result String, all ReadWrite in Line1" width="500"><figcaption><p>追加準備が整った、例のフォルダーとタグ。</p></figcaption></figure>

サーバーは次の場所でタグを公開します。 `opc.tcp://<device-ip>:4840/opcua/server`.

## Workflow からサーバーに書き込む

「 [Ignition に結果を書き込む](https://docs.roboflow.com/workflows/ja/chtoriaru/integrate-with-ignition/live-data/write-results-to-ignition.md#build-the-workflow)」と同じように Workflow を構築します。タグごとに OPC UA Writer Sink を1つ配置し、各 Writer Sink の接続先をデバイスのサーバーに設定します。

<table data-search="false"><thead><tr><th>フィールド</th><th>値</th></tr></thead><tbody><tr><td>「Url」</td><td><code>opc.tcp://&#x3C;device-ip>:4840/opcua/server</code></td></tr><tr><td>「Namespace」</td><td>サーバーの「Namespace URI」（例： <code>http://opcua.roboflow.run</code>)</td></tr><tr><td>「オブジェクト名」</td><td>フォルダー（例： <code>Line1</code>)</td></tr><tr><td>「変数名」</td><td>タグの「参照名」（例： <code>DefectFound</code>)</td></tr><tr><td>「値の型」</td><td>タグの「データ型」（例：「Boolean」）</td></tr><tr><td>「ノード検索モード」</td><td>デフォルトは「hierarchical」です。「direct」ではこれらのタグは見つかりません。</td></tr></tbody></table>

「認証を必須にする」を有効にしていない場合は、「ユーザー名」と「パスワード」を空欄にします。

## Ignitionをサーバーに接続する

Ignitionはクライアントとしてデバイスに接続するため、Ignition自体のOPC UAサーバー設定を変更する必要はありません。

1. Ignition Gatewayで「Config」>「OPC Client」>「OPC Connections」の順に移動し、「Create new OPC Connection...」をクリックして「OPC UA」を選択し、「Next」をクリックします。次の値を入力します。 `opc.tcp://<device-ip>:4840/opcua/server` を「Endpoint URL」に入力し、サーバーとエンドポイントの各手順で「Next」をクリックします。「Security Policy: None」のエンドポイントを選択します。

   サーバーはホスト名でアドレスを通知します。Ignitionがその名前を解決できない場合、ウィザードで代替アドレスを指定するよう求められます。「Substitute URL From Discovery」と「Substitute Hostname From Discovery」は、入力したIPアドレスを使用するため、そのまま有効にしておきます。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-636f94b18f0eac9e413f29368723d5c436990b5a%2Fignition-opc-connection-substitute-url.png?alt=media" alt="The Ignition 8.1 connection wizard step Specify an Alternate Discovery URL, with Substitute URL From Discovery set to the device IP address"><figcaption><p>Ignitionはデバイスのホスト名の代わりにIPアドレスを使用します。</p></figcaption></figure>

   「Manage Certificate」で「Trust certificate?」を「Yes」に設定します。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-638c8bc5d62881189a4a69810f308e735b0eb33e%2Fignition-opc-connection-trust-certificate.png?alt=media" alt="The Manage Certificate step showing the Roboflow OPC UA Server certificate with Trust certificate set to Yes"><figcaption><p>デバイスサーバーの証明書を信頼します。</p></figcaption></figure>

   「Finish」をクリックし、接続名（例： `Roboflow Line 1`）を入力して、「Create New OPC Connection」をクリックします。認証を有効にしていない場合は、「Username」と「Password」を空欄にします。接続の「Status」に「Connected」と表示されます。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-dc08d1e78c904a2f674e876773d553809b17e187%2Fignition-opc-connections-list.png?alt=media" alt="The Ignition OPC Connections list with a Roboflow Line 1 connection to the Roboflow device OPC UA Server showing Connected"><figcaption><p>デバイスへの新しい接続。</p></figcaption></figure>
2. タグを確認するには、「Config」>「OPC Client」>「OPC Quick Client」の順に移動して接続を展開し、タグの「\[s]」をクリックして値をサブスクライブします。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-d21deda2f9e3922c47169008d4e4383d3ca02334%2Fignition-opc-quick-client.png?alt=media" alt="The Ignition OPC Quick Client with the Roboflow Line 1 connection expanded to Line1 and subscriptions showing DefectFound true, LastResult fail, and PassCount 128 with Good quality"><figcaption><p>Workflowが書き込んだ値をIgnitionで読み取ったもの。</p></figcaption></figure>
3. Designerで「View」>「Panels」>「OPC Browser」を開き、接続を展開して、タグをTag Browser内のタグプロバイダーにドラッグします。

   <figure><img src="https://4077895066-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-ef40928983f9cfdf27667f072bcd9f99e5784aed%2Fignition-designer-opc-browser.png?alt=media" alt="The Ignition Designer OPC Browser panel with Roboflow Line 1 expanded to the Line1 folder and its DefectFound, LastResult, and PassCount tags" width="300"><figcaption><p>Designerに表示されたデバイスのタグ。</p></figcaption></figure>

デフォルトでは、サーバーは匿名接続を受け入れます。「Configure OPC UA Server」で「Require Authentication」を有効にした場合は、そのユーザー名とパスワードをWriter SinkとIgnitionの接続の両方で使用します。各クライアントは、タグを書き込む各ストリームも含め、1つのセッションを使用します。そのため、多数のストリームやSCADAクライアントが同じサーバーを共有する場合は、「Max Sessions」の値を増やしてください。詳しくは、 [OPC UA Server](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/services/opc-ua-server).

## トラブルシューティング

<table data-search="false"><thead><tr><th>症状</th><th>原因</th><th>対処方法</th></tr></thead><tbody><tr><td>デバイスログ <code>BadNodeIdUnknown</code> がRoboflow OPC UA Serverへの書き込み時に発生する</td><td>「Node Lookup Mode」が「direct」になっている</td><td>「Node Lookup Mode」を「hierarchical」に設定する</td></tr><tr><td>Roboflow OPC UA Serverが再起動を繰り返す</td><td>設定にタグがなく、ログに次のように表示される <code>OPCUA_CONFIG 'tags' array cannot be empty</code></td><td>「Configure OPC UA Server」でタグを1つ以上追加する</td></tr><tr><td>IgnitionがRoboflow OPC UA Serverに接続できない</td><td>サーバーが「Max Sessions」に達し、次のエラーで新しいクライアントを拒否する <code>BadTooManySessions</code></td><td>「Max Sessions」の値を増やし、「OPC UA Refusing Clients」デバイスアラートを追加する</td></tr></tbody></table>
