我正在开发张量流模型以推断产品属性。我想让该模型运行以在线方式从OPC服务器读取数据,然后将结果写回去。为此,我正在使用OpenOPC项目。
Tensorflow只能在64位OS中与Python 3.6一起使用。因此,我需要在同一环境中建立OPC连接。
OpenOPC最初旨在在x86 OS中与Python 2.7一起使用。有一些项目对其进行了升级,使其可以与Python 3.4+一起使用。我按照以下链接中的过程进行安装: https://github.com/joseamaita/openopc120
我正在使用Windows 2012 Server在VM中开发模型。对于OPC服务器,我使用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读取的更好方法吗?
答案 0 :(得分:0)
我一直在尝试使用适用于python3.6的OpenOPC软件包从KEPWARE SERVER读取数据,现在我可以通过以下以下链接轻松地做到这一点:
但是,当我试图为所有4台设备每5秒连续读取数据时,就会出现此问题。 当前服务器是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连接,然后才尝试重新连接到服务器。