Samples: TcJavaToAds To execute the *.jar sample, the command 'java -classpath "Sample07.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.JNIByteBuffer; import de.beckhoff.jni.tcads.AdsCallDllFunction; import de.beckhoff.jni.tcads.AmsAddr; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static void main(String[] args) { try{ long err; AmsAddr addr = new AmsAddr(); JNIByteBuffer buff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); ByteBuffer bb = ByteBuffer.allocate(0); // 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!"); } // Specify IndexGroup, IndexOffset and read PLCVar err = AdsCallDllFunction.adsSyncReadReq(addr, 0x4020, // Index Group 0x0, // Index Offset buff.getUsedBytesCount(), buff); if (err != 0) { System.out.println("Error: Read by adress: 0x" + Long.toHexString(err)); } else { bb = ByteBuffer.wrap(buff.getByteArray()); bb.order(ByteOrder.LITTLE_ENDIAN); System.out.println("" + bb.getInt()); } // Close communication err = AdsCallDllFunction.adsPortClose(); if(err!=0) { System.out.println("Error: Close Communication:
0x" + Long.toHexString(err)); } System.out.println("Press enter to continue.."); System.in.read(); } catch (Exception ex){ System.out.println(ex.getMessage()); } } } 6.8 Delete handle of a PLC variable In this sample a handle of a PLC variable is fetched and deleted afterwards: Unpack the sample program 'Delete handle of a PLC variable': https://infosys.beckhoff.com/content/1033/ tcjavatoads/Resources/12475100043/.zip To execute the *.jar sample, the command 'java -classpath "Sample08.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.AdsCallDllFunction; TX1000 40 Version: 1.1