Python wrapper for TwinCAT ADS library
Project description
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.
Some Samples
open port, set port number to 801
>>> port = adsPortOpen()
>>> adr = adsGetLocalAddress()
>>> adr.setPort(PORT_SPS1)
set ADS-state and machine-state
>>> adsSyncWriteControlReq(adr, ADSSTATE_STOP, 0, 0)
read bit %MX100.0, toggle it and write back to plc
>>> data = adsSyncReadReq(adr, INDEXGROUP_MEMORYBIT, 100*8 + 0, PLCTYPE_BOOL)
>>> adsSyncWriteReq(adr, INDEXGROUP_MEMORYBIT, 100*8 + 0, not data)
write an UDINT value to MW0 and read it from plc
>>> adsSyncWriteReq(adr, INDEXGROUP_MEMORYBYTE, 0, 65536, PLCTYPE_UDINT)
>>> adsSyncReadReq(adr, INDEXGROUP_MEMORYBYTE, 0, PLCTYPE_UDINT)
write a string value in MW0 and read it from plc
>>> adsSyncWriteReq(adr, INDEXGROUP_MEMORYBYTE, 0, "Hallo, wie geht es?", PLCTYPE_STRING)
>>> adsSyncReadReq(adr, INDEXGROUP_MEMORY_BYTE, 0, PLCTYPE_STRING)
read a value of type real from global variable foo
>>> adsSyncReadByName(adr, ".foo", PLCTYPE_REAL)
write a value of type real to global variable bar
>>> adsSyncWriteByName(adr, ".bar", 1.234, PLCTYPE_REAL)
close port
>>> adsPortClose()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyads-1.3.0.zip
(26.4 kB
view hashes)