> 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/ko/tutorials/integrate-with-ignition/live-data/write-results-to-ignition.md).

# 결과를 Ignition에 쓰기

Roboflow Workflow 결과를 OPC UA를 통해 Ignition 태그에 기록하면, 비전 결과에 따라 Ignition 태그 스크립트, 알람 또는 카운터를 실행할 수 있습니다.

이 경로에서는 엣지 디바이스에서 실행되는 Roboflow Workflow가 OPC UA를 통해 결과를 Ignition 태그에 바로 씁니다. 그런 다음 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 %}

## Ignition OPC UA 서버 설정

이 경로에서는 Roboflow 디바이스가 OPC UA 클라이언트이고 Ignition이 서버입니다. Ignition의 기본 설정은 세 가지 방식으로 이 연결을 차단합니다. Gateway에서 "Config" > "OPC UA" > "Server Settings"로 이동한 다음 "Show advanced properties"를 클릭합니다.

<table data-search="false"><thead><tr><th>설정</th><th>기본값</th><th>다음으로 설정</th><th>이유</th></tr></thead><tbody><tr><td>"Bind Addresses"</td><td><code>localhost</code></td><td><code>0.0.0.0</code></td><td>localhost에 바인딩된 서버에는 디바이스가 연결할 수 없습니다.</td></tr><tr><td>"Security Policies"</td><td><code>Basic256Sha256</code></td><td><code>None,Basic256Sha256</code></td><td>OPC UA Writer Sink는 클라이언트 인증서 없이 연결합니다.</td></tr><tr><td>"Expose Tag Providers"</td><td>꺼짐</td><td>켜짐</td><td>그렇지 않으면 Ignition 태그가 OPC UA를 통해 표시되지 않습니다.</td></tr></tbody></table>

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-d4eb99bbba88f95838f26b1e964fe879a743d24d%2Fignition-opcua-server-settings.png?alt=media" alt="The Ignition 8.1 OPC UA Server Settings page with Bind Addresses set to 0.0.0.0, Security Policies set to None,Basic256Sha256, Anonymous Access Allowed off, User Source opcua-module, and Expose Tag Providers on"><figcaption><p>이 경로의 OPC UA 서버 설정입니다.</p></figcaption></figure>

"Save Changes"를 클릭합니다. OPC UA 모듈이 재시작될 때까지 서버는 이전 설정을 유지합니다. "Config" > "System" > "Modules"로 이동하고 "OPC-UA" 행에서 "restart"를 클릭한 다음 확인합니다.

익명 액세스는 꺼진 상태로 둡니다. Ignition의 `opcua-module` 사용자 소스에는 다음 사용자가 포함되어 있습니다. `opcuauser` 그리고 문서화된 기본 비밀번호가 있으며, 이 사용자의 `AuthenticatedUser` 역할에는 태그 쓰기 권한이 있습니다. 해당 비밀번호를 변경하거나 Roboflow용 별도 사용자를 추가합니다.

## 예시 태그

이 페이지에서는 패턴을 보여 주기 위해 태그 두 개를 사용합니다. 설명을 위한 예시이므로 작업 라인에 맞게 이름, 폴더, 데이터 유형을 직접 정하고 Workflow에서도 같은 이름을 사용합니다.

<table data-search="false"><thead><tr><th>태그</th><th>데이터 유형</th><th>의미</th></tr></thead><tbody><tr><td><code>Roboflow/Trigger</code></td><td>Boolean</td><td>Workflow의 조건이 충족되면 디바이스가 다음 값을 씁니다. <code>true</code> (예: 모델이 사람을 감지한 경우). Ignition의 태그 스크립트가 작업을 실행한 다음 태그를 다시 다음 값으로 설정합니다. <code>false</code>.</td></tr><tr><td><code>Roboflow/TriggerCount</code></td><td>정수(Int4)</td><td>작업이 실행된 횟수를 셉니다. 실제 작업(예: 불량품 배출, 알람 또는 데이터베이스 레코드 추가)을 대신하는 예시입니다.</td></tr></tbody></table>

## 태그와 작업 만들기

Designer의 Tag Browser에서 `default` 프로바이더를 선택하고 이름이 다음과 같은 폴더를 만듭니다. `Roboflow`. 폴더를 마우스 오른쪽 버튼으로 클릭하고 "New Tag" > "Memory Tag"를 선택합니다. Tag Editor에서 "Name"을 다음과 같이 설정합니다. `Trigger` 그런 다음 "Data Type"을 "Boolean"으로 설정하고 "OK"를 클릭합니다. 같은 방법으로 `TriggerCount` 를 추가하되, "Data Type"은 "Integer"로 설정합니다.

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-fadbfc0c495319954ba514b198edbb4475dd076c%2Fignition-designer-new-memory-tag.png?alt=media" alt="The Ignition 8.1 Tag Editor for a new tag with Name Trigger, Value Source Memory, and Data Type Boolean"><figcaption><p>새 <code>Trigger</code> 메모리 태그의 Tag Editor입니다.</p></figcaption></figure>

