本文整理汇总了Python中OpenOPC.open_client方法的典型用法代码示例。如果您正苦于以下问题:Python OpenOPC.open_client方法的具体用法?Python OpenOPC.open_client怎么用?Python OpenOPC.open_client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenOPC
的用法示例。
在下文中一共展示了OpenOPC.open_client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reconnect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_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 open_client [as 别名]
def connect():
global opc
global list
opc = None
list = None
if debug: print "Connecting..."
r.set("connected", "BAD")
while list is None:
try:
if debug: print "Connection Attempt {"
opc = OpenOPC.open_client(opc_server)
opc.connect(opc_server_name, opc_server)
list = opc.list('Brave.calendar.opc_group')
if debug: print "}"
r.set("connected", "OK")
r.set("opc_server", plc)
r.set("opc_server_name", opc_server_name)
r.set("plc", plc)
r.set("redis_server", redis_server)
except Exception as e:
if debug: print e
try:
ping(opc_server, c=1)
print {'error': 'Cannot connect to ' + opc_server_name, 'val': 0}
except Exception as e:
if debug: print e
print {'error': 'Cannot connect to network', 'val': 0}
pass
pass
finally:
time.sleep(poll_rate)
示例3: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_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
示例4: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def connect(self):
print "attempting OPC connection to", self.opc_name
self.opc = OpenOPC.open_client(host=self.opc_host)
self.opc.connect(self.opc_name, self.opc_host)
if self.points is None:
pointlist = self.opc.list(recursive=True, flat=True)
self.points = self.parse_pointlist(pointlist)
props = self.opc.properties(self.points.keys())
print "loaded", len(props), "properties"
points = {}
for point, pid, key, val in props:
key = key.decode().encode('ascii','ignore')
key = key.replace(' ','')
if isinstance(val, unicode) or isinstance(val, str):
val = val.encode('ascii','ignore')
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/ItemCanonicalDataType', None)
if not dtype:
print "no datatype tag in", name
continue
dtype = 'double'
if not self.get_timeseries(name):
name = name.decode().encode('ascii','ignore')
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")
self.updater = task.LoopingCall(self.update).start(self.rate)
示例5: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_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)
示例6: OPCCommand
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def OPCCommand(self):
'''
You will also need to add the following to your config file:
opc:
server: 10.0.1.107
name: OPC SERVER NAME
tags: ["OPC-SERVER.Brightness_1.Brightness", "OPC-SERVER.TAGNAME"]
tagcounter: OPC-SERVER.tag_which_is_int_that_tells_frame_has_changed
This also requires the server you are connecting to be running the OpenOPC
gateway service. It comes bundled with OpenOPC. To get it to route over
the network you also have to set the windows environment variable OPC_GATE_HOST
to the actual of the IP address of the server it's running on instead of 'localhost'
otherwise the interface doesn't bind and you won't be able to connect via
linux.
'''
try:
import OpenOPC
except:
raise Exception('Requires OpenOPC plugin')
from SimpleSeer.realtime import ChannelManager
opc_settings = self.session.opc
if opc_settings.has_key('name') and opc_settings.has_key('server'):
self.log.info('Trying to connect to OPC Server[%s]...' % opc_settings['server'])
try:
opc_client = OpenOPC.open_client(opc_settings['server'])
except:
ex = 'Cannot connect to server %s, please verify it is up and running' % opc_settings['server']
raise Exception(ex)
self.log.info('...Connected to server %s' % opc_settings['server'])
self.log.info('Mapping OPC connection to server name: %s' % opc_settings['name'])
opc_client.connect(opc_settings['name'])
self.log.info('Server [%s] mapped' % opc_settings['name'])
if opc_settings.has_key('tagcounter'):
tagcounter = int(opc_client.read(opc_settings['tagcounter'])[0])
counter = tagcounter
self.log.info('Polling OPC Server for triggers')
while True:
tagcounter = int(opc_client.read(opc_settings['tagcounter'])[0])
if tagcounter != counter:
self.log.info('Trigger Received')
data = dict()
for tag in opc_settings.get('tags'):
tagdata = opc_client.read(tag)
if tagdata:
self.log.info('Read tag[%s] with value: %s' % (tag, tagdata[0]))
data[tag] = tagdata[0]
self.log.info('Publishing data to PUB/SUB OPC channel')
ChannelManager().publish('opc/', data)
counter = tagcounter
示例7: __init__
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def __init__(self,canNum,modNum,host=hostDefault,srvName=srvNameDefault):
self.canNum = canNum
self.modNum = modNum
#connect to OPC Server
self.opc = OpenOPC.open_client(host)
self.opc.connect(srvName,host)
time.sleep(waittimeDefault)
assert self.opc.ping()
示例8: Connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def Connect(self, RemoteHost="dcspc", RemotePort=7766, OPCHost="epdt120", OPCServer="OPC20CanOpen+"):
self.RemoteHost = RemoteHost
self.RemotePort = RemotePort
self.OPCHost = OPCHost
self.OPCServer = OPCServer
print "Connectining to OPC server " + self.OPCServer + " on " + self.RemoteHost
self.OPC = OpenOPC.open_client(self.RemoteHost, self.RemotePort)
self.OPC.connect(self.OPCServer, self.OPCHost)
print "Connected\nWaiting for OPC server to read all values from devices ..."
time.sleep(10)
示例9: OPCconnect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_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
示例10: connect
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def connect(self):
_lock.acquire()
_lock.release()
try:
self.opc = OpenOPC.open_client(self.host, self.port)
self.opc.connect(self.provider,self.host)
except Exception, e:
raise Exception(e.message)
示例11: recreateGroup
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def recreateGroup(self):
_lock.acquire()
_lock.release()
info = ""
if self.reconnecting == 0:
self.reconnecting = 1
try:
self.opc = OpenOPC.open_client(self.host, self.port)
self.opc.connect(self.provider, self.host)
info = self.opc.servers()
info = info + self.opc.info()
for group in self.groups:
self.createGroupByWS2(group)
self.reconnecting = 0
except Exception, e:
# release the lock
info = "excetp: %s"%(e)
log.error(info)
log.error(traceback.format_exc())
self.reconnecting = 0
示例12: time2str
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
if action == 'sessions':
print ' %-38s %-18s %-18s' % ('Remote Client', 'Start Time', 'Last Transaction')
try:
for guid, host, init_time, tx_time in OpenOPC.get_sessions(open_host, open_port):
print ' %-38s %-18s %-18s' % (host, time2str(init_time), time2str(tx_time))
except:
error_msg = sys.exc_info()[1]
print "Cannot connect to OpenOPC service at %s:%s - %s" % (open_host, open_port, error_msg)
exit()
# Connect to OpenOPC service (Open mode)
if opc_mode == 'open':
try:
opc = OpenOPC.open_client(open_host, open_port)
except:
error_msg = sys.exc_info()[1]
print "Cannot connect to OpenOPC Gateway Service at %s:%s - %s" % (open_host, open_port, error_msg)
exit()
# Dispatch to COM class (DCOM mode)
else:
try:
opc = OpenOPC.client(opc_class, client_name)
except OpenOPC.OPCError, error_msg:
print "Failed to initialize an OPC Automation Class from the search list '%s' - %s" % (opc_class, error_msg)
exit()
# Connect to OPC server
示例13: setup_environ
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
from project import settings
setup_environ(settings)
# import models and choices
from project.web.models import Asset, COLLECTOR_CHOICES
choices = dict(COLLECTOR_CHOICES)
# loop through the OPC servers, connecting to each one and
# creating the asset objects we need based off of the data
itemcount = 0
for plant in choices:
for server in choices[plant]:
# ('192.168.141.204', 'APCOLLECTCMC')
try:
opc = OpenOPC.open_client(server[0])
opc.connect(kepware)
except:
print 'Connection to %s (%s) failed!' % (server[0], kepware)
break
eoc_list = opc.list("*.EOC", flat=True)
for item in eoc_list:
parts = item.split('.')
# pop the EOC string off the list and put together our components
tag = parts.pop()
name = parts[-1]
path = '.'.join(parts[:-1])
示例14: connect_local
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
def connect_local(self, svr_name, host="localhost"):
opc_client = OpenOPC.open_client(host)
opc_client.connect(svr_name)
return opc_client
示例15: dict
# 需要导入模块: import OpenOPC [as 别名]
# 或者: from OpenOPC import open_client [as 别名]
import OpenOPC
import time
import calendar
import ConfigParser
from optparse import OptionParser
import psycopg2
cfg = ConfigParser.RawConfigParser()
cfg.read('srv.cfg')
host = cfg.get('SERVER_INFO', 'host')
server = cfg.get('SERVER_INFO', 'server')
var = cfg.items('VARIABLES')
opc = OpenOPC.open_client(host)
opc.connect(server)
db=cfg.get('DATA_BASE_INFO','dbname');
db_host=cfg.get('DATA_BASE_INFO','host');
db_user=cfg.get('DATA_BASE_INFO','user');
db_pass=cfg.get('DATA_BASE_INFO','password');
conn = psycopg2.connect('dbname='+db+' host='+db_host+' user='+db_user+' password='+db_pass)
cur = conn.cursor()
state = dict(opc.info())['State']
print "#################################################"
print "Protocolo: %s" % dict(opc.info())['Protocol']
print "OPC Host: %s" % dict(opc.info())['OPC Host']
print "OPC Server: %s" % dict(opc.info())['OPC Server']
print "Status OPC: %s" % state