【问题标题】:Python 3.6 x64 OpenOPCPython 3.6 x64 OpenOPC
【发布时间】:2018-10-15 20:15:16
【问题描述】:

我正在开发一个张量流模型来推断产品属性。我想让这个模型运行从 OPC 服务器在线读取数据并将结果写回。为此,我正在使用 OpenOPC 项目。

Tensorflow 仅适用于 64 位操作系统中的 Python 3.6。所以我需要在同一个环境中建立一个OPC连接。

OpenOPC 最初设计用于 x86 操作系统中的 Python 2.7。有一些项目将其升级为使用 Python 3.4+。我按照以下链接中的过程进行安装: https://github.com/joseamaita/openopc120

我正在使用 Windows 2012 Server 的 VM 中开发我的模型。对于 OPC Server,我使用 Matrikon OPC 进行模拟。

OpenOPC 的列表功能似乎工作正常。当我运行以下脚本时

import OpenOPC
open_host='10.0.2.15'
open_port='7766'

opc = OpenOPC.open_client(open_host, open_port)
opc.connect('Matrikon.OPC.Simulation.1')

aux=opc.list('Simulation Items.Random')
for item in aux:
    print(item)

opc.close()

我得到了以下结果

Random.ArrayOfReal8
Random.ArrayOfString
Random.Boolean
Random.Int1
Random.Int2
Random.Int4
Random.Money
Random.Qualities
Random.Real4
Random.Real8
Random.String
Random.Time
Random.UInt1
Random.UInt2
Random.UInt4

这是有希望的。但是当我尝试运行以下代码来读取一个值时:

import OpenOPC
open_host='10.0.2.15'
open_port='7766'

opc = OpenOPC.open_client(open_host, open_port)
opc.connect('Matrikon.OPC.Simulation.1')

aux = opc.read(['Random.Int4'])
for item in aux:
    print(item)

opc.close()

OpenOPC 网关服务停止,在事件查看器中我有以下内容

