我如何将数据从python传输到opc da服务器?

问题描述 投票:0回答:2

我用PYTHON写了一段代码。我想将相应的输出传输到 OPC DA 服务器,以便客户端可以从资源管理器访问它。我可以创建一个空的配置别名,在其中填充我的值,然后显示它或任何类似的逻辑简单解决方案吗?我想到的唯一方法是将输出数据传输到模拟项目,但这并不是真正的解决方案,因为我只想显示我的数据..

python client-server opc opc-da
2个回答
0
投票

您可以使用MODBUS或OPC传输值。您可以使用 OpenOPCPyOPC 来完成此操作,但您可能希望使用较新的 OPC-UA 标准。有一个针对 OPC-UA 开发良好的 Python 包。如果您确实需要使用旧的 DA 标准,这里是 OpenOPC 的示例代码。

# #######################################
# OPC write
# #######################################
try:
    # OPC connection
    import OpenOPC
    opc=OpenOPC.client()
    b=opc.connect('Kepware.KEPServerEX.V5')
    #opc.connect('Kepware.KEPServerEX.V5','localhost')

    Load1_avg  = opcm[0][0]
    Load2_avg  = opcm[0][1]

    opc.write( ('Channel2.Device1.T_12_Load_AVG',Load1_avg) )
    opc.write( ('Channel2.Device1.T_21_Load_AVG',Load2_avg) )

    opc.close()
except:
    print 'OPC communication failed'
    pass

我已在多个应用程序上成功地将其与 Kepware 服务器一起使用。


0
投票

通过 OPC DA 操作值的代码,类似于 @john-hedengren 的答案,但使用 QuickOPC 库:

import opclabs_quickopc
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *

client = EasyDAClient()

try:
    IEasyDAClientExtension.WriteItemValue(client, '', 'Kepware.KEPServerEX.V5', 'Channel2.Device1.T_12_Load_AVG', Load1_avg)
    IEasyDAClientExtension.WriteItemValue(client, '', 'Kepware.KEPServerEX.V5', 'Channel2.Device1.T_21_Load_AVG', Load2_avg)
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

OPC UA(统一架构)需要一些更改,但代码原则上是相似的。

© www.soinside.com 2019 - 2024. All rights reserved.