Exemplo n.º 1
0
    def setUp(self):

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

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

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

        self.address_Scalar = Address(
            ExpandedNodeId("Demo.Static.Scalar", demoNsUri, serverUri))
        self.address_Byte = Address(
            self.address_Scalar,
            [RelativePathElement(QualifiedName("Byte", demoNsUri))])
        self.address_Int32 = Address(
            self.address_Scalar,
            [RelativePathElement(QualifiedName("Int32", demoNsUri))])
        self.address_Float = Address(
            self.address_Scalar,
            [RelativePathElement(QualifiedName("Float", demoNsUri))])
Exemplo n.º 2
0
    def setUp(self):
        # create a new ClientSettings instance and add the localhost to the URLs to discover
        settings = pyuaf.client.settings.ClientSettings()
        settings.discoveryUrls.append(ARGS.demo_url)
        settings.applicationName = "client"
        settings.logToStdOutLevel = ARGS.loglevel

        self.client = MyClient(settings)

        serverUri = ARGS.demo_server_uri
        demoNsUri = ARGS.demo_ns_uri

        self.address_Demo = Address(
            ExpandedNodeId("Demo", demoNsUri, serverUri))
        self.address_Method = Address(
            self.address_Demo,
            [RelativePathElement(QualifiedName("Method", demoNsUri))])
        self.address_Multiply = Address(
            self.address_Method,
            [RelativePathElement(QualifiedName("Multiply", demoNsUri))])
        self.address_SetSimulationSpeed = Address(self.address_Demo, [
            RelativePathElement(QualifiedName("SetSimulationSpeed", demoNsUri))
        ])

        self.request = AsyncMethodCallRequest(1)
        self.request.targets[0].objectAddress = self.address_Method
        self.request.targets[0].methodAddress = self.address_Multiply
        self.request.targets[0].inputArguments.append(Double(2.0))
        self.request.targets[0].inputArguments.append(Double(3.0))
Exemplo n.º 3
0
 def setUp(self):
     self.nsUri = "someNameSpaceUri"
 
     self.startingExpandedNodeId = ExpandedNodeId("someId", self.nsUri, "someServerUri")
 
     self.element0 = RelativePathElement(QualifiedName("element0", self.nsUri))
     self.element1 = RelativePathElement(QualifiedName("element1", self.nsUri))
     
     self.b0 = BrowsePath()
     self.b1 = BrowsePath(self.startingExpandedNodeId, [self.element0, self.element1])
    def setUp(self):
        
        # create a new ClientSettings instance and add the localhost to the URLs to discover
        settings = pyuaf.client.settings.ClientSettings()
        settings.discoveryUrls.append(ARGS.demo_url)
        settings.applicationName = "client"
        settings.logToStdOutLevel = ARGS.loglevel
    
        self.client = pyuaf.client.Client(settings)

        
        serverUri    = ARGS.demo_server_uri
        demoNsUri    = ARGS.demo_ns_uri
        plcOpenNsUri = "http://PLCopen.org/OpcUa/IEC61131-3/"
        
        
        self.address_Demo            = Address(ExpandedNodeId("Demo", demoNsUri, serverUri))
        self.address_StartSimulation = Address(self.address_Demo, [RelativePathElement(QualifiedName("StartSimulation", demoNsUri))])
        self.address_StopSimulation  = Address(self.address_Demo, [RelativePathElement(QualifiedName("StopSimulation", demoNsUri))])
        self.address_Scalar          = Address(self.address_Demo, [RelativePathElement(QualifiedName("Dynamic", demoNsUri)),
                                                                   RelativePathElement(QualifiedName("Scalar", demoNsUri))] )
        self.address_Byte            = Address(self.address_Scalar, [RelativePathElement(QualifiedName("Byte", demoNsUri))] )
        self.address_Int32           = Address(self.address_Scalar, [RelativePathElement(QualifiedName("Int32", demoNsUri))] )
        self.address_Int64           = Address(self.address_Scalar, [RelativePathElement(QualifiedName("Int64", demoNsUri))] )
        self.address_Float           = Address(self.address_Scalar, [RelativePathElement(QualifiedName("Float", demoNsUri))] )
        self.address_Double          = Address(self.address_Scalar, [RelativePathElement(QualifiedName("Double", demoNsUri))] )
        
        # start the simulation (otherwise the dynamic variables won't change)
        self.client.call(self.address_Demo, self.address_StartSimulation)
