合并sf代码
This commit is contained in:
@@ -2,22 +2,35 @@ from opcua import ua, Client
|
||||
|
||||
|
||||
class Py2opcua:
|
||||
"""
|
||||
将三元检测补偿值写入opcua服务器
|
||||
"""
|
||||
|
||||
def __init__(self, url='opc.tcp://192.168.2.99:4840'):
|
||||
self.client = Client(url)
|
||||
|
||||
def connect(self):
|
||||
|
||||
try:
|
||||
# 连接客户端
|
||||
self.client.connect()
|
||||
print("opcua服务器连接成功,可以写入")
|
||||
return self.client
|
||||
except:
|
||||
print("opcua服务器连接失败,请检查")
|
||||
# 连接客户端
|
||||
# def connect(self):
|
||||
# try:
|
||||
# self.client.connect()
|
||||
# print("opcua服务器连接成功,可以写入")
|
||||
# return self.client
|
||||
# except Exception as e:
|
||||
# print("opcua服务器连接失败,请检查" + str(e))
|
||||
|
||||
def write(self, temp_dict):
|
||||
temp_dict = temp_dict
|
||||
"""
|
||||
补偿值写入方法,参数是一个字典,键是节点名,值是补偿值
|
||||
:param temp_dict:
|
||||
:return:
|
||||
"""
|
||||
# try:
|
||||
self.client.connect()
|
||||
# print("opcua服务器连接成功,可以写入")
|
||||
# return self.client
|
||||
# except Exception as e:
|
||||
# print("opcua服务器连接失败,请检查" + str(e))
|
||||
# temp_dict = temp_dict
|
||||
temp_list = list(temp_dict.items())
|
||||
for i in range(len(temp_list)):
|
||||
# 寻找节点上的变量
|
||||
@@ -25,8 +38,9 @@ class Py2opcua:
|
||||
# var.set_value(ua.Variant(1.234, ua.VariantType.Float))
|
||||
# 通过set_value写值
|
||||
var.set_value(ua.Variant(temp_list[i][1], ua.VariantType.Double))
|
||||
print("%s 已写入" % var.get_value())
|
||||
|
||||
def disconnect(self):
|
||||
# 断开连接
|
||||
# print("%s 已写入" % var.get_value())
|
||||
self.client.disconnect()
|
||||
|
||||
# 断开连接
|
||||
# def disconnect(self):
|
||||
# self.client.disconnect()
|
||||
|
||||
Reference in New Issue
Block a user