创建了一个简单的客户端和服务器,并试图在wireshark中捕获动作,但无法看到OPC UA协议在相同的.我已经做了这个代码在windows 10上的pycharm,你可以请指出问题是在哪里看到OPCUA协议在wiresharki已添加服务器代码,我已经使用,并添加客户端代码和附加wireshark图像作为一个png文件服务器代码。
from opcua import Server
from random import randint
from xlwt import Workbook
import datetime
import time
server = Server()
workbook = Workbook()
sheet = workbook.add_sheet('sheet 1')
#sheet.write(j, 0, time.time())
#workbook.save("sub_ohio_latency_ACK.xls")
url = "opc.tcp://LAPTOP-9UCODEJ5:48020"
server.set_endpoint(url)
name = "OPCUA_Server"
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")
Temp = Param.add_variable(addspace, "Temperature",0)
Time = Param.add_variable(addspace, "Time",0)
i = Param.add_variable(addspace, "TagID", 0)
Temp.set_writable()
Time.set_writable()
l = server.get_objects_node()
p = server.get_node(Temp)
k = server.get_node(Time)
j = server.get_node(i)
print(k)
print(p)
print(l)
print(j)
server.start()
print("server started at ()".format(url))
c = 0
while True:
Temperature = randint(0,20)
TIME = datetime.datetime.now()
TagID = c
print(Temperature, TIME, c)
Temp.set_value(Temperature)
Time.set_value(TIME)
i.set_value(c)
c += 1
#time.sleep(2)
客户端代码
from opcua import Client
import time
from xlwt import Workbook
workbook =Workbook()
#workbook2=Workbook()
sheet = workbook.add_sheet('sheet 1')
url = "opc.tcp://192.168.0.108:48020"
client = Client(url)
client.connect()
print("client connected")
for i in range(2000):
objects = client.get_objects_node()
l = client.get_node("ns=2;i=2")
Temperature = l.get_value()
#print(Temperature)
k = client.get_node("ns=2;i=3")
Time = k.get_value()
j = client.get_node("ns=2;i=4")
msg_tag = j.get_value()
sheet.write(i, 0, msg_tag)
sheet.write(i, 1, Temperature)
sheet.write(i, 2, Time)
sheet.write(i,3,time.time())
workbook.save("test_client.xls")
#print(Time)
#print(msg_tag)
#print(objects)
#time.sleep(5)
client.disconnect()
print("client disconnected")