我正在开发一个tensorflow模型来推断产品属性。我想把这个模型放在OPC服务器上运行在线读取数据,然后写回结果。为此,我使用了OpenOPC项目。
Tensorflow只在64位操作系统中使用Python3.6。因此,我需要在相同的环境中建立OPC连接。
OpenOPC最初被设计用于在x86操作系统中使用Python2.7。有一些项目将其升级为与Python一起工作。我按照以下链接中的步骤安装它:https://github.com/joseamaita/openopc120
我正在使用Windows2012Server在VM中开发我的模型。对于OPC服务器,我使用Matrikon进行仿真。
OpenOPC的list函数似乎运行良好。当我运行以下脚本时
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版本
并以批准的方式注册。
当我尝试使用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?
发布于 2019-12-17 09:30:09
我一直试图使用python3.6的OpenOPC包从KEPWARE服务器读取数据,现在我可以通过以下给定的链接轻松地读取数据:
但是,当我试图每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组,然后关闭连接,然后再尝试重新连接到服务器。
https://stackoverflow.com/questions/52824127
复制相似问题