1
2
3 '''
4 @requires: ctypes, Beckhoff TwinCAT mit ADS-DLL
5 @version: 1
6 @note: Wrapper for the Beckhoff TwinCAT AdsDLL.dll
7
8 pyads uses the C API I{AdsDLL.dll}. The documentation for the ADS API is available on U{infosys.beckhoff.de<http://infosys.beckhoff.de/index.php?content=../content/1031/TcAdsDll2/HTML/TcAdsDll_Api_Overview.htm&id=>}
9
10 B{samples:}
11
12 opening port, set port number to 801
13 >>> port = adsPortOpen()
14 >>> adr = adsGetLocalAddress()
15 >>> adr.setPort(PORT_SPS1)
16
17 setting ADS-state and machine-state
18 >>> errCode = adsSyncWriteControlReq(adr, ADSSTATE_STOP, 0, 0)
19 >>> print errCode
20
21 reading bit %MX100.0, toggle it and writing back
22 >>> (errCode, data) = adsSyncReadReq(adr, INDEXGROUP_MEMORYBIT, 100*8 + 0)
23 >>> errCode = adsSyncWriteReq(adr, INDEXGROUP_MEMORYBIT, 100*8 + 0, not data)
24
25 writing an UDINT value to MW0 and reading it
26 >>> errCode = adsSyncWriteReq(adr, INDEXGROUP_MEMORYBYTE, 0, 65536, PLCTYPE_UDINT)
27 >>> (errCode, val) = adsSyncReadReq(adr, INDEXGROUP_MEMORYBYTE, 0, PLCTYPE_UDINT)
28 >>> print errCode, val
29
30 writing a string value in MW0 and reading it
31 >>> errCode = adsSyncWriteReq(adr, INDEXGROUP_MEMORYBYTE, 0, "Hallo, wie geht es?", PLCTYPE_STRING)
32 >>> (errCode, val) = ads
33
34 close port
35 >>> adsPortClose()
36 '''
37
38
39 from pyads import *
40