Skip to main content

Python wrapper for TwinCAT ADS library

Project description

Code Issues

This is a python wrapper for TwinCATs ADS library. It provides python functions for communicating with TwinCAT devices. pyads uses the C API AdsDLL.dll. The documentation for the ADS API is available on infosys.beckhoff.com.

Changelog

Version 2.0.0

I wanted to make the Wrapper more pythonic so I created a new module named pyads.ads that contains all the functions from pyads.pyads but in a more pythonic way. You can still access the old functions by using the pyads.pyads module.

Improvements:

  • more pythonic function names (e.g. ‘write’ instead of ‘adsSyncWrite’)

  • easier handling of reading and writing Strings

  • no error codes, if errors occur an Exception with the error code will be raised

Examples

Open port and create a AmsAddr object for remote machine.

>>> import pyads
>>> pyads.open_port()
32828
>>> pyads.get_local_address()
<AmsAddress 192.168.0.109.1.1:32828>
>>> adr = pyads.AmsAddr('5.33.160.54.1.1', 851)

You can read and write a variable by name from a remote machine.

>>> pyads.read_by_name(adr, 'global.bool_value', pyads.PLCTYPE_BOOL)
True
>>> pyads.write_by_name(adr, 'global.bool_value', False, pyads.PLCTYPE_BOOL)
>>> pyads.read_by_name(adr, 'global.bool_value', pyads.PLCTYPE_BOOL)
False

If the name could not be found an Exception containing the error message and ADS Error number is raised.

>>> pyads.read_by_name(adr, 'global.wrong_name', pyads.PLCTYPE_BOOL)
ADSError: ADSError: symbol not found (1808)

Reading and writing Strings is now easier as you don’ t have to supply the length of a string anymore. For reading strings the maximum buffer length is 1024.

>>> pyads.read_by_name(adr, 'global.sample_string', pyads.PLCTYPE_STRING)
'Hello World'
>>> pyads.write_by_name(adr, 'global.sample_string', 'abc', pyads.PLCTYPE_STRING)
>>> pyads.read_by_name(adr, 'global.sample_string', pyads.PLCTYPE_STRING)
'abc'

Setting the ADS state and machine state.

>>> pyads.write_control(adr, pyads.ADSSTATE_STOP, 0, 0)

Toggle bitsize variables by address.

>>> data = pyads.read(adr, INDEXGROUP_MEMORYBIT, 100*8 + 0, PLCTYPE_BOOL)
>>> pyads.write(adr, INDEXGROUP_MEMORYBIT, 100*8 + 0, not data)

Read and write udint variable by address.

>>> pyads.write(adr, INDEXGROUP_MEMORYBYTE, 0, 65536, PLCTYPE_UDINT)
>>> pyads.read(adr, INDEXGROUP_MEMORYBYTE, 0, PLCTYPE_UDINT)
65536

Finally close the ADS port.

>>> pyads.close_port()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyads-2.0.0.zip (28.9 kB view details)

Uploaded Source

File details

Details for the file pyads-2.0.0.zip.

File metadata

  • Download URL: pyads-2.0.0.zip
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyads-2.0.0.zip
Algorithm Hash digest
SHA256 6ecf72b2ad6de8365c32d1b393515db4597eb31545b2da5f3df1038e8a61b970
MD5 a9ad26f53e2fcb51aaa44bfd61bb87bc
BLAKE2b-256 aa6263ca77d6ba69baa653ebdfa0a78845ea5761f04096de9674f33aa4178643

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page