Opc клиент на python

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

OPC UA library for python >= 3.7

License

FreeOpcUa/opcua-asyncio

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

The OPC UA binary protocol implementation has undergone extensive testing with various OPC UA stacks. The API offers both a low level interface to send and receive all UA defined structures and high level classes allowing to write a server or a client in a few lines. It is easy to mix high level objects and low level UA calls in one application. Most low level code is autogenerated from xml specification.

The test coverage reported by coverage.py is over 95%, with the majority of the non-tested code being autogenerated code that is not currently in use.

opcua-asyncio is open-source and comes with absolutely no warranty. We try to keep it as bug-free as possible, and try to keep the API stable, but bugs and API changes will happen! In particular, API changes are expected to take place prior to any 1.0 release.

Some renaming of methods from get_xx to read_xx and set_xx to write_xxx have been made to better follow OPC UA naming conventions

Version 0.9.9 introduces some argument renaming due to more automatic code generation. Especially the arguments to NodeId, BrowseName, LocalizedText and DataValue, which are now CamelCase instead of lower case, following the OPC UA conventions used in all other structures in this library

We assume that you already have some experience with Python, the asyncio module, the async / await syntax and the concept of asyncio Tasks.

The Client class provides a high level API for connecting to OPC UA servers, session management and access to basic address space services. The client can be used as a context manager. The client will then automatically connect and disconnect withing the with syntax.

from asyncua import Client async with Client(url='opc.tcp://localhost:4840/freeopcua/server/') as client: while True: # Do something with client node = client.get_node('i=85') value = await node.read_value()

Of course, you can also call the connect , disconnect methods yourself if you do not want to use the context manager.

See the example folder and the code for more information on the client API.

The Node class provides a high level API for management of nodes as well as data access services.

The Subscription class provides a high level API for management of monitored items.

The Server class provides a high level API for creation of OPC UA server instances.

The documentation is available here ReadTheDocs.

The API remains mostly unchanged with regards to python-opcua. The main difference is that most methods are now asynchronous. Please have a look at the examples and/or the code.

  • uadiscover (find_servers, get_endpoints and find_servers_on_network calls)
  • uals (list children of a node)
  • uahistoryread
  • uaread (read attribute of a node)
  • uawrite (write attribute of a node)
  • uacall (call method of a node)
  • uasubscribe (subscribe to a node and print datachange events)
  • uaclient (connect to server and start python shell)
  • uaserver (starts a demo OPC UA server) tools/uaserver —populate —certificate cert.pem —private_key pk.pem
  • connection to server, opening channel, session
  • browsing and reading attributes value
  • getting nodes by path and nodeids
  • creating subscriptions
  • subscribing to items for data change
  • subscribing to events
  • adding nodes
  • method call
  • user and password
  • history read
  • login with certificate
  • communication encryption
  • removing nodes

Tested servers: freeopcua C++, freeopcua Python, prosys, kepware, beckhoff, winCC, B&R, …

  • localized text feature
  • XML protocol
  • UDP (PubSub stuff)
  • WebSocket
  • maybe automatic reconnection.
  • creating channel and sessions
  • read/set attributes and browse
  • getting nodes by path and nodeids
  • autogenerate address space from spec
  • adding nodes to address space
  • datachange events
  • events
  • methods
  • basic user implementation (one existing user called admin, which can be disabled, all others are read only)
  • encryption
  • certificate handling
  • removing nodes
  • history support for data change and events
  • more high level solution to create custom structures

Tested clients: freeopcua C++, freeopcua Python, uaexpert, prosys, quickopc

  • UDP (PubSub stuff)
  • WebSocket
  • session restore
  • alarms
  • XML protocol
  • views
  • localized text features
  • better security model with users and password

Running a server on a Raspberry Pi

Setting up the standard address-space from XML is the most time-consuming step of the startup process which may lead to long startup times on less powerful devices like a Raspberry Pi. By passing a path to a cache-file to the server constructor, a shelve holding the address space will be created during the first startup. All following startups will make use of the cache-file which leads to significantly better startup performance (~3.5 vs 125 seconds on a Raspberry Pi Model B).

Code follows PEP8 apart for line lengths which should be max 160 characters and OPC UA structures that keep camel case from XML definition.

All protocol code is under opcua directory

  • asyncua/ua contains all UA structures from specification, most are autogenerated
  • asyncua/common contains high level objects and methods used both in server and client
  • asyncua/client contains client specific code
  • asyncua/server contains server specific code
  • asyncua/utils contains some utilities function and classes
  • asyncua/tools contains code for command lines tools
  • schemas contains the XML and text files from specification and the python scripts used to autogenerate code
  • tests contains tests
  • docs contains files to auto generate documentation from doc strings
  • examples contains many example files
  • examples/sync contains many example files using sync API
  • tools contains python scripts that can be used to run command line tools from repository without installing
python -m pip install -r requirements.txt python -m pip install -r dev_requirements.txt pytest -v -s 
pytest -v -s --cov asyncua --cov-report=html 
./run-test.sh -v -s --cov asyncua --cov-report=html 

About

OPC UA library for python >= 3.7

Источник

OpenOPC-DA 1.5.0

OpenOPC for Python 3.7+ is a descendent of http://openopc.sourceforge.net with modifications for Python 3 and distutils.

About OpenOPC

OpenOPC for Python is a free, open source OPC (OLE for Process Control) toolkit designed for use with the popular Python programming language.

Software Developers

