OPC UA 최소 읽기 및 쓰기
개요
이 기사에서는 OPC UA 서버 측 My Object>My Bariable에 대한 쓰기, 읽기 값을 보여 줍니다.
OPC UA 서버에서 데이터를 쓰고 읽는 데 필요한 최소한의 OPC UA 그룹을 나타내는 매개 변수입니다.
UaExpert를 통해 Python용 OPC UA Server 라이브러리를 사용하는 서버와 연결, 읽기, 쓰기를 위한 통신 데이터 패키지를 가져옵니다.
그 데이터 패키지의 일부를 변경해서 서버에 보내서 정상적으로 통신하게 했다.이때 메모는 다음과 같습니다.
※ 주의: OPC UA의 규격을 확인한 것이 아니라 개인 분석이기 때문에 본 기사의 내용은 모든 OPC UA 서버에 적용되지 않습니다.
설명 절차는 다음과 같다.
환경
OPC UA Server : https://github.com/FreeOpcUa/python-opcua
Python3 : Python 3.6.9
OPC UA 서버측 IP 주소: 192.168.1.35
OPC UA 클라이언트 IP 주소: 192.168.1.104
서버 측 준비
서버 프로그램
서버 프로그램을 실행합니다.sango@example:~/opcua$ python3 serv.py
Endpoints other than open requested but private key and certificate are not set.
Listening on 0.0.0.0:4840
다음은 소스 코드입니다.import sys
sys.path.insert(0, "..")
import time
from opcua import ua, Server
if __name__ == "__main__":
# setup our server
server = Server()
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our nodes
objects = server.get_objects_node()
# populating our address space
myobj = objects.add_object(idx, "MyObject")
myvar = myobj.add_variable(idx, "MyVariable", 3535)
myvar.set_writable() # Set MyVariable to be writable by clients
# start
server.start()
try:
while True:
time.sleep(1)
finally:
#close connection, remove subcsriptions, etc
server.stop()
(참조) 이 예제의 UaExpert 서버 모양새 방법
세션 설정 (클라이언트)
Hello message & Ack
서버 프로그램
서버 프로그램을 실행합니다.
sango@example:~/opcua$ python3 serv.py
Endpoints other than open requested but private key and certificate are not set.
Listening on 0.0.0.0:4840
다음은 소스 코드입니다.import sys
sys.path.insert(0, "..")
import time
from opcua import ua, Server
if __name__ == "__main__":
# setup our server
server = Server()
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our nodes
objects = server.get_objects_node()
# populating our address space
myobj = objects.add_object(idx, "MyObject")
myvar = myobj.add_variable(idx, "MyVariable", 3535)
myvar.set_writable() # Set MyVariable to be writable by clients
# start
server.start()
try:
while True:
time.sleep(1)
finally:
#close connection, remove subcsriptions, etc
server.stop()
(참조) 이 예제의 UaExpert 서버 모양새 방법
세션 설정 (클라이언트)
Hello message & Ack
Open Secure Channel Request & Response
요청할 때 Sequence Number를 설정하고 나중에 요청할 때마다 1씩 증가합니다.
또한 이후 Sequence Number의 이름은 Security Sequence Number로 변경됩니다.
이 예에서는 SequenceNumber(Security SequenceNumber)로 설정합니다. 51.
SecureChannel Id 및 Secure Token Id를 기록해 둡니다.
이 예에서는 SecureChannel Id:7, Secure Token Id:14입니다.
나중에 클라이언트 측에서 요청을 보낼 때 이 두 Id를 머리 부분에 설정해야 합니다.
Create Session Request & Response
이 예에서 방금 기록한 Secure Channel Id:7, Secure Token Id:14를 설정하고 요청을 보냅니다.
이 예에서 보안 시퀀스 번호: 52.
Activate Session Request & Response
이 예에서 방금 기록한 Secure Channel Id:7, Secure Token Id:14를 설정하고 요청을 보냅니다.
이 예에서는 보안 시퀀스 번호:53으로 설정합니다.
쓰기 (클라이언트)
위에서 말한 바와 같이 OPC UA 서버가 시작될 때 My Object>My Bariable 저장소는 3535입니다.
이 예에서 MyObject>Mybariable에 4047(0x0fcf)을 기록합니다.
이 예에서 Namespace Index:2, Identifier Numeric:2를 지정했는데 이것은 My Object>My Bariable을 가리킨다.
(확인되지 않음) EncodingMask에서 has value(0x01)를 지정해야 할 수 있습니다.
메시지 크기를 올바르게 설정하지 않으면 서버 측에서 OPC UA 그룹을 올바르게 식별할 수 없습니다.
메시지 크기의 범위는 WireShark의 OpcUa Binary Protocol을 가리킨다.
읽기 (클라이언트)
읽을 Namespace 인덱스 지정, Identifier Numeric
이 예에서 Namespace Index:2, Identifier Numeric:2를 지정했는데 이것은 My Object>My Bariable을 가리킨다.
읽을 속성 지정 Id
이 예에서는 값(0x000000d)을 지정합니다.
이 예에서 방금 설정한 My Object>My Bariable에서 4047(0x0fcf)을 읽습니다.
총결산
Reference
이 문제에 관하여(OPC UA 최소 읽기 및 쓰기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/sang0/items/7e0e93da897a7917dd6e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)