Samples: TcJavaToAds AdsCallDllFunction.ADSIGRP_SYM_RELEASEHND, 0, handleBuff.getUsedBytesCount(), handleBuff); if(err!=0) { System.out.println("Error: Release Handle: 0x" + Long.toHexString(err)); } else { System.out.println("Success: Release Handle!"); } // Close communication err = AdsCallDllFunction.adsPortClose(); if(err!=0) { System.out.println("Error: Close Communication: 0x" + Long.toHexString(err)); } try{ System.in.read(); } catch (Exception e){ System.out.println("Error: Close program"); } } } 6.3 Accessing an array in the PLC An array, located in the PLC, is to be read by means of a read command. The variable is addressed here by its variable name.
The procedure is only slightly different from that for reading discrete variables: Unpack the sample program 'Access an array in the PLC': https://infosys.beckhoff.com/content/1033/ tcjavatoads/Resources/12475093003/.zip To execute the *.jar sample, the command 'java -classpath "Sample03.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.Convert; import de.beckhoff.jni.JNIByteBuffer; import de.beckhoff.jni.tcads.AmsAddr; import de.beckhoff.jni.tcads.AdsCallDllFunction; public class Main { public static void main(String[] args) { long err; AmsAddr addr = new AmsAddr(); JNIByteBuffer dataBuff = new JNIByteBuffer(200); // 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!"); } // Read value by IndexGroup and IndexOffset err = AdsCallDllFunction.adsSyncReadReq(addr, 0x4020, // Index Group 0x0, // Index Offset 200, dataBuff); if(err!=0) { System.out.println("Error: Read by handle: 0x" + Long.toHexString(err)); } TX1000 33 Version: 1.1