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)
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)
from pyuaf.client.configs import BrowseConfig, SessionConfig from pyuaf.util import Address, NodeId from pyuaf.util import primitives from pyuaf.util import opcuaidentifiers from pyuaf.util.errors import UafError # define the namespace URI and server URI of the UaServerCPP demo server demoServerUri = "urn:UnifiedAutomation:UaServerCpp" # define the address of the Root node which we would like to start browsing rootNode = Address(NodeId(opcuaidentifiers.OpcUaId_RootFolder, 0), demoServerUri) # define the ClientSettings: settings = ClientSettings() settings.applicationName = "MyClient" settings.discoveryUrls.append("opc.tcp://localhost:48010") # create the client myClient = Client(settings) try: print("") print("First option: use the convenience function \"browse()\"") print("===================================================") # now browse the root node # (notice that there is also an argument called 'maxAutoBrowseNext', which we don't mention # here because we can leave it at the default value (100), to make sure that BrowseNext is # automatically being called for us as much as needed!) # (notice too that you can optionally provide a BrowseConfig and a SessionConfig for
data = readResult.targets[3].data # 'data' has type pyuaf.util.LocalizedText if status.isGood() and isinstance(data, LocalizedText): print("The locale is: '%s', the text is: '%s'" %(data.locale(), data.text())) # target 4: status = readResult.targets[4].status # 'status' has type pyuaf.util.Status data = readResult.targets[4].data # 'data' is a list of pyuaf.util.primitives.SByte if status.isGood() and isinstance(data, list): print("The array is:") for i in xrange(len(data)): print(" - array[%d] = %d" %(i, data[i].value)) # define the ClientSettings: settings = ClientSettings() settings.applicationName = "MyClient" settings.discoveryUrls.append("opc.tcp://localhost:4841") # create the client myClient = Client(settings) # read the node attributes all at once try: print("") print("First option: use the convenience function \"read()\"") print("===================================================") # OPTIONAL: You could also provide a ReadConfig to configure a call timeout, # or maximum age of the values, or ...