Faulting application name: PythonService.exe, version: 0.0.0.0, time stamp: 0x5af24199
Faulting module name: gbda_aut.dll, version: 1.0.8.304, time stamp: 0x4d92bcca
Exception code: 0xc0000005
Fault offset: 0x000000000001b966
Faulting process id: 0xa90
Faulting application start time: 0x01d464c2264cd7ec
Faulting application path: C:\ProgramData\Anaconda3\lib\site-packages\win32\PythonService.exe
Faulting module path: c:\Windows\System32\gbda_aut.dll
Report Id: 69629dee-d0b5-11e8-8120-080027bc5cb4
Faulting package full name: 
Faulting package-relative application ID: ` .

看来问题与这个gbda_aut.dll有关。我已经从

下载了它的 x64 版本

http://gray-box.net/download_daawrapper.php?lang=en

并以适当的方式注册。

当我尝试使用 DCOM 模式时也会出现此问题。这样做时,我会收到以下信息。

Problem signature:
Problem Event Name: APPCRASH
Application Name:   pythonw.exe
Application Version:    3.6.5150.1013
Application Timestamp:  5abd3212
Fault Module Name:  gbda_aut.dll
Fault Module Version:   1.0.8.304
Fault Module Timestamp: 4d92bcca
Exception Code: c0000005
Exception Offset:   000000000001b966
OS Version: 6.3.9600.2.0.0.272.7
Locale ID:  1033
Additional Information 1:   e0f5
Additional Information 2:   e0f51433c52d71c63f2bde60bf8cf401
Additional Information 3:   1c6f
Additional Information 4:   1c6f1bc49be4e21c20f4309779c02df6

有没有人知道如何使它工作或使用 Python 进行 OPC 读取的更好方法?

【问题讨论】:

  • 问题解决了吗?我也有这个。
  • 很遗憾没有。我看到了一个从 64 位 OPC 服务器读取的 32 位应用程序。但 Open OPC 不适用于 Python 64 位
  • 我明白了。我通过用 Python x86 替换 Python x64 解决了这个问题
  • @Dariva 你是如何安装OpenOPC的。它给了我没有找到模块的错误。
  • @SAndrew。只需将 OpenOPC.py 文件复制到 phyton 文件夹中的 lib\site_packages 文件夹即可。您需要注意在 windows 中创建环境变量。看看安装手册。

标签: tensorflow 64-bit python-3.6 opc


【解决方案1】:

我一直在尝试使用适用于 python3.6 的 OpenOPC 包从 KEPWARE SERVER 读取数据,现在我可以通过以下链接轻松完成:

  1. https://github.com/Alexhll/OpenOPC-python3.6
  2. https://github.com/joseamaita/openopc120

但是当我尝试每 5 秒连续读取所有 4 台设备的数据时,就会出现问题。 目前服务器是一台windows机器,我已经安装了所有32位版本的东西,比如python、pywin32、pyro4。

下面给出的是我得到的日志,在尝试读取设备数据时大部分是超时的(我看到这个错误主要是在 python 脚本连续运行 3-4 小时之后)。

2019-12-14 05:09:08,750 - loggingModule - getOPCData10thDec.py - <module> - 1368 - 170 - Exception Captured in OPC Part. Trying to reconnect.
2019-12-14 05:09:08,765 - loggingModule - getOPCData10thDec.py - opcReconnect - 1368 - 41 - Trying to reconnect to the OPC server. Max Retries: 3
2019-12-14 05:09:08,781 - loggingModule - getOPCData10thDec.py - opcReconnect - 1368 - 44 - Closing the opc connection if any and retrying to connect 0 time
2019-12-14 05:09:08,796 - loggingModule - getOPCData10thDec.py - opcReconnect - 1368 - 47 - Creating a new OPC client
2019-12-14 05:09:08,859 - loggingModule - getOPCData10thDec.py - opcReconnect - 1368 - 49 - Trying to Connect to the OPC server: Kepware.KEPServerEX.V6
2019-12-14 05:09:08,906 - loggingModule - getOPCData10thDec.py - opcReconnect - 1368 - 51 - Connected to the OPC server
2019-12-14 05:09:08,921 - loggingModule - getOPCData10thDec.py - <module> - 1368 - 174 - Available Devices on the OPC:
2019-12-14 05:09:08,937 - loggingModule - getOPCData10thDec.py - <module> - 1368 - 175 - ['_AdvancedTags', '_ConnectionSharing', '_CustomAlarms', '_DataLogger', '_EFMExporter', '_IDF_for_Splunk', '_IoT_Gateway', '_LocalHistorian', '_Redundancy', '_Scheduler', '_SecurityPolicies', '_SNMP Agent', '_System', '_ThingWorx', 'Compressor01', 'Metering-Coriolis-S3S-Active', 'Metering-Coriolis-S3S-Diesel', 'Metering-Coriolis-S3S-Frac', 'Metering-Coriolis-S3S-Water', 'MudCube01', 'MudCube02', 'MudCube03', 'Pason WITS', 'S3S Coriolis Skid']
2019-12-14 05:09:18,869 - loggingModule - getOPCData10thDec.py - readOPCData - 1368 - 101 - Error while reading the OPC data for device: Compressor01
2019-12-14 05:09:18,884 - loggingModule - getOPCData10thDec.py - readOPCData - 1368 - 102 - Callback: Timeout waiting for data 

在进一步检查该问题时,我查看了事件查看器日志,其中我发现下面给出的与我注册的 dll 相关的应用程序错误。

Faulting application name: python.exe, version: 3.6.8150.1013, time stamp: 0x5c201b63
Faulting module name: gbda_aut.dll, version: 1.2.8.508, time stamp: 0x4822c190
Exception code: 0xc0000005
Fault offset: 0x0001c088
Faulting process id: 0x1484
Faulting application start time: 0x01d5b30ce3a7a612
Faulting application path: C:\Users\OPCAdmin\AppData\Local\Programs\Python\Python36-32\python.exe
Faulting module path: C:\OpenOPC36\lib\gbda_aut.dll
Report Id: 3fd3dbef-8701-4516-87ce-bc514ee627c2
Faulting package full name: 
Faulting package-relative application ID: 

我正在尝试找到解决此问题的方法,但对此无能为力。 下面给出的是我在看到任何超时问题后尝试重新连接到 OPC 服务器时尝试使用的代码。

def opcReconnect():
    """
    reconnect to the opc server
    :return: opc client
    """
    global opc
    logger.info("Trying to reconnect to the OPC server. Max Retries: " + str(retry_n_times))
    for i in range(retry_n_times):
        try:
            logger.info("Closing the opc connection if any and retrying to connect " + str(i) + " time")
            opc.remove(opc.groups())
            opc.close()  # closing all old conneciton to the OPC
            logger.info("Creating a new OPC client")
            opc = OpenOPC.client()
            logger.info("Trying to Connect to the OPC server: " + s3sEdgeOPCServer)
            opc.connect(s3sEdgeOPCServer)
            logger.info("Connected to the OPC server")
            return opc
        except ConnectionError as e:
            logger.error('OPC Connection Failure')
            logger.error(e)
        time.sleep(retry_threshold)
    raise Exception

我正在尝试通过删除所有 opc 组然后关闭连接来正确关闭旧的 opc 连接,然后我才尝试再次重新连接到服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多