beckhoff — 6.13 ADS sum command: read and write multiple variables

Samples: TcJavaToAds 6.13 ADS sum command: read and write multiple variables This sample shows how to read or write many variables using the ADS sum command. Set up as TcAdsClient.ReadWrite it serves as a container in which the subcommands are transported in an ADS stream. System requirements: TwinCAT v2.11 Build >= 1550 Unpack the sample program 'ADS sum command: read and write multiple variables': https:// infosys.beckhoff.com/content/1033/tcjavatoads/Resources/12475107083/.zip To execute the *.jar sample, the command 'java -classpath "Sample13.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.

Fetch symbol information of the PLC variables import java.nio.ByteBuffer; import java.nio.ByteOrder; import de.beckhoff.jni.JNIByteBuffer; import de.beckhoff.jni.tcads.AdsCallDllFunction; import de.beckhoff.jni.tcads.AmsAddr; public class Main { private final static RequestData[] REQ_DATA = new RequestData[]{ new RequestData("uintValue", 0x4020, 0x0, 0x2), new RequestData("boolValue", 0x4020, 0x8, 0x1), new RequestData("dintValue", 0x4020, 0x10, 0x4) }; // The data that is going to be written in the third step private final static char CHAR_VAL = Character.MAX_VALUE; private final static byte BOOL_VAL = 1; private final static int INT_VAL = Integer.MIN_VALUE; private final static int DATA_LEN = 7; private final static int RESP_ERR_LEN = 4; public static void main(String[] args) { long err; 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!"); } If variables are to be written or read in the PLC without resorting to handles, then IndexGroup and IndexOffset must be known. To get these values from all relevant variables, usually the symbol information has to be read out. In this sample, the values are assumed to be constant and defined in REQ_DATA. Read values The RequestBuffer is now written with the data from REQ_DATA according to the scheme below. Here IG1 stands for the IndexGroup of the first subcommand.

IO2 for the IndexOffset of the second subcommand and L3 for the length of the expected response of the third subcommand. TX1000 52 Version: 1.1