當前位置: 首頁>>代碼示例>>Python>>正文


Python OpenOPC.open_client方法代碼示例

本文整理匯總了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:
開發者ID:mabotech,項目名稱:mabopy,代碼行數:35,代碼來源:opc_proxy.py

示例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)
開發者ID:casullivan,項目名稱:project,代碼行數:33,代碼來源:opc_redis.py

示例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
開發者ID:mabotech,項目名稱:mabo.io,代碼行數:28,代碼來源:opc_monitor.py

示例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)
開發者ID:aslakjohansen,項目名稱:smap,代碼行數:37,代碼來源:opc_auto.py

示例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)
開發者ID:mabotech,項目名稱:mabo.io,代碼行數:27,代碼來源:opc_proxy.py

示例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
開發者ID:carriercomm,項目名稱:SimpleSeer,代碼行數:59,代碼來源:core_commands.py

示例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()
開發者ID:pwuertz,項目名稱:qao,代碼行數:11,代碼來源:iSegControl.py

示例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)
開發者ID:nlurkin,項目名稱:Other,代碼行數:12,代碼來源:ThControl.py

示例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
開發者ID:chrylarson,項目名稱:WM,代碼行數:12,代碼來源:pythonprog.py

示例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)
開發者ID:mabotech,項目名稱:mabo.io,代碼行數:16,代碼來源:opc_connector.py

示例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
開發者ID:mabotech,項目名稱:mabo.io,代碼行數:26,代碼來源:opc_connector.py

示例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
開發者ID:bapowell,項目名稱:OpenOPC,代碼行數:32,代碼來源:opc.py

示例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])
開發者ID:rpassage,項目名稱:opc_check,代碼行數:32,代碼來源:fetch_opc.py

示例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
開發者ID:pengtianyue,項目名稱:Solvay_test,代碼行數:6,代碼來源:OPCclient.py

示例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
開發者ID:gio1612,項目名稱:py-opc,代碼行數:33,代碼來源:opc-v1.py


注:本文中的OpenOPC.open_client方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。