6. OPC Service
Access via client.opc(). OPC represents a data collection channel (Data Source). It is the entry point for external data such as OPC UA servers, PLCs, Modbus, RDBMS, REST API/files, and virtual channels.
ID rule: The
OPC_orAPI_prefix is mandatory. For details, see Domain ID Rules.
6.1 Method List
| Method | Return Type | HTTP | Endpoint |
|---|---|---|---|
create(OPCRequestV5) | OPCResponseV5 or null | POST | /api/v5/opc |
update(opc_id, OPCRequestV5) | OPCResponseV5 or null | PUT | /api/v5/opc/{id} |
delete(opc_id) | boolean | DELETE | /api/v5/opc/{id} |
get(opc_id) | OPCResponseV5 or 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_type) | List<OPCResponseV5> | GET | /api/v5/opc?opc_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 Type Values
| Value | Purpose |
|---|---|
OPC | OPC UA / OPC DA server |
PLC | Direct PLC connection such as Siemens, Mitsubishi, Allen-Bradley |
MODBUS | Modbus TCP/RTU device |
DATABASE | External RDBMS (Oracle, MSSQL, etc.) |
FILE | REST API / file import |
VIRTUAL | Virtual channel (for simulation and testing) |
6.3 OPCRequestV5 / OPCResponseV5
| Field | Type | Description |
|---|---|---|
opc_id | String | OPC ID (PK, OPC_ or API_ required) |
opc_name | String | OPC display name |
opc_type | String | OPC/PLC/MODBUS/DATABASE/FILE/VIRTUAL |
opc_sub_type | String | Detailed type (e.g., PLC manufacturer) |
opc_server_ip | String | OPC server IP |
opc_agent_ip | String | Data collection agent IP |
opc_agent_port | int | Agent port |
site_id | String | Owning site |
description | String | Description |
6.4 Usage Examples
Creating an OPC (Direct PLC Connection)
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_type("PLC");
req.setOpc_sub_type("SIEMENS_S7");
req.setOpc_server_ip("192.168.10.50");
req.setSite_id("SITE_DJ");
req.setOpc_agent_ip("192.168.10.5");
req.setOpc_agent_port(60000);
OPCResponseV5 created = client.opc().create(req);
Creating an OPC (External REST API)
OPCRequestV5 api = new OPCRequestV5();
api.setOpc_id("API_ERP_001"); // 관례상 API_ 접두사
api.setOpc_name("ERP 생산 실적 API");
api.setOpc_type("FILE");
api.setSite_id("SITE_DJ");
api.setDescription("매시간 ERP에서 생산 카운트 폴링");
client.opc().create(api);
Creating an OPC (Virtual — for Testing)
OPCRequestV5 v = new OPCRequestV5();
v.setOpc_id("OPC_VIRTUAL_001");
v.setOpc_name("테스트용 가상 OPC");
v.setOpc_type("VIRTUAL");
v.setSite_id("SITE_00001");
v.setOpc_agent_ip("127.0.0.1");
v.setOpc_agent_port(0);
client.opc().create(v);
Querying OPCs by Site
import java.util.List;
List<OPCResponseV5> djOpcs = client.opc().listBySite("SITE_DJ");
for (OPCResponseV5 opc : djOpcs) {
System.out.println(opc.getOpc_id() + " (" + opc.getOpc_type() + ")");
}
Querying OPCs by Type
// 모든 사이트의 PLC만
List<OPCResponseV5> plcs = client.opc().listByType("PLC");
// 모든 사이트의 Modbus만
List<OPCResponseV5> modbus = client.opc().listByType("MODBUS");
Count
long total = client.opc().count();
long djCount = client.opc().countBySite("SITE_DJ");
System.out.printf("전체 OPC: %d, 대전공장: %d%n", total, djCount);
CUD Lifecycle
String opcId = "OPC_PLC_L1_001";
// 생성
OPCRequestV5 req = new OPCRequestV5();
req.setOpc_id(opcId);
req.setOpc_name("초기 이름");
req.setOpc_type("PLC");
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 Application Scenarios
Scenario — Waiting for tag collection after registering a PLC on a new line
// 1) OPC 등록
OPCRequestV5 plc = new OPCRequestV5();
plc.setOpc_id("OPC_PLC_L2_001");
plc.setOpc_type("PLC");
plc.setSite_id("SITE_DJ");
plc.setOpc_server_ip("192.168.10.60");
plc.setOpc_agent_ip("192.168.10.5");
plc.setOpc_agent_port(60000);
client.opc().create(plc);
// 2) 에이전트가 자동으로 태그를 수집하면 — 이후 Tag 서비스에서 확인
List<TagResponseV5> tags = client.tag().listByOpc("OPC_PLC_L2_001");
System.out.println("수집된 태그 수: " + tags.size());
Next Steps
- Asset Service — Asset tree for linking Equipment and tags
- Tag Service — Tag definition and OPC connection