OpenOPC - Python连接在几个小时后崩溃

时间:2016-01-25 17:18:23

标签: python mysql opc

我有简单的python脚本,用于将数据从OPC记录到MySQL。

import OpenOPC
import MySQLdb
import json
import time, datetime, threading

opc = OpenOPC.open_client('localhost')
opc.connect('MyOPCServer.OPC')

while True:
    temp11 = "R1_33"
    value1 = opc.read(zmienna1) 
    db = MySQLdb.connect("localhost","root","","test")
    cursor = db.cursor()
    sql = "INSERT INTO test1(name, value, time) VALUES('%s', '%d', '%s')" % \
    (temp11, value1[0], value1[2])
    try:
        cursor.execute(sql)
        db.commit()
    except:
        db.rollback()

    db.close()

    time.sleep(6)
opc.close()

经过几个小时的工作后,脚本崩溃并出现此错误:

Traceback (most recent call last):
  File "pcs4.py", line 16, in <module>
    value1 = client.read(zmienna1, include_error=True)
  File "C:\Python27\lib\site-packages\pyro-3.16-py2.7.egg\Pyro\core.py", line 38
1, in __call__
    return self.__send(self.__name, args, kwargs)
  File "C:\Python27\lib\site-packages\pyro-3.16-py2.7.egg\Pyro\core.py", line 45
6, in _invokePYRO
    return self.adapter.remoteInvocation(name, Pyro.constants.RIF_VarargsAndKeyw
ords, vargs, kargs)
  File "C:\Python27\lib\site-packages\pyro-3.16-py2.7.egg\Pyro\protocol.py", lin
e 497, in remoteInvocation
    return self._remoteInvocation(method, flags, *args)
  File "C:\Python27\lib\site-packages\pyro-3.16-py2.7.egg\Pyro\protocol.py", lin
e 572, in _remoteInvocation
    answer.raiseEx()
  File "C:\Python27\lib\site-packages\pyro-3.16-py2.7.egg\Pyro\errors.py", line
72, in raiseEx
    raise self.excObj
OpenOPC.OPCError

之后,甚至Matrikon OPC资源管理器也不会从服务器获取标签。我必须重新启动操作系统然后脚本再次工作几个小时。有什么想法吗?

0 个答案:

没有答案