OPC UA는 사실 레퍼런스도 공개되어 있으며, 이를 바탕으로 한 라이브러리가 이미 공개되어 있다.
https://opcfoundation.org/developer-tools/samples-and-tools-unified-architecture
Unified Architecture - OPC Foundation
The following Unified Architecture sample code is provided to demonstrate Server and Client implementations, along with many other aspects of UA technology. Certified Commercial OPC toolkits are the most effective way to maximize productivity while reducin
opcfoundation.org
해당 주소를 방문하면 다양한 플랫폼에서 개발환경을 지원하는 것을 확인할 수 있다.
웹 사이트 가입 시 소스코드를 제공해주지만, .NET의 경우 github을 통해서 가입 없이 소스코드를 다운받을 수 있다.
( github에 fuzzing을 위한 솔루션도 제공해주어 afl을 통한 fuzzing도 진행해보고 있다 )
https://github.com/OPCFoundation/UA-.NETStandard
GitHub - OPCFoundation/UA-.NETStandard: OPC Unified Architecture .NET Standard
OPC Unified Architecture .NET Standard. Contribute to OPCFoundation/UA-.NETStandard development by creating an account on GitHub.
github.com
해당 소스코드를 분석해서 OPC-UA 패킷 파서를 구현해야 하는 줄 알았으나, reference문서를 아래에서 찾을 수 있었다.
Home Page - OPC Foundation
Welcome to the World of OPC In today’s complex economy, information is the key to business success and profitability. OPC technologies were created to allow information to be easily and securely exchanged between diverse platforms from multiple vendors a
opcfoundation.org
심지어 python pip 로 이미 배포가 되어있어, 실습은 어렵지 않았다.
!pip install opcua
로 설치할 수 있었으며, 이전 포스트에서 진행했던 ROBO DK를 통해 OPC-UA server를 시작한 상태라면
from opcua import Client
url = "opc.tcp://localhost:4840"
client=Client(url)
client.connect()
을 통해 OPC-UA 서버에 연결을 수립할 수 있다.
물론 이 경우에는 SSL 인증서는 없이 연결된다. ( 서버 측에서 SSL 인증서와 그 외 인증 절차 없이 접속하는 것을 허가해주어야한다 )
실습을 위해서
NodeId 가 ns=1;i=3 인 value를 읽어보겠다.
UaExpert를 통해 해당 value는 현재 5라는 것을 알 수 있으며 아래 코드를 실행시켜보면
import time
cnt =0;
while cnt<=3:
normal = client.get_node("ns=1;i=3")
print(normal.get_value())
time.sleep(4)
cnt+=1
예상대로 5가 출력된다. 이를 통해, 이미 개발 된 opcua lib을 사용하여 python으로 opc-ua 통신이 가능하다는 것을 확인하였다.
추가로...
https://github.com/techbeast-org/opc-ua
GitHub - techbeast-org/opc-ua: Repository contains sample OPC UA server and OPC UA client async code
Repository contains sample OPC UA server and OPC UA client async code - techbeast-org/opc-ua
github.com
해당 깃허브 소스코드를 통해 실습을 진행해보면, python을 통해 opc-ua server를 구축하고, python으로 된 opc-ua client 프로세스를 실행하여 통신해볼 수 있다.
opcua lib 없이 python으로 opc-ua 통신을 하는 소스코드를 개발하는 내용으로 다음 포스트를 작성하겠다.
'study' 카테고리의 다른 글
[Network] SynFlood 실습 Docker 사용 (0) | 2024.05.05 |
---|---|
[Network] SynFlood 실습 VM 이용 시 주의사항 (0) | 2024.05.05 |
[CPS] OPC UA 프로토콜 실습 (0) | 2024.05.05 |
[CPS] OPC UA 프로토콜 정리 (0) | 2024.05.05 |
[RAID] h/w raid card 03 (0) | 2024.04.29 |