I am developing a tensorflow model to make a inference of a product property. I want to put this model to run on-line reading data from a OPC Server a writing the result back. To do that I am using the OpenOPC project.
Tensorflow just works with Python 3.6 in a 64 bit OS. So I need to make a OPC connection in the same environment.
OpenOPC was originally desinged to work with Python 2.7 in a x86 OS. There are some projects that upgraded it to work with Python 3.4+. I followed the procedure in the following link to install it: https://github.com/joseamaita/openopc120
I am developing my model in a VM with Windows 2012 Server. For OPC Server I am using Matrikon OPC for Simulation.
The list function from OpenOPC seems to be working fine. When I run the following script
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()
I got the following result
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
Which is promising. But when I tried to run the following code to read a value:
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()
the OpenOPC gateway service stops and in the event viewer I have the following
Faulting application name: PythonService.exe, version: 0.0.0.0, time stamp: 0x5af24199 Faulting module name: gbda_aut.dll, version: 22.214.171.1244, 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: ` .
It seems that the problem is related to this gbda_aut.dll. I have download the x64 version of it from
and registered it in the appropiated way.
The problem also happen when I try to use the DCOM mode. When doing that I receive the following.
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: 126.96.36.1994 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
Does anyone have a idea how to make it work or a better way to do a OPC read using Python?
I have been trying to read data from KEPWARE SERVER using the OpenOPC package for python3.6 and i'm able to do so easily now by following the below given links:
But the issue arises when i'm trying to read data continuously for every 5 secs for all 4 devices. Currently the server is a windows machine on which i have installed all 32bit version thing like python, pywin32, pyro4.
Below given are the logs i'm getting which is mostly timeout while trying to read the data for the device(i see this error mostly after 3-4 hours of continuous awesome run of the python script).
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
On further inspecting the issue, i looked at the event viewer logs wherein i found the application error given below pertaining the dll i registered.
Faulting application name: python.exe, version: 3.6.8150.1013, time stamp: 0x5c201b63 Faulting module name: gbda_aut.dll, version: 188.8.131.528, 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:
I'm trying to find some solution to this problem but not able to do anything about it. Below given is the code i'm trying to use when i'm trying to reconnect to the OPC server once i see any timeout issue.
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
I'm trying to properly close the old opc connection by removing all the opc groups and then closing the connection, only after which i try to reconnect to the server again.
User contributions licensed under CC BY-SA 3.0