Writer Sink는 "Object Name"과 "Variable Name"을 조합해 태그를 지정하므로, 이 예시에서는 태그를 폴더에 넣습니다. 대신 프로바이더 루트의 태그에 쓰려면 "Object Name"을 태그의 전체 경로로 설정합니다(예: `[default]Trigger`) 그리고 "Variable Name"은 비워 둡니다.

더블 클릭 `Trigger` 하여 Tag Editor를 열고 "Scripting" > "Value Changed"로 이동한 다음, 스크립트 본문에 다음을 붙여 넣습니다:

```python
if initialChange or not currentValue.value:
    return
system.util.getLogger("Roboflow").info("Roboflow trigger fired")
count = system.tag.readBlocking(["[default]Roboflow/TriggerCount"])[0].value or 0
system.tag.writeAsync(["[default]Roboflow/TriggerCount", "[default]Roboflow/Trigger"], [count + 1, False])
```

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-17772b93bfee8a9f18bc3f8e751ae9929ca3ec9d%2Fignition-designer-trigger-script.png?alt=media" alt="The Ignition Tag Editor for the Trigger tag, on Scripting > Value Changed, with a script that logs Roboflow trigger fired, increments TriggerCount, and sets Trigger back to false"><figcaption><p>의 Value Changed 스크립트에서 <code>Trigger</code>.</p></figcaption></figure>

로거와 카운터 줄을 원하는 동작으로 바꿉니다(예: `system.tag.writeAsync` 를 사용해 PLC 태그에 쓰거나, `system.db.runPrepUpdate` 를 사용해 이벤트를 기록하거나, 알람을 발생시킬 수 있습니다). 마지막 쓰기 작업은 그대로 두어야 합니다. 이 작업은 `Trigger` 를 다시 `false`로 설정합니다. 이 작업이 없으면 다음 `true` 는 값 변경으로 인식되지 않으므로 스크립트가 다시 실행되지 않습니다.

## 워크플로 빌드

워크플로는 모델을 실행하고 조건을 확인한 후, 조건이 충족되면 `true` 를 `Trigger` 에 씁니다. Workflow 편집기에서 다음과 같이 빌드합니다:

