twincat-ads
This is a client implementation of the Twincat ADS protocol from Beckhoff.
Changelog
initial version
Connect to the Host
var ads = ; var options = // The IP or hostname of the target machine host: "10.0.0.2" // The NetId of the target machine amsNetIdTarget: "5.1.204.160.1.1" // The NetId of the source machine. // You can choose anything in the form of x.x.x.x.x.x, // but on the target machine this must be added as a route. amsNetIdSource: "192.168.137.50.1.1" // OPTIONAL: (These are set by default) // The tcp destination port port: 48898 // The ams source port amsPortSource: 32905 // The ams target port amsPortTarget: 801 var client = ads; client;
How to define Handles
var handle = // The symname is the name of the Symbol which is defined in // the PLC symName: '.TESTINT' // An ads type object or an array of type objects. // You can also specify a number or an array of numbers, // the result will then be a buffer object. // If not defined, the default will be BOOL. byteLength: adsINT // The propery name where the value should be written. // This can be an array with the same length as the array // length of byteLength. // If not defined, the default will be 'value'. propname: 'value' // The value is only necessary to write data. value: 5 // OPTIONAL: // (These are set by default) transmissionMode: adsNOTIFYONCHANGE // or ads.NOTIFY.CYLCIC // Latest time (in ms) after which the event has finished maxDelay: 0 // Time (in ms) after which the PLC server checks whether // the variable has changed cycleTime: 10;
Read single symbol
var handle = symName: '.TESTINT' byteLength: adsINT; var client = ads;
Write single symbol
var handle = symName: '.TESTINT' byteLength: adsINT value: 5; var client = ads;
Read multiple symbols
var client = ads;
Write multiple symbols
var client = ads;
Get handles
var client = ads
Get notifications
var handle = symName: '.CounterTest' byteLength: adsWORD ; var client = ads; client; process; process;
Get symbol list
var client = ads;
Read device state
var client = ads;
Event-Driven detection for changes of the Symbol-Table
If the symbol table changes, like a new PLC program is written into the controller, the handles must be loaded once again.
The example below illustrates how changes of the Symbol-Table can be detected.
var start = false; var client = ads; var handle = indexGroup: adsADSIGRPSYM_VERSION indexOffset: 0 byteLength: adsBYTE; client; process; client;
Twincat and ADS (Automation Device Specification) is brought by Beckhoff©
I'm not affiliated from Beckhoff©!
Credits:
- The initial idea to implement the TCP/IP API came from Inando - Copyright (c) 2012 Inando