示例#1
0
 def setUp(self):
     
     # create a new ClientSettings instance and add the localhost to the URLs to discover
     settings = ClientSettings()
     settings.discoveryUrls.append(ARGS.demo_url)
     settings.applicationName = "client"
     settings.logToStdOutLevel = ARGS.loglevel
     
     self.client = pyuaf.client.Client(settings)
 
     self.serverUri = ARGS.demo_server_uri
     demoNsUri = ARGS.demo_ns_uri
     plcOpenNsUri = "http://PLCopen.org/OpcUa/IEC61131-3/"
     
     # define some addresses
     self.addresses = [ Address(NodeId("Demo.SimulationSpeed", demoNsUri), self.serverUri),
                        Address(NodeId("Demo.SimulationActive", demoNsUri), self.serverUri) ]
     self.address_Method   = Address(ExpandedNodeId("Demo.Method", demoNsUri, self.serverUri))
     self.address_Multiply = Address(ExpandedNodeId("Demo.Method.Multiply", demoNsUri, self.serverUri))
     self.address_Alarms = Address(ExpandedNodeId("AlarmsWithNodes", demoNsUri, self.serverUri))
     
     readResult = self.client.read(self.addresses)
     self.values = [readResult.targets[0].data, readResult.targets[1].data]
     
     del self.client
     self.client = pyuaf.client.Client(settings)
示例#2
0
    def setUp(self):

        # create a new ClientSettings instance and add the localhost to the URLs to discover
        settings = ClientSettings()
        settings.discoveryUrls.append(ARGS.demo_url)
        settings.applicationName = "client"
        settings.logToStdOutLevel = ARGS.loglevel

        self.client = pyuaf.client.Client(settings)

        self.serverUri = ARGS.demo_server_uri
        demoNsUri = ARGS.demo_ns_uri
        plcOpenNsUri = "http://PLCopen.org/OpcUa/IEC61131-3/"

        # define some addresses
        self.addresses = [
            Address(NodeId("Demo.SimulationSpeed", demoNsUri), self.serverUri),
            Address(NodeId("Demo.SimulationActive", demoNsUri), self.serverUri),
        ]
        self.address_Method = Address(ExpandedNodeId("Demo.Method", demoNsUri, self.serverUri))
        self.address_Multiply = Address(ExpandedNodeId("Demo.Method.Multiply", demoNsUri, self.serverUri))
        self.address_Alarms = Address(ExpandedNodeId("AlarmsWithNodes", demoNsUri, self.serverUri))

        readResult = self.client.read(self.addresses)
        self.values = [readResult.targets[0].data, readResult.targets[1].data]

        del self.client
        self.client = pyuaf.client.Client(settings)
See the PyUAF HTML documentation for more info.
"""

import time, os

import pyuaf
from pyuaf.client import Client
from pyuaf.client.settings import ClientSettings
from pyuaf.util import loglevels, Address, NodeId

# we can create some ClientSettings:
settings = ClientSettings()
settings.applicationName = "MyClient"
settings.discoveryUrls.append("opc.tcp://localhost:4841")
settings.logToStdOutLevel = loglevels.Info  # print Info, Warning and Error logging to the console
settings.logToCallbackLevel = loglevels.Debug  # send Debug, Info, Warning and Error logging to the callback

# And if you want to catch the logging output, you may also define a callback.
# In this case we define a callback to write the logging output to a file in the user's home directory.
# (but this callback is optional of course, only define one if you want to do something more with the
#  logging output than simply printing it to the console (i.e. sending it to the stdout))
f = open(os.path.expanduser("~/my_logging_output.txt"), "w")


def callback(msg):
    logDetailsString = ""
    logDetailsString += time.strftime("%a, %d %b %Y %H:%M:%S",
                                      time.localtime(msg.ctime))
    logDetailsString += ".%.3d " % msg.msec
    logDetailsString += "%-10s " % msg.applicationName
示例#4
0
See the PyUAF HTML documentation for more info.
"""

import time, os

import pyuaf
from pyuaf.client          import Client
from pyuaf.client.settings import ClientSettings
from pyuaf.util            import loglevels, Address, NodeId

# we can create some ClientSettings:
settings = ClientSettings()
settings.applicationName = "MyClient"
settings.discoveryUrls.append("opc.tcp://localhost:4841")
settings.logToStdOutLevel   = loglevels.Info   # print Info, Warning and Error logging to the console 
settings.logToCallbackLevel = loglevels.Debug  # send Debug, Info, Warning and Error logging to the callback

# And if you want to catch the logging output, you may also define a callback.
# In this case we define a callback to write the logging output to a file in the user's home directory.
# (but this callback is optional of course, only define one if you want to do something more with the
#  logging output than simply printing it to the console (i.e. sending it to the stdout))
f = open(os.path.expanduser("~/my_logging_output.txt"), "w")
def callback(msg):
    logDetailsString = ""
    logDetailsString += time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(msg.ctime))
    logDetailsString += ".%.3d " %msg.msec
    logDetailsString += "%-10s " %msg.applicationName
    logDetailsString += "%-20s " %msg.loggerName
    logDetailsString += "%-8s "  %loglevels.toString(msg.level)
    # msg.message may contain multiple lines, so we prepend the other logging details in
See the HTML documentation of PyUAF for more info!
""" 
import pyuaf
from pyuaf.util            import loglevels
from pyuaf.client          import Client
from pyuaf.client.settings import ClientSettings
from pyuaf.util            import Address, NodeId

# create a client that
#  - logs everything to the standard out ("stdout", i.e. the Windows DOS Prompt or the Linux shell)
#  - only logs warnings and errors to an external callback function
settings = ClientSettings()
settings.discoveryUrls.append("opc.tcp://localhost:4841")
settings.applicationName = "myClient"
settings.logToStdOutLevel = loglevels.Debug
settings.logToCallbackLevel = loglevels.Error

# define the callback for the logging
def myLoggingCallback(msg):
    print("************ CALLBACK SAYS: ************")
    if msg.level == loglevels.Error:
        print("Error message received: %s" %str(msg))
    elif msg.level == loglevels.Warning:
        print("Warning message received: %s" %str(msg))
    else:
        print("Info or debug message received: %s" %str(msg))

# create the client
myClient = Client(settings, myLoggingCallback)
See the HTML documentation of PyUAF for more info!
"""
import pyuaf
from pyuaf.util import loglevels
from pyuaf.client import Client
from pyuaf.client.settings import ClientSettings
from pyuaf.util import Address, NodeId

# create a client that
#  - logs everything to the standard out ("stdout", i.e. the Windows DOS Prompt or the Linux shell)
#  - only logs warnings and errors to an external callback function
settings = ClientSettings()
settings.discoveryUrls.append("opc.tcp://localhost:4841")
settings.applicationName = "myClient"
settings.logToStdOutLevel = loglevels.Debug
settings.logToCallbackLevel = loglevels.Error


# define the callback for the logging
def myLoggingCallback(msg):
    print("************ CALLBACK SAYS: ************")
    if msg.level == loglevels.Error:
        print("Error message received: %s" % str(msg))
    elif msg.level == loglevels.Warning:
        print("Warning message received: %s" % str(msg))
    else:
        print("Info or debug message received: %s" % str(msg))


# create the client