1. [Workflow를 만들고](https://docs.roboflow.com/workflows/ko/build/create-a-workflow.md) 모델이 포함된 "Object Detection Model" 블록을 추가합니다.
2. 모델 뒤에 "Continue If" 블록을 추가하고 동작을 시작할 조건을 설정합니다(예: 모델이 하나 이상의 `person`).
3. "Continue If" 뒤에 "OPC UA Writer Sink" 블록을 추가합니다. "Workflow Blocks"에서 "OPC UA"를 검색하면 찾을 수 있습니다.

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-53083c474eb542fb6f0c3b3555447b728e7546ed%2Fignition-workflow-opc-writer-graph.png?alt=media" alt="A Workflow in the Roboflow Workflow editor with an Object Detection Model block named model, a Continue If block, and an OPC UA Writer Sink block named ignition_trigger, with outputs predictions, opc_error_status, and opc_message" width="400"><figcaption><p>모델, 조건, Writer Sink입니다.</p></figcaption></figure>

OPC UA Writer Sink를 클릭하고 필드를 입력한 다음, "Show Additional Properties"를 클릭하여 로그인 및 조회 설정을 지정합니다. 이 설정은 Ignition에서 중요합니다:

<table data-search="false"><thead><tr><th>필드</th><th>값</th><th>이유</th></tr></thead><tbody><tr><td>"Url"</td><td><code>opc.tcp://&#x3C;ignition-host>:62541</code></td><td>Ignition의 OPC UA 엔드포인트</td></tr><tr><td>"Namespace"</td><td><code>urn:inductiveautomation:ignition:opcua:tags</code></td><td>Ignition 태그의 네임스페이스 URI입니다. 블록은 연결할 때 해당 인덱스를 조회합니다.</td></tr><tr><td>"개체 이름"</td><td><code>[default]Roboflow</code></td><td>태그 공급자와 폴더</td></tr><tr><td>"변수 이름"</td><td><code>Trigger</code></td><td>태그 이름</td></tr><tr><td>"Value"</td><td><code>1</code></td><td>쓸 값입니다. 이 필드에는 숫자를 입력하며, 블록은 이를 Boolean 태그에 <code>1</code> 로 씁니다. <code>true</code> 값은 Boolean 태그에 기록됩니다.</td></tr><tr><td>"값 유형"</td><td>"Boolean"</td><td>태그의 데이터 유형과 일치해야 합니다</td></tr><tr><td>"쿨다운 시간(초)"</td><td><code>5</code></td><td>쓰기 작업 사이의 최소 간격(초)입니다. <code>0</code> 쿨다운을 비활성화합니다.</td></tr><tr><td>"사용자 이름" 및 "비밀번호"</td><td>Ignition OPC UA 사용자(예: <code>roboflow</code>)</td><td>Ignition은 익명 쓰기를 거부합니다</td></tr><tr><td>"노드 조회 모드"</td><td>"direct"</td><td>Ignition은 문자열 NodeId로 태그를 지정하므로 블록은 다음을 구성합니다. <code>ns=&#x3C;index>;s=[default]Roboflow/Trigger</code>. 기본값인 "hierarchical"은 Ignition 태그를 찾지 못합니다.</td></tr><tr><td>"Fire And Forget"</td><td>꺼짐</td><td>그러면 쓰기 오류가 블록의 <code>error_status</code> 및 <code>message</code> 출력에 표시됩니다. 이 옵션을 켜면 블록은 백그라운드에서 쓰기를 수행하며 <code>error_status</code> 항상 <code>false</code>.</td></tr></tbody></table>

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-22cf7e9f9d1816d7c7bba9f934b7a8c0cda6c191%2Fignition-workflow-opc-writer-settings.png?alt=media" alt="The OPC UA Writer Sink settings in the Workflow editor with Url opc.tcp://192.168.1.20:62541, the Ignition tags namespace, Object Name [default]Roboflow, Variable Name Trigger, Value 1, Value Type Boolean, Cooldown Seconds 5, and Additional Properties with User Name roboflow, a password, and Node Lookup Mode direct"><figcaption><p>예시용으로 설정된 Writer Sink <code>Trigger</code> 태그입니다.</p></figcaption></figure>

사용자 이름과 비밀번호는 Workflow에 저장되므로, Roboflow에는 필요한 태그에만 쓰기 권한이 있는 Ignition 사용자를 지정하세요.

장치에서 쓰기 오류를 확인하려면 블록의 `error_status` 및 `message` 를 Workflow 출력에 추가하세요(예: `opc_error_status` 및 `opc_message`로 추가). 그런 다음 "저장"을 클릭해 Workflow를 게시하세요.

펄스 대신 값을 쓰려면 "Value"를 다른 블록의 출력(예: Property Definition 블록의 감지 횟수)에 연결하고, "Value Type"을 태그 유형과 일치시키세요.

<table data-search="false"><thead><tr><th>Ignition 태그 유형</th><th>"값 유형"</th></tr></thead><tbody><tr><td>Boolean</td><td>Boolean</td></tr><tr><td>정수(Int4)</td><td>Int32</td></tr><tr><td>Double(Float8)</td><td>Double</td></tr><tr><td>String</td><td>String</td></tr></tbody></table>

블록의 "Integer" 값 유형은 "Int64"의 별칭이므로 Int4인 Ignition의 "Integer" 태그와 일치하지 않습니다. "Int32"를 사용하세요. 블록은 "Float", "Int16", "SByte", "UInt16", "UInt32", "UInt64"도 지원합니다.

## Workflow를 장치에 배포하기

장치에서 Workflow를 스트림으로 실행합니다. Deployment Manager에서 장치를 열고 "Add Stream"을 클릭하세요. "Workflow ID"에서 Workflow를 선택하고, 모든 프레임에서 Workflow가 실행되도록 "Mode"를 "Continuous"로 설정한 다음 카메라의 "RTSP URL"을 입력하세요. "Create Stream"을 클릭하세요. 자세히 알아보려면 [스트림 추가](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/setting-up/add-a-stream).

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-984d374ce6073fa4a5e55d5aa3b143d738ffa06e%2Fignition-dm-add-stream-continuous.png?alt=media" alt="The Deployment Manager Add New Video Stream dialog with Name line-1-camera, the Workflow selected, Workflow Version Latest (auto-update), Mode Continuous, Stream Type RTSP Stream, and an RTSP URL" width="400"><figcaption><p>연속 스트림은 모든 프레임에서 Workflow를 실행합니다.</p></figcaption></figure>

OPC UA 설정은 Workflow에 저장되므로 스트림에 별도의 설정이 필요하지 않습니다.

## 연결 테스트

스트림에 "Running"이 표시되면 장치는 조건이 충족될 때마다 `true` 를 `Trigger` 에 씁니다. 단, 최대 쓰기 빈도는 5초에 한 번입니다. 양쪽에서 확인하세요.

* Ignition에서 `TriggerCount` 증가하고 게이트웨이 로그에 `Roboflow 트리거가 실행됨`.

<figure><img src="https://3843302164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoO0Ceoy9R0lHDZATcPyh%2Fuploads%2Fgit-blob-3be63b7b4cb1d061c4389780e21dc7b5e8887e4e%2Fignition-designer-roboflow-tags.png?alt=media" alt="The Ignition Designer Tag Browser with the default provider selected and the Roboflow folder expanded, showing Trigger false and TriggerCount 3"><figcaption><p><code>TriggerCount</code> 장치에서 세 번 쓴 후에 표시됩니다.</p></figcaption></figure>

* Deployment Manager에서 장치 로그에 `OPC Writer successfully wrote` 각 쓰기 후 info 수준으로 표시되고, 실패는 `OPC Writer` 경고 또는 오류로 표시됩니다. 증가하는 `TriggerCount` 가 확실한 확인 방법입니다. 성공 로그는 장치 로그가 info 수준으로 설정된 경우에만 표시되기 때문입니다.

라인이 실행되기 전에 테스트하려면 Workflow를 두 번째 스트림으로 추가하고, "Mode"를 "Triggered"로 설정한 다음, 조건을 통과하는 대상을 카메라에 비추고 Deployment Manager에서 해당 스트림의 "Trigger"를 클릭하세요. `TriggerCount` 가 1 증가합니다. 자세한 내용은 [스트림 트리거하기](https://docs.roboflow.com/deployment/self-hosted/enterprise/deployment-manager/making-changes/trigger-a-stream).

## 문제 해결

<table data-search="false"><thead><tr><th>증상</th><th>원인</th><th>해결 방법</th></tr></thead><tbody><tr><td>장치 로그 <code>WRONG NAMESPACE ERROR</code></td><td>네임스페이스 URI가 서버와 일치하지 않거나 Ignition 태그가 OPC UA를 통해 노출되지 않았습니다.</td><td>"Namespace"를 확인하고 "Expose Tag Providers"를 켜세요.</td></tr><tr><td>장치 로그 <code>WRONG OBJECT OR PROPERTY ERROR</code></td><td>태그 경로가 잘못되었거나, 루트 태그에 "Variable Name"이 설정되어 있거나, Ignition에서 "Node Lookup Mode"가 "hierarchical"로 설정되어 있습니다.</td><td>"Object Name"과 "Variable Name"을 확인하고 "Node Lookup Mode"를 "direct"로 설정하세요.</td></tr><tr><td>장치 로그 <code>WRONG TYPE ERROR</code></td><td>"Value Type"이 태그의 데이터 형식과 일치하지 않습니다.</td><td>형식을 일치시키세요(예: Ignition의 "Integer" 태그에는 "Int32" 사용).</td></tr><tr><td>장치 로그 <code>Connection is closed</code> Ignition이 재시작된 후 한 번 표시됩니다.</td><td>블록의 풀링된 OPC UA 세션이 오래되어 쓰기 한 건이 손실됩니다.</td><td>수정할 필요가 없습니다. 다음 쓰기 때 다시 연결됩니다.</td></tr><tr><td><code>TriggerCount</code> 장치에서 계속 쓰기를 수행하는데도 증가하지 않습니다.</td><td><code>Trigger</code> 가 <code>true</code>에 고정되어 있어 새 쓰기가 값 변경으로 처리되지 않습니다.</td><td>다음을 설정하세요: <code>Trigger</code> 을 <code>false</code>로 설정하고 스크립트에 초기화 라인을 유지하세요.</td></tr><tr><td><code>Trigger</code> 또는 <code>Inspect</code> 가 <code>true</code> 상태로 유지됩니다(시험용 게이트웨이에서).</td><td>Ignition 평가판 사용 기간이 만료되었습니다. OPC UA 쓰기는 계속 적용되지만 태그 스크립트는 실행되지 않습니다.</td><td>체험판을 재설정한 다음 태그를 다시 다음 값으로 설정합니다. <code>false</code></td></tr></tbody></table>

## 보안

장치와 Ignition 게이트웨이를 플랜트 또는 OT 네트워크에 연결된 상태로 유지하세요.

* OPC UA Writer Sink와 OPC UA Reader는 다음 보안 정책으로 연결합니다. `None`. 따라서 OPC UA 트래픽에 서명이나 암호화가 적용되지 않습니다.
* Ignition의 OPC UA 서버를 다음 주소에 바인딩하면 `0.0.0.0` Ignition 호스트의 모든 네트워크 인터페이스에서 포트 62541이 열립니다.
* Roboflow 전용 Ignition OPC UA 사용자를 만들고, 다음 항목에 대한 쓰기 권한만 부여하세요. `Roboflow` 폴더에만.