Exemplo n.º 5
0
    def setUp(self):

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

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

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

        # define some nodeids
        self.id0 = NodeId(opcuaidentifiers.OpcUaId_Server_Auditing, 0)
        self.id1 = NodeId(
            opcuaidentifiers.
            OpcUaId_Server_ServerCapabilities_MaxHistoryContinuationPoints, 0)
        self.id2 = NodeId("Demo.SimulationSpeed", 2)
        self.id3 = NodeId("Demo.SimulationActive", demoNsUri)
        self.id4 = NodeId(opcuaidentifiers.OpcUaId_Server_ServerArray, 0)

        # define some nodeids
        self.address0 = Address(ExpandedNodeId(self.id0, serverUri))
        self.address1 = Address(ExpandedNodeId(self.id1, serverUri))
        self.address2 = Address(ExpandedNodeId(self.id2, serverUri))
        self.address3 = Address(ExpandedNodeId(self.id3, serverUri))
        self.address4 = Address(ExpandedNodeId(self.id4, serverUri))

        # create some relative paths
        self.id5 = NodeId("Demo.BoilerDemo.Boiler1", demoNsUri)
        self.start5 = Address(ExpandedNodeId(self.id5, serverUri))
        self.name5 = QualifiedName("TemperatureSetPoint", demoNsUri)
        self.elem5 = RelativePathElement(self.name5)
        self.path5 = [self.elem5]
        self.address5 = Address(self.start5, self.path5)

        self.start6 = Address(ExpandedNodeId("Demo", demoNsUri, serverUri))
        self.elem6a = RelativePathElement(
            QualifiedName("BoilerDemo", demoNsUri))
        self.elem6b = RelativePathElement(QualifiedName("Boiler1", demoNsUri))
        self.path6 = [self.elem6a, self.elem6b]
        self.address6 = Address(self.start6, self.path6)

        self.elem7a = RelativePathElement(
            QualifiedName("TemperatureSensor", demoNsUri))
        self.elem7b = RelativePathElement(
            QualifiedName("Temperature", demoNsUri))
        self.path7 = [self.elem7a, self.elem7b]
        self.address7 = Address(self.address6, self.path7)
Exemplo n.º 6
0
 def ADR(self):
     if isinstance(self.__opcua_parent__, Address):
         parentAddress = self.__opcua_parent__
     else:
         parentAddress = self.__opcua_parent__.ADR()
     
     return Address(parentAddress, [RelativePathElement(QualifiedName(self.__opcua_name__, self.__opcua_ns__))])
Exemplo n.º 7
0
    def setUp(self):
        
        # create a new ClientSettings instance and add the localhost to the URLs to discover
        settings = pyuaf.client.settings.ClientSettings()
        settings.discoveryUrls.append(ARGS.demo_url)
        settings.applicationName = "client"
        settings.logToStdOutLevel = ARGS.loglevel
    
        self.client = pyuaf.client.Client(settings)

        
        serverUri    = ARGS.demo_server_uri
        demoNsUri    = ARGS.demo_ns_uri
        
        self.address_Demo     = Address(ExpandedNodeId("Demo", demoNsUri, serverUri))
        self.address_Method   = Address(self.address_Demo, [RelativePathElement(QualifiedName("Method", demoNsUri))] )
        self.address_Multiply = Address(self.address_Method, [RelativePathElement(QualifiedName("Multiply", demoNsUri))] )
        self.address_SetSimulationSpeed = Address(self.address_Demo, [RelativePathElement(QualifiedName("SetSimulationSpeed", demoNsUri))] )
from pyuaf.util             import RelativePathElement
from pyuaf.util             import QualifiedName
from pyuaf.util             import primitives
from pyuaf.util             import opcuaidentifiers
from pyuaf.util             import opcuastatuscodes
from pyuaf.util.errors      import UafError


# define the namespace URI and server URI of the UaDemoServer
demoNsUri     = "http://www.unifiedautomation.com/DemoServer"
demoServerUri = "urn:UnifiedAutomation:UaServerCpp"