If you elected to install the OpenOPC Development library during the installation process, then you’ll need to also download and install the following packages in order to develop your own Python programs which use the OpenOPC library:

Of course, Python is necessary on all platforms. However the other packages may be optional depending on your configuration:

Pywin32: optional Pyro5: required

Pywin32: required Pyro5: optional

Pywin32: not applicable Pyro5: required

In order to get the most from the OpenOPC package, Windows developers are encouraged to install both Pywin32 and Pyro. Using Pyro to talk to the Gateway Service provides a quick and easy method for bypassing the DCOM security nightmares which are all too common when using OPC.

Documentation

A PDF manual for OpenOPC is included in this installation inside the “doc” folder. Users are encouraged to also look at the OpenOPC web site for additional usage examples that may not be contained in the manual.

EXAMPLE — Minimal working program:

import OpenOPC opc = OpenOPC.client() opc.connect('Matrikon.OPC.Simulation') print(opc['Square Waves.Real8']) opc.close()

OpenOPC Command-line Client

OpenOPC includes the only publically available command-line OPC client. Unlike graphical clients, it can be easily used in scripts or batch files. And because of its piping capability (i.e. chaining commands together), it is far more powerful than other OPC clients

1. Get a listing of the available OPC servers on your computer by going to the command prompt and entering:

2. Set your prefered OPC server as the default by setting the system wide enviornment variable OPC_SERVER. (On Windows you can do this by going to Control Panel > System > Advanced > Environment Variables):

OPC_SERVER=Matrikon.OPC.Simulation

4. Test to see if the OpenOPC Gateway Service is functioning by entering:

5. Test some of the other commands available using the OPC Command Line Client. To get started, try entering the opc command without any arguments in order to see the help page:

To read an item from your OPC server, just include the item name as one of your arguments. For example, if you’re using Matrikon’s Simulation server you could do:

To read items from a specific OPC server you have installed, include the -s switch followed by the OPC server name. For example:

opc -s Matrikon.OPC.Simulation Random.Int4
C:\> opc -f Random.*Int* Random.Int1 Random.Int2 Random.Int4 Random.UInt1 Random.UInt2 Random.UInt4

To read values of items every 60 seconds, logging the results to a file until stopped by Ctrl-C…:

C:\> opc Random.Int4 Random.Real8 -L 60 >data.log
C:\> opc OpenOPC Command Line Client 1.1.6 Copyright (c) 2007-2008 Barry Barnreiter (barry_b@users.sourceforge.net) Usage: opc [OPTIONS] [ACTION] [ITEM|PATH. ] Actions: -r, --read Read ITEM values (default action) -w, --write Write values to ITEMs (use ITEM=VALUE) -p, --properties View properties of ITEMs -l, --list List items at specified PATHs (tree browser) -f, --flat List all ITEM names (flat browser) -i, --info Display OPC server information -q, --servers Query list of available OPC servers -S, --sessions List sessions in OpenOPC Gateway Service Options: -m MODE, --mode=MODE Protocol MODE (dcom, open) (default: OPC_MODE) -C CLASS,--class=CLASS OPC Automation CLASS (default: OPC_CLASS) -n NAME, --name=NAME Set OPC Client NAME (default: OPC_CLIENT) -h HOST, --host=HOST DCOM OPC HOST (default: OPC_HOST) -s SERV, --server=SERVER DCOM OPC SERVER (default: OPC_SERVER) -H HOST, --gate-host=HOST OpenOPC Gateway HOST (default: OPC_GATE_HOST) -P PORT, --gate-port=PORT OpenOPC Gateway PORT (default: OPC_GATE_PORT) -F FUNC, --function=FUNC Read FUNCTION to use (sync, async) -c SRC, --source=SOURCE Set data SOURCE for reads (cache, device, hybrid) -g SIZE, --size=SIZE Group tags into SIZE items per transaction -z MSEC, --pause=MSEC Sleep MSEC milliseconds between transactions -u MSEC, --update=MSEC Set update rate for group to MSEC milliseconds -t MSEC, --timeout=MSEC Set read timeout to MSEC mulliseconds -o FMT, --output=FORMAT Output FORMAT (table, values, pairs, csv, html) -L SEC, --repeat=SEC Loop ACTION every SEC seconds until stopped -y ID, --id=ID. Retrieve only specific Property IDs -a STR, --append=STR. Append STRINGS to each input item name -x N --rotate=N Rotate output orientation in groups of N values -v, --verbose Verbose mode showing all OPC function calls -e, --errors Include descriptive error message strings -R, --recursive List items recursively when browsing tree -, --pipe Pipe item/value list from standard input

If you experience any unexpected errors, please check the FAQ on http://openopc.sourceforge.net for additional help.

If after reading through the FAQ you still require additional help, then the author of this package would be happy to assist you via e-mail. Please see the project website for current contact information.

Technical Support

If you have any questions, bug reports, or suggestions for improvements please feel free to contact the author at:

While I cannot always guarantee a quick response, I eventually respond to all e-mails and will do my best to solve any issues which are discovered.

Thanks for using OpenOPC for Python!

Credits

Copyright (c) 2008-2012 by Barry Barnreiter (barry_b @ users . sourceforge . net) Copyright (c) 2014 by Anton D. Kachalov (mouse @ yandex . ru) Copyright (c) 2017 by Michal Kwiatkowski (michal @ trivas . pl) Copyright (c) 2022 by j3mg

Источник

Читайте также:  Python output file name
Оцените статью