Samples: TcJavaToAds 6.11 Event-Driven Detection of Changes to the Symbol Table ADS devices that support symbol names (PLC, NC, ...) store those names in an internal table. A handle is assigned here to each symbol. The symbol handle is necessary in order to be able to access the variables. If the symbol table changes because, for instance, a new PLC program is written into the controller, the handles must be ascertained once again. The following sample illustrates how changes to the symbol table can be detected. Unpack the sample program 'Event-driven detection of changes to the symbol table':
https:// infosys.beckhoff.com/content/1033/tcjavatoads/Resources/12475104267/.zip To execute the *.jar sample, the command 'java -classpath "Sample11.jar;[path to TcJavaToAds.jar] Main' must be executed in the console in the correct directory (example path: "C:TwinCAT\Ads Api\AdsToJava\*"). For this, java must be entered in the environment variables.
import de.beckhoff.jni.AdsConstants; import de.beckhoff.jni.JNILong; import de.beckhoff.jni.tcads.AdsCallDllFunction; import de.beckhoff.jni.tcads.AdsCallbackObject; import de.beckhoff.jni.tcads.AdsNotificationAttrib; import de.beckhoff.jni.tcads.AmsAddr; public class Main { public static void main(String[] args) { long err = 0; AmsAddr addr = new AmsAddr(); try { // Open communication AdsCallDllFunction.adsPortOpen(); err = AdsCallDllFunction.getLocalAddress(addr); addr.setPort(AdsCallDllFunction.AMSPORT_R0_PLC_RTS1); if (err != 0) { System.out.println("Error: Open communication: 0x" + Long.toHexString(err)); } else { System.out.println("Success:
Open communication!"); } JNILong notification = new JNILong(); AdsNotificationAttrib attr = new AdsNotificationAttrib(); attr.setCbLength(1); attr.setNTransMode(AdsConstants.ADSTRANS_SERVERONCHA); attr.setNMaxDelay(5000000); attr.setNCycleTime(5000000); // Create and add listener AdsListener listener = new AdsListener(); AdsCallbackObject callObject = new AdsCallbackObject(); callObject.addListenerCallbackAdsState(listener); AdsCallDllFunction.adsSyncAddDeviceNotificationReq(addr, AdsCallDllFunction.ADSIGRP_SYM_VERSION, // IndexGroup 0, // IndexOffset attr, // The defined AdsNotificationAttrib object 0, // Choose arbitrary number notification); if (err != 0) { System.out.println("Error:
Add notification: 0x" + Long.toHexString(err)); } // Read as long as user does not press return System.out.println("Press enter to continue..\n"); System.in.read(); // Delete notificationHandle err = AdsCallDllFunction.adsSyncDelDeviceNotificationReq( addr, TX1000 47 Version: 1.1