6. OPC 서비스
client.opc() 으로 접근합니다. OPC는 소스 연결(Source Connection)을 나타냅니다. OPC UA 서버, PLC, Modbus 장치, 데이터베이스, 메시지 브로커, REST API 등 외부 데이터의 진입점입니다.
ID 규칙:
OPC_접두사 필수. 자세한 내용은 도메인 ID 규칙 참고.
6.1 메서드 일람
| 메서드 | 반환 타입 | HTTP | 엔드포인트 |
|---|---|---|---|
create(OPCRequestV5) | OPCResponseV5 또는 null | POST | /api/v5/opc |
update(opc_id, OPCRequestV5) | OPCResponseV5 또는 null | PUT | /api/v5/opc/{id} |
delete(opc_id) | boolean | DELETE | /api/v5/opc/{id} |
get(opc_id) | OPCResponseV5 또는 null | GET | /api/v5/opc/{id} |
list() | List<OPCResponseV5> | GET | /api/v5/opc |
listBySite(site_id) | List<OPCResponseV5> | GET | /api/v5/opc?site_id=... |
listByType(opc_source_type) | List<OPCResponseV5> | GET | /api/v5/opc?opc_source_type=... |
exists(opc_id) | boolean | GET | /api/v5/opc/{id}/exists |
count() | long | GET | /api/v5/opc/count |
countBySite(site_id) | long | GET | /api/v5/opc/count?site_id=... |
6.2 프로토콜과 소스 유형
연결은 프로토콜(opc_protocol, 예: S7·LS·MELSEC·MODBUS·OPCUA·MQTT_CLIENT·API)을 가집니다.
소스 유형과 수집 주체는 프로토콜에서 파생되며 직접 쓰지 않습니다. 프로토콜 어휘의 정본은 plantpulse-event 의 프로토콜 카탈로그입니다.
| 소스 유형 | 용도 |
|---|---|
OPC | OPC UA 서버 |
PLC | Siemens, LS, Mitsubishi, Allen-Bradley 등 PLC 직결 |
MODBUS | Modbus TCP/UDP/RTU 장치 |
DATABASE | 외부 데이터베이스 폴링 |
MESSAGING | 메시지 브로커·푸시 프로토콜 (MQTT, Kafka, HTTP, WebSocket, CoAP, ROS 2) |
API | PlantPulse REST API 로 들어오는 데이터 |
SYSTEM | 엣지 게이트웨이 자기감시 (OPC_SYSTEM_<edge_id>, 엣지가 선언) |
6.3 OPCRequestV5 / OPCResponseV5
| 필드 | 타입 | 설명 |
|---|---|---|
opc_id | String | OPC ID (PK, OPC_ 필수) |
opc_name | String | OPC 표시명 |
opc_protocol | String | 프로토콜 코드 (예: S7, LS, OPCUA, API) |
opc_source_ip | String | 실제 소스(PLC·장치·OPC UA 서버·DB·브로커)의 IP 또는 호스트 |
opc_source_port | int | 실제 소스의 포트 |
opc_edge_id | String | 이 연결을 수집하는 엣지. 플랫폼이 직접 수집하면 비운다 |
opc_source_type | String | (응답 전용) 프로토콜에서 파생된 소스 유형 |
opc_collected_by | String | (응답 전용) EDGE / PLATFORM — 프로토콜에서 파생 |
site_id | String | 소속 사이트 |
description | String | 설명 |
엣지가 수집하는 연결(
opc_edge_id가 있는 연결)의 프로토콜·주소는 엣지 sync(PUT /api/v5/opc/{id}/sync)만 씁니다. 플랫폼 화면에서는 읽기 전용입니다.
6.4 사용 예시
OPC 생성 (PLC 직결)
import plantpulse.api.v5.dto.request.OPCRequestV5;
import plantpulse.api.v5.dto.response.OPCResponseV5;
OPCRequestV5 req = new OPCRequestV5();
req.setOpc_id("OPC_PLC_L1_001");
req.setOpc_name("Line1 메인 PLC");
req.setOpc_protocol("S7");
req.setSite_id("SITE_DJ");
req.setOpc_source_ip("192.168.10.50");
req.setOpc_source_port(102);
OPCResponseV5 created = client.opc().create(req);
OPC 생성 (외부 REST API)
OPCRequestV5 api = new OPCRequestV5();
api.setOpc_id("OPC_API_ERP_001"); // OPC_ 접두사 필수
api.setOpc_name("ERP 생산 실적 API");
api.setOpc_protocol("API");
api.setSite_id("SITE_DJ");
api.setDescription("매시간 ERP에서 생산 카운트 폴링");
client.opc().create(api);
OPC 생성 (테스트용 — API 소스)
OPCRequestV5 v = new OPCRequestV5();
v.setOpc_id("OPC_TEST_001");
v.setOpc_name("테스트용 OPC");
v.setOpc_protocol("API");
v.setSite_id("SITE_000001");
client.opc().create(v);
사이트별 OPC 조회
import java.util.List;
List<OPCResponseV5> djOpcs = client.opc().listBySite("SITE_DJ");
for (OPCResponseV5 opc : djOpcs) {
System.out.println(opc.getOpc_id() + " (" + opc.getOpc_protocol() + ", " + opc.getOpc_source_type() + ")");
}
소스 유형별 OPC 조회
// 사이트를 가리지 않고 PLC 만
List<OPCResponseV5> plcs = client.opc().listByType("PLC");
// 사이트를 가리지 않고 Modbus 만
List<OPCResponseV5> modbus = client.opc().listByType("MODBUS");
카운트
long total = client.opc().count();
long djCount = client.opc().countBySite("SITE_DJ");
System.out.printf("전체 OPC: %d, 대전공장: %d%n", total, djCount);
CUD 라이프사이클
String opcId = "OPC_PLC_L1_001";
// 생성
OPCRequestV5 req = new OPCRequestV5();
req.setOpc_id(opcId);
req.setOpc_name("초기 이름");
req.setOpc_protocol("S7");
req.setSite_id("SITE_DJ");
client.opc().create(req);
// 존재 여부 확인
assert client.opc().exists(opcId);
// 수정
req.setOpc_name("수정된 이름");
client.opc().update(opcId, req);
// 삭제
boolean deleted = client.opc().delete(opcId);
assert !client.opc().exists(opcId);
6.5 활용 시나리오
시나리오 — 신규 라인 PLC 등록 후 태그 수집 대기
// 1) OPC 등록
OPCRequestV5 plc = new OPCRequestV5();
plc.setOpc_id("OPC_PLC_L2_001");
plc.setOpc_protocol("S7");
plc.setSite_id("SITE_DJ");
plc.setOpc_source_ip("192.168.10.60");
plc.setOpc_source_port(102);
client.opc().create(plc);
// 2) 수집이 시작되면 — 이후 Tag 서비스에서 확인
List<TagResponseV5> tags = client.tag().listByOpc("OPC_PLC_L2_001");
System.out.println("수집된 태그 수: " + tags.size());