Skip to main content

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_ or API_ prefix is mandatory. For details, see Domain ID Rules.

6.1 Method List

MethodReturn TypeHTTPEndpoint
create(OPCRequestV5)OPCResponseV5 or nullPOST/api/v5/opc
update(opc_id, OPCRequestV5)OPCResponseV5 or nullPUT/api/v5/opc/{id}
delete(opc_id)booleanDELETE/api/v5/opc/{id}
get(opc_id)OPCResponseV5 or nullGET/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)booleanGET/api/v5/opc/{id}/exists
count()longGET/api/v5/opc/count
countBySite(site_id)longGET/api/v5/opc/count?site_id=...

6.2 OPC Type Values

ValuePurpose
OPCOPC UA / OPC DA server
PLCDirect PLC connection such as Siemens, Mitsubishi, Allen-Bradley
MODBUSModbus TCP/RTU device
DATABASEExternal RDBMS (Oracle, MSSQL, etc.)
FILEREST API / file import
VIRTUALVirtual channel (for simulation and testing)

6.3 OPCRequestV5 / OPCResponseV5

FieldTypeDescription
opc_idStringOPC ID (PK, OPC_ or API_ required)
opc_nameStringOPC display name
opc_typeStringOPC/PLC/MODBUS/DATABASE/FILE/VIRTUAL
opc_sub_typeStringDetailed type (e.g., PLC manufacturer)
opc_server_ipStringOPC server IP
opc_agent_ipStringData collection agent IP
opc_agent_portintAgent port
site_idStringOwning site
descriptionStringDescription

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