# define the addresses of some useful nodes
# (demoAddress is an absolute address, all the others are relative ones) 
demoAddress             = Address( NodeId("Demo", demoNsUri), demoServerUri )
simulationActiveAddress = Address( demoAddress, [RelativePathElement(QualifiedName("SimulationActive", demoNsUri))] )
startSimulationAddress  = Address( demoAddress, [RelativePathElement(QualifiedName("StartSimulation" , demoNsUri))] )
historyAddress          = Address( demoAddress, [RelativePathElement(QualifiedName("History", demoNsUri))] )
loggingActiveAddress    = Address( historyAddress, [RelativePathElement(QualifiedName("DataLoggerActive", demoNsUri))] )
startLoggingAddress     = Address( historyAddress, [RelativePathElement(QualifiedName("StartLogging", demoNsUri))] )
doubleAddress           = Address( historyAddress, [RelativePathElement(QualifiedName("DoubleWithHistory", demoNsUri))] )

# define the ClientSettings:
settings = ClientSettings()
settings.applicationName = "MyClient"
settings.discoveryUrls.append("opc.tcp://localhost:48010")

# create the client
myClient = Client(settings)

# first, we need to start the simulation (if it's not already started),
Exemplo n.º 9
0
# within the Root folder, there is another standard node called the Objects folder:
Objects_Node = Address(NodeId(OpcUaId_ObjectsFolder, OPCUA_NAMESPACE_ID),
                       serverUri)

# we could also refer to the Objects node via a relative path!
# We can do this, since the standard Object node has a standard BrowseName.
# The following are all valid ways to define the BrowseName of the Objects node
Objects_BrowseName = QualifiedName("Objects", OPCUA_NAMESPACE_ID)
Objects_BrowseName = QualifiedName(
    "Objects", OPCUA_NAMESPACE_URI)  # namespace URI instead of index
Objects_BrowseName = QualifiedName(
    "Objects", OPCUA_NAMESPACE_URI,
    OPCUA_NAMESPACE_ID)  # redundant namespace info, but valid
# we can now create a path from the Root node to the Objects node, using a path of one element:
Objects_Node = Address(Root_Node, [RelativePathElement(Objects_BrowseName)])
# The Objects_Node that we just created, refers to the exact same node as the Objects_Node that we previously created.

# within the Objects node, there is a standard node called Server, which represents a sort
# of object that contains all kinds of information about the server.
# The following are all equally valid ways to define this node:
Server_Node = Address(
    ExpandedNodeId(NodeId(OpcUaId_Server, OPCUA_NAMESPACE_ID), serverUri))
Server_Node = Address(
    ExpandedNodeId(OpcUaId_Server, OPCUA_NAMESPACE_ID, serverUri))
