本文整理汇总了Python中OpenOPC.client方法的典型用法代码示例。如果您正苦于以下问题:Python OpenOPC.client方法的具体用法?Python OpenOPC.client怎么用?Python OpenOPC.client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenOPC
的用法示例。
在下文中一共展示了OpenOPC.client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reconnect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def reconnect(self):
""" reconnect """
log.info("reconnect...")
info = ""
if self._lock.locked() == False:
#self.reconnecting = 1
self._lock.acquire()
try:
#self.opc = OpenOPC.open_client(self.host, self.port)
#self.opc.connect(self.provider, self.host)
if self.mode == 'dcom':
self.opc = OpenOPC.client("Graybox.OPC.DAWrapper", self.host)
else:
self.opc = OpenOPC.open_client(self.host, self.port)
info = self.opc.servers()
info = info + self.opc.info()
for group in self.groups:
self.create_group(group, self.groups[group])
#self.reconnecting = 0
except Exception, e:
# release the lock
info = "excetp: %s"%(e.message)
log.error(info)
log.error(traceback.format_exc())
#self.reconnecting = 0
finally:
示例2: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def connect():
''' return 2 connection objects: "opc" and "cursor" '''
# PLC
plc='Matrikon.OPC.Simulation.1'
try:
print "+------------+"
print "| | - Connecting to PLC...",
opc=OpenOPC.client()
opc.connect(plc)
print " Success!"
except:
print "Error connecting to OPC"
print "| Connecting |"
# MYSQL
server='127.0.0.1'
user='root'
pasw=''
dbName='mbr'
try:
print "| | - Connecting to MySQL...",
db=MySQLdb.connect(server,user,pasw,dbName)
cursor = db.cursor()
print " Success!"
except:
print "Error connecting to MySQL"
print "+------------+"
return [opc,cursor]
示例3: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def connect(self):
print "attempting OPC connection to", self.opc_name
self.opc = OpenOPC.client()
self.opc.connect(self.opc_name, self.opc_host)
props = self.opc.properties(self.points.keys())
print "loaded", len(props), "properties"
points = {}
for point, pid, key, val in props:
name = self.make_path(point)
if not name in points:
points[name] = self.points[point]
if not exclude(key):
points[name]["OpcDA/" + key] = str(val)
# try to make some sense out of the metadata
for name, meta in points.iteritems():
unit = str(meta.get("OpcDA/" + self.unit_tag, "None"))
dtype = meta.get("OpcDA/Item Canonical DataType", None)
if not dtype:
print "no datatype tag in", name
continue
if dtype.startswith("VT_R"):
dtype = "double"
elif dtype.startswith("VT_U") or dtype.startswith("VT_I"):
dtype = "long"
else:
print "skipping", name, "since cannot find data type"
continue
if not self.get_timeseries(name):
self.add_timeseries(name, unit, data_type=dtype)
self.set_metadata(name, points[name])
vals = self.opc.read(self.points.keys(), group="smap-points-group")
示例4: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def connect(self):
self._lock.acquire()
self._lock.release()
try:
#print self.host
#print self.opc_host
#print self.opc_server
#self.opc = OpenOPC.open_client(self.host, self.port)
if self.mode == 'dcom':
self.opc = OpenOPC.client("Graybox.OPC.DAWrapper", self.host)
else:
self.opc = OpenOPC.open_client(self.host, self.port)
self.opc.connect(self.opc_server, self.opc_host)
#info = self.opc.servers()
#print info
except OPCError, oe:
log.debug( str(oe) )
raise Exception(oe.message)
示例5: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def connect(self):
logger.debug("connect...............")
try:
if conf["Use_Wrapper"] == True:
logger.debug(conf["DAWrapper"])
self.opc_client = OpenOPC.client(conf["DAWrapper"], conf["HOST"])
else:
logger.debug(conf["PROVIDER"])
self.opc_client = OpenOPC.open_client(conf["HOST"], conf["PORT"])
self.opc_client.connect(conf["PROVIDER"], conf["OPC_HOST"])
self.connected = 1
except Exception as ex:
logger.debug(ex)
self.connected = 0
示例6: jobWriteOPC
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def jobWriteOPC(TVpairs,opcserver='OPCManager.DA.XML-DA.Server.DA',client_name=None):
opc = OpenOPC.client(client_name=client_name)
opc.connect(opcserver)
sleep(0.7)
status = opc.write(TVpairs)
sleep(0.7)
opc.close()
return status
示例7: get_opc_info
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def get_opc_info(self,opc_server):
print "Get opc server infomation"
opc = OpenOPC.client()
opc.connect(opc_server)
all = opc.info()
opc.close()
return all
示例8: OPCconnect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def OPCconnect():
opc = OpenOPC.client()
#opc = OpenOPC.open_client('localhost')
opc = OpenOPC.open_client(wm_global.OpcClientName)
opc.servers()
# opc.connect('KEPware.KEPServerEx.V4')
opc.connect(wm_global.OpcServerName)
return opc
示例9: checkICONICS_Simulator
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def checkICONICS_Simulator():
opc = OpenOPC.client()
opc.connect(IconicsSim)
j=0
for i in tagset:
print i, ": ", opc[i]
j = j+1
opc.close()
示例10: _init_OPC
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def _init_OPC(self, opcserver='CoDeSys.OPC.02', opcclientName='OPCClient.GPCSys'):
try:
# opc client instance can not be stored here as this will be run in the main thread during initialisation.
# opc connection will faile later if run from the scheduler job (which will be in an other thread)
opc = OpenOPC.client()
except:
raise ValueError('OPC-Client could not be instantiated')
if opcserver in opc.servers():
self.opcServer = opcserver
try:
opc.connect(self.opcServer)
except:
raise ValueError('OPC-Server: "%s" could not be connected'%(self.opcServer,))
if self.Variables.has_key('OPC_Group'):
opcGrp = self.Variables['OPC_Group']
opcVMap = {}
opcVars = set()
opcServVars = set()
for sti in self.Variables.keys():
if sti in ["OPC_Group",]: continue
stg = lambda vi: ''.join(vi.split('_',2)[:2])
vmapi = dict([(sti+':.'+vi['OPC'],GPC_Stations[stg(vi['OPC'])]+':'+vi['GPC']) for vi in self.Variables[sti]])
opcVMap.update(vmapi)
opcVars.update(vmapi.keys())
opcServVars.update(opc.list(sti+"*", flat=True))
opcVMap.update(dict([reversed(i) for i in opcVMap.items()]))
else:
opcGrp = self.Variables.keys()[0]
opcVars = set([opcGrp+':.'+vi for vi in self.Variables[opcGrp]])
opcServVars = set(opc.list(opcGrp+"*", flat=True))
if opcVars <= opcServVars:
self.opcGrp = opcGrp
self.opcVars = opcVars
self.opcVarsDict = dict()
try: #only if variable mapping available store it
self.opcVMap = opcVMap
self.gpcVars = [opcVMap[vi] for vi in opcVars]
except:
self.gpcVars = self.opcVars
else:
raise ValueError('Not all needed Variables are listed by the OPC Server\n missing: %s' % (opcVars - opcServVars,))
self.opcclientName = opcclientName
self.readLock = False
self.writeLock = False
self.connTrys = 0
self.connMaxTrys = 3 #Could come from config
opc.close()
else:
raise ValueError('OPC Server is not accessible: %s' % opcserver)
示例11: get_opc_list
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def get_opc_list(self,opc_server,browe_option):
print "Initial to get all OPC item from ",opc_server
opc = OpenOPC.client()
opc.connect(opc_server)
#all = opc.list()
if browe_option: #Flat == True
all = opc.list('*',flat = True)
print "------------------------"
for t in all:
print t
opc.close()
return all # rerturn all opc server
else:
return all
示例12: readOPC
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def readOPC(self,server,tag_read):
opc = OpenOPC.client()
opc.connect(server)
result = opc.read(tag_read,timeout=7000)
del self.global_list[server]['value'][:] # delete all item
self.global_list[server]['value'] = result
check_time_out = 0
run_proc = True
try:
while run_proc:
# reset tag timeout
if check_time_out > 3:
check_time_out = 0
tag_read = []
del_tag = []
for t in self.global_list[server]['tag']:
time_out = self.global_list[server]['tag'][t]-1
print "Tag %s timeout %s " % (t,time_out)
if time_out > 0 :
self.global_list[server]['tag'][t]=time_out
tag_read.append(t)
else:
del_tag.append(t)
# delete tag from servie
for t in del_tag:
del self.global_list[server]['tag'][t]
#print "OPC thread service update between 2 second \r\n Try to set new value in global_list : ",
#print self.global_list
time.sleep(2)
if len(tag_read)>0:
result = opc.read(tag_read,timeout=7000)
#print result
del self.global_list[server]['value'][:] # delete all item
self.global_list[server]['value'] = result
check_time_out +=1
else:
run_proc = False # exit process
del self.global_list[server] # delete all tag and server
except Exception,err:
print "interrupt exit with thread opc : ",err
示例13: jobReadOPC
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def jobReadOPC(Tags,opcserver='OPCManager.DA.XML-DA.Server.DA',client_name=None):
opc = OpenOPC.client(client_name=client_name)
opc.connect(opcserver)
sleep(0.7)
opcIn = []
for i in xrange(2):
try:
opcIn = opc.read(Tags,timeout=1000)
break
except OpenOPC.TimeoutError:
print "%s: TimeoutError" % (client_name,)
opc.close()
sleep(1)
opc.connect(opcserver)
sleep(0.7)
opc.close()
return opcIn
示例14: _connect_OPC
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def _connect_OPC(self):
try:
self.opc
except AttributeError:
# opc client instance can now be stored as this is done within the job thread.
# later cals will be issued from the same thread.
try:
self.opc = OpenOPC.client(client_name=self.opcclientName)
except OpenOPC.OPCError as e:
raise ValueError('OpenOPC.OPCError: %s\n Error during OPC client instantiation' % e)
try:
self.opc.info() #This raises an exception if the OPC-Server is not connected.
conn = True
except:
conn = False
if not conn:
self.opc.connect(self.opcServer)
sleep(0.3) #To be sure connection is done on OPC server side.
示例15: create_client
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import client [as 别名]
def create_client(self):
"""Create a new OpenOPC instance in the Pyro server"""
opc_obj = OpenOPC.client(opc_class)
base_obj = Pyro.core.ObjBase()
base_obj.delegateTo(opc_obj)
uri = self.getDaemon().connect(base_obj)
opc_obj._open_serv = self
opc_obj._open_self = base_obj
opc_obj._open_host = self.getDaemon().hostname
opc_obj._open_port = self.getDaemon().port
opc_obj._open_guid = uri.objectID
remote_ip = self.getLocalStorage().caller.addr[0]
try:
remote_name = socket.gethostbyaddr(remote_ip)[0]
self._remote_hosts[uri.objectID] = '%s (%s)' % (remote_ip, remote_name)
except socket.herror:
self._remote_hosts[uri.objectID] = '%s' % (remote_ip)
self._init_times[uri.objectID] = time.time()
self._tx_times[uri.objectID] = time.time()
return Pyro.core.getProxyForURI(uri)