Server_Node = Address(Root_Node, [
    RelativePathElement(QualifiedName("Objects", OPCUA_NAMESPACE_ID)),
    RelativePathElement(QualifiedName("Server", OPCUA_NAMESPACE_ID))
])
Server_Node = Address(
    Objects_Node,
Exemplo n.º 10
0
print("")

# There are *many* ways how you can identify (address) a node, see the examples below:
# 1) absolute address to the standard OPC UA "RootFolder" node (notice the standard OPC UA index 0)
# 2) absolute address to the non-standard "Demo" node (notice the demo server namespace URI)
# 3) absolute address to the non-standard "BoilerDemo" node (notice that we use an ExpandedNodeId this time)
# 4) relative address to the "Boiler1" node (relative to the previous address)
# 5) relative address to the "TemperatureSetpoint" Double variable (relative to the previous relative (!!!) address)
# 6) relative address to the "HeaterStatus" node (relative to the standard "Root" folder)
address_Root = Address(NodeId(OpcUaId_RootFolder, 0), demoServerUri)
address_Demo = Address(NodeId("Demo", demoNsUri), demoServerUri)
address_BoilerDemo = Address(
    ExpandedNodeId("Demo.BoilerDemo", demoNsUri, demoServerUri))
address_Boiler1 = Address(
    address_BoilerDemo,
    [RelativePathElement(QualifiedName("Boiler1", demoNsUri))])
address_TSetpoint = Address(
    address_Boiler1,
    [RelativePathElement(QualifiedName("TemperatureSetPoint", demoNsUri))])
address_HeaterStatus = Address(address_Root, [
    RelativePathElement(QualifiedName("Objects", 0)),
    RelativePathElement(QualifiedName("Demo", demoNsUri)),
    RelativePathElement(QualifiedName("BoilerDemo", demoNsUri)),
    RelativePathElement(QualifiedName("Boiler1", demoNsUri)),
    RelativePathElement(QualifiedName("HeaterStatus", demoNsUri))
])

# In the above examples, 0 is used to identify the "standard OPC UA namespace" (which is ALWAYS 0).
# We could also have replaced 0 with the standard OPC UA namespace URI ('http://opcfoundation.org/UA/').
# This namespace URI is available as a constant: pyuaf.util.constants.OPCUA_NAMESPACE_URI.
Exemplo n.º 11
0
    def setUp(self):

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

        self.client = MyClient(settings)

        serverUri = ARGS.demo_server_uri
        demoNsUri = ARGS.demo_ns_uri
        opcUaNsIndex = 0  # the namespace index of nodes defined by the OPC UA specs is always 0

        self.address_Demo = Address(
            ExpandedNodeId("Demo", demoNsUri, serverUri))
        self.address_Events = Address(
            self.address_Demo,
            [RelativePathElement(QualifiedName("Events", demoNsUri))])
        self.address_Alarms = Address(
            self.address_Events,
            [RelativePathElement(QualifiedName("AlarmsWithNodes", demoNsUri))])
        self.address_Alarm = Address(self.address_Alarms, [
            RelativePathElement(QualifiedName("ExclusiveLevelAlarm",
                                              demoNsUri))
        ])
        self.address_Trigger = Address(self.address_Alarms, [
            RelativePathElement(
                QualifiedName("ExclusiveLevelAlarmTrigger", demoNsUri))
        ])
        self.address_LowLow = Address(
            self.address_Alarm,
            [RelativePathElement(QualifiedName("LowLowLimit", opcUaNsIndex))])
        self.address_Low = Address(
            self.address_Alarm,
            [RelativePathElement(QualifiedName("LowLimit", opcUaNsIndex))])
        self.address_High = Address(
            self.address_Alarm,
            [RelativePathElement(QualifiedName("HighLimit", opcUaNsIndex))])
        self.address_HighHigh = Address(self.address_Alarm, [
            RelativePathElement(QualifiedName("HighHighLimit", opcUaNsIndex))
        ])

        # start the simulation (otherwise the dynamic variables won't change)
        res = self.client.read([
            self.address_LowLow, self.address_Low, self.address_High,
            self.address_HighHigh
        ])

        self.assertTrue(res.overallStatus.isGood())

        self.lowLowLimit = res.targets[0].data.value
        self.lowLimit = res.targets[1].data.value
        self.highLimit = res.targets[2].data.value
        self.highHighLimit = res.targets[3].data.value

        self.eventFilter = EventFilter()
        self.eventFilter.selectClauses.resize(3)
        self.eventFilter.selectClauses[0].attributeId = attributeids.Value
        self.eventFilter.selectClauses[0].browsePath.append(
            QualifiedName("Message", 0))
        self.eventFilter.selectClauses[0].typeId = NodeId(
            opcuaidentifiers.OpcUaId_BaseEventType, 0)
        self.eventFilter.selectClauses[1].attributeId = attributeids.Value
        self.eventFilter.selectClauses[1].browsePath.append(
            QualifiedName("SourceName", 0))
        self.eventFilter.selectClauses[1].typeId = NodeId(
            opcuaidentifiers.OpcUaId_BaseEventType, 0)
        self.eventFilter.selectClauses[2].attributeId = attributeids.Value
        self.eventFilter.selectClauses[2].browsePath.append(
            QualifiedName("Severity", 0))
        self.eventFilter.selectClauses[2].typeId = NodeId(
            opcuaidentifiers.OpcUaId_BaseEventType, 0)

        # make sure the trigger has a default value
        result = self.client.write([self.address_Trigger], [Double(50.0)])
        # Check if the write failed due to a BadUserAccessDenied failure
        # This appears to be the case for the UaServerCpp shipped with the Windows MSVS2008 demo SDK,
        # probably a bug in the UaServerCpp.
        if result.targets[0].status.opcUaStatusCode(
        ) == pyuaf.util.opcuastatuscodes.OpcUa_BadUserAccessDenied:
            self.skipTest(
                "Some old versions of the UaServerCpp have non-writeable triggers (bug in UaServerCpp?)"
            )
Exemplo n.º 12
0
print("Step 3: Specify the addresses to some nodes which we would like to read/write/browse/monitor/call/...")
print("################################################################################################################")
print("")


# There are *many* ways how you can identify (address) a node, see the examples below:
# 1) absolute address to the standard OPC UA "RootFolder" node (notice the standard OPC UA index 0)
# 2) absolute address to the non-standard "Demo" node (notice the demo server namespace URI)
# 3) absolute address to the non-standard "BoilerDemo" node (notice that we use an ExpandedNodeId this time)
# 4) relative address to the "Boiler1" node (relative to the previous address)
# 5) relative address to the "TemperatureSetpoint" Double variable (relative to the previous relative (!!!) address)
# 6) relative address to the "HeaterStatus" node (relative to the standard "Root" folder)
address_Root         = Address( NodeId(OpcUaId_RootFolder , 0        ), demoServerUri )
address_Demo         = Address( NodeId("Demo"             , demoNsUri), demoServerUri )
address_BoilerDemo   = Address( ExpandedNodeId("Demo.BoilerDemo", demoNsUri, demoServerUri) )
address_Boiler1      = Address( address_BoilerDemo , [ RelativePathElement(QualifiedName("Boiler1"            , demoNsUri)) ] )
address_TSetpoint    = Address( address_Boiler1    , [ RelativePathElement(QualifiedName("TemperatureSetPoint", demoNsUri)) ] )
address_HeaterStatus = Address( address_Root       , [ RelativePathElement(QualifiedName("Objects"            , 0        )),
                                                       RelativePathElement(QualifiedName("Demo"               , demoNsUri)),
                                                       RelativePathElement(QualifiedName("BoilerDemo"         , demoNsUri)),
                                                       RelativePathElement(QualifiedName("Boiler1"            , demoNsUri)),
                                                       RelativePathElement(QualifiedName("HeaterStatus"       , demoNsUri)) ] )


# In the above examples, 0 is used to identify the "standard OPC UA namespace" (which is ALWAYS 0).
# We could also have replaced 0 with the standard OPC UA namespace URI ('http://opcfoundation.org/UA/').
# This namespace URI is available as a constant: pyuaf.util.constants.OPCUA_NAMESPACE_URI.

# As you can see above, there are a variety of ways how you can address a node. 
# But there are even more things you can do:
#  - for each ExpandedNodeId, NodeId or QualifiedName, you may include namespace indexes, or namespace URIs, or both
from pyuaf.client.requests       import TranslateBrowsePathsToNodeIdsRequest
from pyuaf.client.configs        import TranslateBrowsePathsToNodeIdsConfig
from pyuaf.util                  import Address, NodeId, RelativePathElement, QualifiedName, BrowsePath, ExpandedNodeId
from pyuaf.util                  import primitives
from pyuaf.util.errors           import UafError
from pyuaf.util.opcuaidentifiers import OpcUaId_RootFolder
from pyuaf.util.constants        import OPCUA_NAMESPACE_URI


# define the namespace URI and server URI of the UaDemoServer
demoNsUri     = "http://www.unifiedautomation.com/DemoServer"
demoServerUri = "urn:UnifiedAutomation:UaServerCpp"

# define a browse path to the HeaterStatus node
myStartingPoint = ExpandedNodeId( NodeId(OpcUaId_RootFolder, OPCUA_NAMESPACE_URI), demoServerUri )
myRelativePath  = [ RelativePathElement(QualifiedName("Objects"     , OPCUA_NAMESPACE_URI)),
                    RelativePathElement(QualifiedName("Demo"        , demoNsUri)),
                    RelativePathElement(QualifiedName("BoilerDemo"  , demoNsUri)),
                    RelativePathElement(QualifiedName("Boiler1"     , demoNsUri)),
                    RelativePathElement(QualifiedName("HeaterStatus", demoNsUri)) ]
myBrowsePath = BrowsePath(myStartingPoint, myRelativePath)

# define the ClientSettings:
settings = ClientSettings()
settings.applicationName = "MyClient"
settings.discoveryUrls.append("opc.tcp://localhost:48010")
# settings.logToStdOutLevel = pyuaf.util.loglevels.Debug # uncomment for seeing debugging information

# create the client
myClient = Client(settings)